major bug in getImplicitHCount()

User 870ab5b546

25-07-2006 16:44:38

In this molecule:





Code:
<?xml version="1.0" ?>


<MDocument>


  <MChemicalStruct>


    <molecule molID="m1">


      <atomArray


          atomID="a1 a2 a3 a4 a5 a6 a7"


          elementType="C C C C C O N"


          formalCharge="0 0 0 0 0 -1 0"


          x2="-8.036874771118164 -9.282741100135192 -8.80687868274797 -7.266870859488357 -6.791008442101136 -5.3034826696159705 -7.459374904632568"


          y2="0.8768672655063927 -0.02834933300560749 -1.4928967729254987 -1.4928967729254987 -0.02834933300560749 0.37023199645227445 3.4649999141693115"


          />


      <bondArray>


        <bond atomRefs2="a1 a2" order="1" />


        <bond atomRefs2="a2 a3" order="1" />


        <bond atomRefs2="a3 a4" order="1" />


        <bond atomRefs2="a4 a5" order="1" />


        <bond atomRefs2="a1 a5" order="1" />


        <bond atomRefs2="a5 a6" order="1" />


        <bond atomRefs2="a7 a5" order="1" />


      </bondArray>


    </molecule>


  </MChemicalStruct>


  <MEFlow arcAngle="150.0" headSkip="0.15" headLength="0.5" headWidth="0.4"


          tailSkip="0.25">


    <MAtomSetPoint atomRefs="m1.a7" />


    <MAtomSetPoint atomRefs="m1.a7 m1.a5" />


  </MEFlow>


  <MEFlow arcAngle="-254.995522631729" headSkip="0.25" headLength="0.5"


          headWidth="0.4" tailSkip="0.15">


    <MAtomSetPoint atomRefs="m1.a5 m1.a6" />


    <MAtomSetPoint atomRefs="m1.a6" />


  </MEFlow>


</MDocument>








When I operate this command for i=6:





Code:
            MolAtom atom = molecule.getAtom(i);


            System.out.println(atom.getSymbol() + (i+1)


               + " had " + initImplicitHcounts[i]


               + " implicit H atoms and now has "


               + atom.getImplicitHcount()


               + "; adding explicit H atoms.");








I get this output:





N7 had 2 implicit H atoms and now has 1; adding explicit H atoms.





Clearly, molecule.getAtom(6).getImplicitHcount() is returning 1, but just as clearly, the correct value is 2.





I have changed the charge on the N just before this step from -1 to 0; perhaps the bug is that JChem thinks that the charge is still -1.

ChemAxon 7c2d26e5cf

25-07-2006 17:09:52

I don't understand your problem. MolAtom.getImplicitHcount() works fine for me in Marvin.


By testing it with your molecule, the method returns with 2 for the nitrogen ( molecule.getAtom(6).getImplicitHcount() ). Indeed, if I change charge to -1 on the nitrogen, the above method will return with 1.

ChemAxon 7c2d26e5cf

25-07-2006 17:14:15

Probably, you should get the molecule again if you have modified the structure since the last MSketchPane.getMol() calling.


getMol() returns with a clone of the edited molecule.

User 870ab5b546

25-07-2006 17:45:49

I am not doing these commands in Marvin. I am calling JChem from a Java program. I agree that Marvin calculates the implicit H atoms correctly, but JChem does not, as you can see from the fact that





Code:
System.out.println(atom.getSymbol() + (i+1)


               + " had " + initImplicitHcounts[i]


               + " implicit H atoms and now has "


               + atom.getImplicitHcount()


               + "; adding explicit H atoms.");








returns the output,





N7 had 2 implicit H atoms and now has 1; adding explicit H atoms.





The molecule was initially derived from Marvin, but I have done several operations on it: making and removing bonds, changing charges and radical states.

ChemAxon a3d59b832c

26-07-2006 06:25:13

bobgr wrote:
The molecule was initially derived from Marvin, but I have done several operations on it: making and removing bonds, changing charges and radical states.
Please call mol.valenceCheck() after these operations to fix the number of implicit hydrogens. (Documentation: http://www.chemaxon.com/marvin/doc/api/chemaxon/struc/MoleculeGraph.html#valenceCheck())





Best Regards,


Szabolcs

User 870ab5b546

26-07-2006 12:09:15

Excellent, your suggestion solved the problem.





May I suggest that you should include a cross-reference to valenceCheck() in your documentation for getImplicitHcount() and any other method that might be similarly affected? There is no way on God's green earth that I would ever have thought to do what you suggested.





Even the documentation for valenceCheck() is mysterious. What does "Check valence and query property errors" mean? What happens after it checks them? When is it supposed to be used?





At the UGM, you mentioned you were considering hiring someone to clean up the documentation. I encourage you to move quickly on that initiative.

ChemAxon a3d59b832c

27-07-2006 12:43:28

I have updated the API documentation. It reads for valenceCheck:
Quote:
chemaxon.struc.MoleculeGraph


public void valenceCheck()


Check valence and query property errors for each atoms. During this check implicit hydrogens are calculated and the valence error flag is set in case of error.


See Also:


MolAtom.valenceCheck(), MolAtom.getImplicitHcount(), hasValenceError()


And for getImplicitHCount():
Quote:
chemaxon.struc.MolAtom


public int getImplicitHcount()


Gets the number of implicit hydrogens attached. This information may not be accurate if some manipulation has been made on the molecule. In this case, use valenceCheck() before this method.


Returns:


the implicit hydrogen count or the number of query hydrogens


See Also:


valenceCheck()
bobgr wrote:
At the UGM, you mentioned you were considering hiring someone to clean up the documentation. I encourage you to move quickly on that initiative.
It could probably not helped in this particular case, because a new personnel cannot create documentation for the API, this should have been done by the programmers who created the aforementioned methods. But we are keen on improving the documentation, thank you for pointing out many missing points in it.





Best regards,


Szabolcs

User 870ab5b546

27-07-2006 14:43:17

Hmm, both these documentation changes and the one in twicesumbonds() are not showing up in the API that I can see. I'm looking at http://www.chemaxon.com/jchem/doc/api/ . Is that URL the most up-to-date one?

ChemAxon 7c2d26e5cf

27-07-2006 15:18:27

You will see the updated apidoc it in the next release.

ChemAxon 7c2d26e5cf

27-07-2006 15:24:05

The new apidoc of the method:





public int twicesumbonds(boolean countH, boolean all2)





Calculates the total number of bonding electrons, excluding implicit hydrogens. The number of electrons is 2 for single bond, 4 for double and 6 for triple. For other bond types, the following values are used: 3 for AROMATIC, 2 for ANY and SINGLE_OR_AROMATIC, 3 for SINGLE_OR_DOUBLE, 4 for DOUBLE_OR_AROMATIC.





Parameters:


countH - bonds to explicit hydrogen atoms are counted if true, not counted if false


all2 - use the value 2 for each bond (independently of type) if true





Returns:


the sum of bond values