H atom property lost in resonance plugin

User 870ab5b546

07-10-2011 14:41:29

Using JChem 5.6.0.0.  The code:


        ChemUtils.setAtomIndicesAsAtomProperties(molecule); // sets 1-based indices
debugPrintMRV(SELF + "after setting atom properties:\n", molecule);
final pKaPlugin plugin = getPKaPlugin(!USE_LARGE_MODEL);
molecule.aromatize(MoleculeGraph.AROM_BASIC);
final ResonancePlugin resPlugin = new ResonancePlugin();
// get best resonance structure before calculating pKa
resPlugin.setTakeCanonicalForm(true);
try {
resPlugin.setMolecule(molecule);
resPlugin.run(); // moves explicit H atoms to end of atom list
final Molecule molRes = resPlugin.getStructure(0);
molRes.dearomatize();
molRes.aromatize(MoleculeGraph.AROM_BASIC);
if (!MolFunctions.matchPrecise(molecule, molRes)) {
molecule = molRes;
debugPrintMRV(SELF + "before obtaining pKa and pKb, molecule ",
molecule.getFormula(), (stageIndex >= 0
? " in stage " + (stageIndex + 1) : ""),
" is converted to best resonance structure:\n",
molecule);
} // if resonance form is not same as original molecule
} catch (Exception e) {
Utils.alwaysPrint(SELF + "resonance plugin or matchPrecise "
+ "throws exception for",
(stageIndex >= 0 ? " stage " + (stageIndex + 1) : ""),
" molecule ", molecule.getFormula(),
"; can't get best resonance structure; proceed anyway");
e.printStackTrace();
} // try

public static void setAtomIndicesAsAtomProperties(Molecule mol) {
int atomNum = 0;
for (MolAtom atom : mol.getAtomArray()) {
atomNum++;
atom.putProperty(ATOM_INDEX, Integer.valueOf(atomNum));
} // for each atom
} // setAtomIndicesAsAtomProperties(Molecule)

The log output:


pKaFunctions.pKapKbAtoms: after setting atom properties:
<?xml version="1.0" ?>
<cml>
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray>
<atom id="a1" elementType="C"
x2="20.077753481729204" y2="-7.429787228127836">
<scalar id="a1:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="1" />
</atom>
<atom id="a2" elementType="C"
x2="18.590232772212516" y2="-7.828387452361290">
<scalar id="a2:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="2" />
</atom>
<atom id="a3" elementType="C"
x2="18.191642673676004" y2="-9.315945951493433">
<scalar id="a3:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="3" />
</atom>
<atom id="a4" elementType="C"
x2="19.280573284656180" y2="-10.404904226392123">
<scalar id="a4:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="4" />
</atom>
<atom id="a5" elementType="C"
x2="20.768093994172872" y2="-10.006304002158668">
<scalar id="a5:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="5" />
</atom>
<atom id="a6" elementType="C"
x2="21.166684092709385" y2="-8.518745503026526">
<scalar id="a6:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="6" />
</atom>
<atom id="a7" elementType="C" formalCharge="-1"
x2="22.704541652738875" y2="-8.438229358717074">
<scalar id="a7:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="7" />
</atom>
<atom id="a8" elementType="C"
x2="22.059652137927266" y2="-10.845054058493997">
<scalar id="a8:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="8" />
</atom>
<atom id="a9" elementType="C"
x2="23.256394907922274" y2="-9.875956031191187">
<scalar id="a9:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="9" />
</atom>
<atom id="a10" elementType="H"
x2="22.704541652738875" y2="-6.898229358717073">
<scalar id="a10:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="10" />
</atom>
</atomArray>
<bondArray>
<bond atomRefs2="a1 a2" order="1" />
<bond atomRefs2="a1 a6" order="2" />
<bond atomRefs2="a2 a3" order="2" />
<bond atomRefs2="a3 a4" order="1" />
<bond atomRefs2="a4 a5" order="2" />
<bond atomRefs2="a5 a8" order="1" />
<bond atomRefs2="a6 a5" order="1" />
<bond atomRefs2="a7 a6" order="1" />
<bond atomRefs2="a7 a9" order="1" />
<bond atomRefs2="a7 a10" order="1" />
<bond atomRefs2="a8 a9" order="2" />
</bondArray>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>

pKaFunctions.pKapKbAtoms: before obtaining pKa and pKb, molecule C9H7 in stage 2 is converted to best resonance structure:
<?xml version="1.0" ?>
<cml>
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray>
<atom id="a1" elementType="C"
x2="20.077753481729204" y2="-7.429787228127836">
<scalar id="a1:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="1" />
</atom>
<atom id="a2" elementType="C"
x2="18.590232772212516" y2="-7.828387452361290">
<scalar id="a2:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="2" />
</atom>
<atom id="a3" elementType="C"
x2="18.191642673676004" y2="-9.315945951493433">
<scalar id="a3:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="3" />
</atom>
<atom id="a4" elementType="C"
x2="19.280573284656180" y2="-10.404904226392123">
<scalar id="a4:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="4" />
</atom>
<atom id="a5" elementType="C"
x2="20.768093994172872" y2="-10.006304002158668">
<scalar id="a5:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="5" />
</atom>
<atom id="a6" elementType="C"
x2="21.166684092709385" y2="-8.518745503026526">
<scalar id="a6:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="6" />
</atom>
<atom id="a7" elementType="C"
x2="22.704541652738875" y2="-8.438229358717074">
<scalar id="a7:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="7" />
</atom>
<atom id="a8" elementType="C"
x2="22.059652137927266" y2="-10.845054058493997">
<scalar id="a8:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="8" />
</atom>
<atom id="a9" elementType="C" formalCharge="-1"
x2="23.256394907922274" y2="-9.875956031191187">
<scalar id="a9:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="9" />
</atom>
<atom id="a10" elementType="H"
x2="0.000000000000000" y2="0.000000000000000" />
</atomArray>
<bondArray>
<bond atomRefs2="a1 a2" order="A" />
<bond atomRefs2="a1 a6" order="A" />
<bond atomRefs2="a2 a3" order="A" />
<bond atomRefs2="a3 a4" order="A" />
<bond atomRefs2="a4 a5" order="A" />
<bond atomRefs2="a5 a8" order="A" />
<bond atomRefs2="a6 a5" order="A" />
<bond atomRefs2="a7 a6" order="A" />
<bond atomRefs2="a7 a9" order="A" />
<bond atomRefs2="a8 a9" order="A" />
<bond atomRefs2="a10 a7" order="1" />
</bondArray>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>

Note how the atom property of the H atom has disappeared.  Please fix.  


Here's another example, in which the H atom migrates from the middle of the atom list to the end AND loses its atom property.  (The migration is why I went to atom properties in the first place.)


pKaFunctions.pKapKbAtoms: after setting atom properties:
<?xml version="1.0" ?>
<cml>
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray>
<atom id="a1" elementType="C"
x2="15.154476686214904" y2="2.6384464461512276">
<scalar id="a1:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="1" />
</atom>
<atom id="a2" elementType="C"
x2="16.488155808042940" y2="3.408446446151227">
<scalar id="a2:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="2" />
</atom>
<atom id="a3" elementType="O" formalCharge="-1"
x2="18.124405827116426" y2="4.467196160048932">
<scalar id="a3:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="3" />
</atom>
<atom id="a4" elementType="C"
x2="13.820797564386869" y2="3.4084464461512276">
<scalar id="a4:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="4" />
</atom>
<atom id="a5" elementType="H"
x2="14.384476686214905" y2="1.3047673243231919">
<scalar id="a5:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="5" />
</atom>
<atom id="a6" elementType="C"
x2="20.530210138475788" y2="-0.7803916284442405">
<scalar id="a6:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="6" />
</atom>
<atom id="a7" elementType="C"
x2="21.863498587554194" y2="-0.009715359473866592">
<scalar id="a7:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="7" />
</atom>
<atom id="a8" elementType="C"
x2="21.862737129660900" y2="1.5303183333957104">
<scalar id="a8:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="8" />
</atom>
<atom id="a9" elementType="C"
x2="20.528687222689207" y2="2.2996757572948994">
<scalar id="a9:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="9" />
</atom>
<atom id="a10" elementType="C"
x2="19.195398773610800" y2="1.5289994883245246">
<scalar id="a10:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="10" />
</atom>
<atom id="a11" elementType="C"
x2="19.196160231504090" y2="-0.011034204545055992">
<scalar id="a11:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="11" />
</atom>
<atom id="a12" elementType="O"
x2="17.861339094236648" y2="2.2983399668307154">
<scalar id="a12:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="12" />
</atom>
<atom id="a13" elementType="C"
x2="13.820797564386870" y2="4.9484464461512285">
<scalar id="a13:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="13" />
</atom>
<atom id="a14" elementType="C"
x2="12.487118442558836" y2="5.718446446151230">
<scalar id="a14:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="14" />
</atom>
<atom id="a15" elementType="C"
x2="11.153439320730800" y2="4.948446446151234">
<scalar id="a15:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="15" />
</atom>
<atom id="a16" elementType="C"
x2="11.153439320730794" y2="3.4084464461512276">
<scalar id="a16:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="16" />
</atom>
<atom id="a17" elementType="C"
x2="12.487118442558828" y2="2.6384464461512263">
<scalar id="a17:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="17" />
</atom>
</atomArray>
<bondArray>
<bond atomRefs2="a1 a2" order="2" />
<bond atomRefs2="a1 a4" order="1" />
<bond atomRefs2="a1 a5" order="1" />
<bond atomRefs2="a2 a3" order="1" />
<bond atomRefs2="a12 a2" order="1" />
<bond atomRefs2="a6 a7" order="1" />
<bond atomRefs2="a6 a11" order="1" />
<bond atomRefs2="a7 a8" order="1" />
<bond atomRefs2="a8 a9" order="1" />
<bond atomRefs2="a9 a10" order="1" />
<bond atomRefs2="a10 a11" order="1" />
<bond atomRefs2="a10 a12" order="1" />
<bond atomRefs2="a4 a13" order="2" />
<bond atomRefs2="a4 a17" order="1" />
<bond atomRefs2="a13 a14" order="1" />
<bond atomRefs2="a14 a15" order="2" />
<bond atomRefs2="a15 a16" order="1" />
<bond atomRefs2="a16 a17" order="2" />
</bondArray>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>

pKaFunctions.pKapKbAtoms: before obtaining pKa and pKb, molecule C14H17O2 in stage 2 is converted to best resonance structure:
<?xml version="1.0" ?>
<cml>
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray>
<atom id="a1" elementType="C" formalCharge="-1"
x2="15.154476686214904" y2="2.6384464461512276">
<scalar id="a1:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="1" />
</atom>
<atom id="a2" elementType="C"
x2="16.488155808042940" y2="3.408446446151227">
<scalar id="a2:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="2" />
</atom>
<atom id="a3" elementType="O"
x2="18.124405827116426" y2="4.467196160048932">
<scalar id="a3:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="3" />
</atom>
<atom id="a4" elementType="C"
x2="13.820797564386869" y2="3.4084464461512276">
<scalar id="a4:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="4" />
</atom>
<atom id="a5" elementType="C"
x2="20.530210138475788" y2="-0.7803916284442405">
<scalar id="a5:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="6" />
</atom>
<atom id="a6" elementType="C"
x2="21.863498587554194" y2="-0.009715359473866592">
<scalar id="a6:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="7" />
</atom>
<atom id="a7" elementType="C"
x2="21.862737129660900" y2="1.5303183333957104">
<scalar id="a7:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="8" />
</atom>
<atom id="a8" elementType="C"
x2="20.528687222689207" y2="2.2996757572948994">
<scalar id="a8:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="9" />
</atom>
<atom id="a9" elementType="C"
x2="19.195398773610800" y2="1.5289994883245246">
<scalar id="a9:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="10" />
</atom>
<atom id="a10" elementType="C"
x2="19.196160231504090" y2="-0.011034204545055992">
<scalar id="a10:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="11" />
</atom>
<atom id="a11" elementType="O"
x2="17.861339094236648" y2="2.2983399668307154">
<scalar id="a11:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="12" />
</atom>
<atom id="a12" elementType="C"
x2="13.820797564386870" y2="4.9484464461512285">
<scalar id="a12:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="13" />
</atom>
<atom id="a13" elementType="C"
x2="12.487118442558836" y2="5.718446446151230">
<scalar id="a13:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="14" />
</atom>
<atom id="a14" elementType="C"
x2="11.153439320730800" y2="4.948446446151234">
<scalar id="a14:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="15" />
</atom>
<atom id="a15" elementType="C"
x2="11.153439320730794" y2="3.4084464461512276">
<scalar id="a15:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="16" />
</atom>
<atom id="a16" elementType="C"
x2="12.487118442558828" y2="2.6384464461512263">
<scalar id="a16:prop1" title="atomIndexAsProperty" convention="marvin:atomprop" dataType="xsd:integer" value="17" />
</atom>
<atom id="a17" elementType="H"
x2="0.000000000000000" y2="0.000000000000000" />
</atomArray>
<bondArray>
<bond atomRefs2="a1 a2" order="1" />
<bond atomRefs2="a1 a4" order="1" />
<bond atomRefs2="a2 a3" order="2" />
<bond atomRefs2="a11 a2" order="1" />
<bond atomRefs2="a5 a6" order="1" />
<bond atomRefs2="a5 a10" order="1" />
<bond atomRefs2="a6 a7" order="1" />
<bond atomRefs2="a7 a8" order="1" />
<bond atomRefs2="a8 a9" order="1" />
<bond atomRefs2="a9 a10" order="1" />
<bond atomRefs2="a9 a11" order="1" />
<bond atomRefs2="a4 a12" order="A" />
<bond atomRefs2="a4 a16" order="A" />
<bond atomRefs2="a12 a13" order="A" />
<bond atomRefs2="a13 a14" order="A" />
<bond atomRefs2="a14 a15" order="A" />
<bond atomRefs2="a15 a16" order="A" />
<bond atomRefs2="a17 a1" order="1" />
</bondArray>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>

ChemAxon e08c317633

25-10-2011 15:47:32

Bob, we cannot reproduce the error. Could you attach an mrv file which contains the input molecule, and a java code (as a .java file) which we can just compile and run? The outptu should be the faulty structure.


Zsolt

User 870ab5b546

26-10-2011 23:45:04

Now that the pKaPlugin takes resonance structures into account, and we no longer need to generate canonical resonance structures, I no longer have the code handy that caused the bug in the first place.  It's also possible you inadvertenty fixed the problem already.  So, if you can't reproduce it, let's just forget about it for now.