bond sequence change after adding a bond to a molecule

User 870ab5b546

14-12-2010 17:31:34

The code:


    public Molecule getProducts(boolean fromJSP) throws MechError,
MolFormatException {
final String SELF = "MechSolver.getProducts: ";
...
calculateNewBonds(refMol);
final boolean hasOddElectronBond = setNewBondTypes();
final String SET_CHGS_RADS = "setting charges and radical flags";
final String SET_H_CTS = "resetting H counts";
final String CPD_HAS = ", compound has ";
debugPrintMRV(SELF + "before " + SET_CHGS_RADS + CPD_HAS,
molecule.getAtomCount(), " atoms:\n", molecule);
setChargesRadicals();
...
} // getProducts(boolean)

private void calculateNewBonds(Molecule refMol) {
final String SELF = "MechSolver.calculateNewBonds: ";
debugPrint(SELF + "Before calculating new bond orders, bondElecCts = ",
bondElecCts);
printBonds();
...
debugPrint(SELF + "After calculating new bond orders, bondElecCts = ",
bondElecCts);
printBonds();
} // calculateNewBonds(Molecule)

private boolean setNewBondTypes() throws MechError {
...
debugPrint(SELF + "After setting new bond orders, bondElecCts = ",
bondElecCts);
printBonds();
return hasOddElectronBond;
} // setNewBondTypes()

private void setChargesRadicals() {
final String SELF = "MechSolver.setChargesRadicals: ";
debugPrint(SELF + "Before setting charges and radicals, bondElecCts = ",
bondElecCts);
printBonds();
...
} // setChargesRadicals()

private void printBonds() {
int bondNum = 0;
for (MolBond bond : molecule.getBondArray()) {
final MolAtom atom1 = bond.getAtom1();
final MolAtom atom2 = bond.getAtom2();
final int atom1Num = molecule.indexOf(atom1) + 1;
final int atom2Num = molecule.indexOf(atom2) + 1;
final int order = bond.getType();
debugPrint(" Bond ", ++bondNum, ": ", atom1, atom1Num,
(order == 3 ? "#" : order == 2 ? "=" : "-"), atom2, atom2Num);
} // for each bond
} // printBonds()

The debugging output:


MechSolver.calculateNewBonds: Before calculating new bond orders, bondElecCts = [2, 2, 4, 2, 2, 2, 2, 4, 2, 2, 4, 2, 4, 2, 2, 2]
Bond 1: C1-C2
Bond 2: C2-C3
Bond 3: C2=O4
Bond 4: C3-H5
Bond 5: C3-H6
Bond 6: C3-H7
Bond 7: O[-1]8-C9
Bond 8: C1=C10
Bond 9: C1-C14
Bond 10: C10-C11
Bond 11: C11=C12
Bond 12: C12-C13
Bond 13: C13=C14
Bond 14: C9-C15
Bond 15: C9-C16
Bond 16: C9-C17
...
MechSolver.calculateNewBonds: After calculating new bond orders, bondElecCts = [2, 4, 2, 0, 2, 2, 2, 4, 2, 2, 4, 2, 4, 2, 2, 2, 2]
Bond 1: C1-C2
Bond 2: C2-C3
Bond 3: C2=O4
Bond 4: C3-H5
Bond 5: C3-H6
Bond 6: C3-H7
Bond 7: O[-1]8-C9
Bond 8: C1=C10
Bond 9: C1-C14
Bond 10: C10-C11
Bond 11: C11=C12
Bond 12: C12-C13
Bond 13: C13=C14
Bond 14: C9-C15
Bond 15: C9-C16
Bond 16: C9-C17
Bond 17: O[-1]8-H5
...
MechSolver.setNewBondTypes: After setting new bond orders, bondElecCts = [2, 4, 2, 2, 2, 2, 4, 2, 2, 4, 2, 4, 2, 2, 2, 2]
Bond 1: C1-C2
Bond 2: C2=C3
Bond 3: C2-O4
Bond 4: C3-H6
Bond 5: C3-H7
Bond 6: O[-1]8-C9
Bond 7: C1=C10
Bond 8: C1-C14
Bond 9: C10-C11
Bond 10: C11=C12
Bond 11: C12-C13
Bond 12: C13=C14
Bond 13: C9-C15
Bond 14: C9-C16
Bond 15: C9-C17
Bond 16: O[-1]8-H5
MechSolver.getProducts: before setting charges and radical flags, compound has 17 atoms:
<?xml version="1.0" ?>
<cml>
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray
atomID="a1 a2 a3 a4 a5 a6 a7 a8 a9"
elementType="R C C O H H H O R"
formalCharge="0 0 0 0 0 0 0 -1 0"
sgroupRef="sg1 0 0 0 0 0 0 0 sg2"
x2="-30.4796085357666 -29.145929413938568 -27.812250292110534 -29.145929413938568 -26.4785711702825 -28.582250292110533 -27.042250292110534 -24.268407821655273 -22.728407821655274"
y2="24.08344078063965 24.853440780639648 24.08344078063965 26.393440780639647 24.853440780639648 22.749761658811614 22.749761658811614 23.770877838134766 23.770877838134766"
/>
<bondArray>
<bond atomRefs2="a1 a2" order="1" />
<bond atomRefs2="a2 a3" order="2">
<bondStereo convention="MDL" conventionValue="3" />
</bond>
<bond atomRefs2="a2 a4" order="1" />
<bond atomRefs2="a3 a6" order="1" />
<bond atomRefs2="a3 a7" order="1" />
<bond atomRefs2="a8 a9" order="1" />
<bond atomRefs2="a8 a5" order="1" />
</bondArray>
<molecule id="sg1" role="SuperatomSgroup" title="Ph" molID="m2">
<atomArray
atomID="a10 a11 a12 a13 a14 a15"
elementType="C C C C C C"
attachmentPoint="1 0 0 0 0 0"
sgroupAttachmentPoint="1 0 0 0 0 0"
x2="-57.954067385006034 -56.620388263178 -56.620388263178 -57.95406738500604 -59.28774650683407 -59.28774650683407"
y2="51.36443145751953 50.594431457519526 49.05443145751953 48.28443145751953 49.054431457519534 50.59443145751953"
/>
<bondArray>
<bond atomRefs2="a10 a11" order="2" />
<bond atomRefs2="a10 a15" order="1" />
<bond atomRefs2="a11 a12" order="1" />
<bond atomRefs2="a12 a13" order="2" />
<bond atomRefs2="a13 a14" order="1" />
<bond atomRefs2="a14 a15" order="2" />
</bondArray>
</molecule>
<molecule id="sg2" role="SuperatomSgroup" title="tBu" molID="m3">
<atomArray
atomID="a16 a17 a18 a19"
elementType="C C C C"
attachmentPoint="1 0 0 0"
sgroupAttachmentPoint="1 0 0 0"
x2="-22.720535278320312 -23.490535278320312 -21.180535278320313 -23.490535278320312"
y2="23.660314559936523 24.993993681764557 23.660314559936523 22.32663543810849"
/>
<bondArray>
<bond atomRefs2="a16 a17" order="1" />
<bond atomRefs2="a16 a18" order="1" />
<bond atomRefs2="a16 a19" order="1" />
</bondArray>
</molecule>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>

MechSolver.setChargesRadicals: Before setting charges and radicals, bondElecCts = [2, 4, 2, 2, 2, 2, 4, 2, 2, 4, 2, 4, 2, 2, 2, 2]
Bond 1: C1-C2
Bond 2: C2=C3
Bond 3: C2-O4
Bond 4: C3-H6
Bond 5: C3-H7
Bond 6: O[-1]8-C9
Bond 7: O[-1]8-H5
Bond 8: C1=C10
Bond 9: C1-C14
Bond 10: C10-C11
Bond 11: C11=C12
Bond 12: C12-C13
Bond 13: C13=C14
Bond 14: C9-C15
Bond 15: C9-C16
Bond 16: C9-C17

Note that between the end of setNewBondTypes() and the beginning of setChargesRadicals(), bond 16 has moved to bond 7.  There has been no manipulation of the molecule, save for exporting it to MRV format for printing to the log.  The problem is, when I added bond 16 to the molecule, I also added its order to a parallel list.  When the molecule reorders its bonds without any prompting whatsoever, the parallel list becomes inconsistent.  


Is there any reason why the bond should shift positions when nothing has happened to the molecule except subjecting it to toFormat("mrv")?  (This is definitely the stage where the bonds reorder; if I change the call to debugPrintMRV() to use molecule.cloneMolecule() instead of molecule itself, the bonds to not reorder.)  

ChemAxon e500b51457

16-12-2010 11:32:42

Hi Bob,


We tried to reproduce the problem - without success. Please help us create an example code in order to reproduce the problem. We need more information about how you created the input molecule and how you exported the molecule in debugPrintMRV.

Thanks,
Erika.

User 870ab5b546

16-12-2010 14:13:15

The original source is as follows:


<?xml version="1.0" ?>
<cml>
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray
atomID="a1 a2 a3 a4 a5 a6 a7 a8 a9"
elementType="R C C O H H H O R"
formalCharge="0 0 0 0 0 0 0 -1 0"
sgroupRef="sg1 0 0 0 0 0 0 0 sg2"
x2="-30.4796085357666 -29.145929413938568 -27.812250292110534 -29.145929413938568 -26.4785711702825 -28.582250292110533 -27.042250292110534 -24.268407821655273 -22.728407821655274"
y2="24.08344078063965 24.853440780639648 24.08344078063965 26.393440780639647 24.853440780639648 22.749761658811614 22.749761658811614 23.770877838134766 23.770877838134766"
/>
<bondArray>
<bond atomRefs2="a1 a2" order="1" />
<bond atomRefs2="a2 a3" order="1" />
<bond atomRefs2="a2 a4" order="2" />
<bond atomRefs2="a3 a6" order="1" />
<bond atomRefs2="a3 a7" order="1" />
<bond atomRefs2="a8 a9" order="1" />
<bond atomRefs2="a5 a3" order="1" />
</bondArray>
<molecule id="sg1" role="SuperatomSgroup" title="Ph" molID="m2">
<atomArray
atomID="a10 a11 a12 a13 a14 a15"
elementType="C C C C C C"
attachmentPoint="1 0 0 0 0 0"
sgroupAttachmentPoint="1 0 0 0 0 0"
x2="-57.954067385006034 -56.620388263178 -56.620388263178 -57.95406738500604 -59.28774650683407 -59.28774650683407"
y2="51.36443145751953 50.594431457519526 49.05443145751953 48.28443145751953 49.054431457519534 50.59443145751953"
/>
<bondArray>
<bond atomRefs2="a10 a11" order="2" />
<bond atomRefs2="a10 a15" order="1" />
<bond atomRefs2="a11 a12" order="1" />
<bond atomRefs2="a12 a13" order="2" />
<bond atomRefs2="a13 a14" order="1" />
<bond atomRefs2="a14 a15" order="2" />
</bondArray>
</molecule>
<molecule id="sg2" role="SuperatomSgroup" title="tBu" molID="m3">
<atomArray
atomID="a16 a17 a18 a19"
elementType="C C C C"
attachmentPoint="1 0 0 0"
sgroupAttachmentPoint="1 0 0 0"
x2="-22.720535278320312 -23.490535278320312 -21.180535278320313 -23.490535278320312"
y2="23.660314559936523 24.993993681764557 23.660314559936523 22.32663543810849"
/>
<bondArray>
<bond atomRefs2="a16 a17" order="1" />
<bond atomRefs2="a16 a18" order="1" />
<bond atomRefs2="a16 a19" order="1" />
</bondArray>
</molecule>
</molecule>
</MChemicalStruct>
<MEFlow id="o2" arcAngle="-150.0" headSkip="0.15" headLength="0.5"
headWidth="0.4" tailSkip="0.25">
<MEFlowBasePoint atomRef="m1.a8" />
<MAtomSetPoint atomRefs="m1.a8 m1.a5" weights="0.25 0.75" />
</MEFlow>
<MEFlow id="o3" arcAngle="-182.17399554899995" headSkip="0.15"
headLength="0.5" headWidth="0.4" tailSkip="0.15">
<MAtomSetPoint atomRefs="m1.a5 m1.a3" />
<MAtomSetPoint atomRefs="m1.a2 m1.a3" />
</MEFlow>
<MEFlow id="o4" arcAngle="248.39738999999997" headSkip="0.25"
headLength="0.5" headWidth="0.4" tailSkip="0.15">
<MAtomSetPoint atomRefs="m1.a2 m1.a4" />
<MAtomSetPoint atomRefs="m1.a4" />
</MEFlow>
</MDocument>
</cml>

The molecule is exported as follows:


System.out.print(mol.toFormat(format));

where format is "mrv".  No other operation is done on the molecule.


Here is how we add a new bond inside calculateNewBonds():


            if (eFlow.sinkIsIncipBond()) {
debugPrint(SELF + "sink is MolAtom[].");
final MolAtom[] atoms = eFlow.getSinkAtoms();
debugPrint(SELF + "sink is incipient bond: ");
debugPrint(SELF + " atom1: ", atoms[0], refMol.indexOf(atoms[0]) + 1);
debugPrint(SELF + " atom2: ", atoms[1], refMol.indexOf(atoms[1]) + 1);
if (atoms[0].getBondTo(atoms[1]) == null) {
// the incipient bond has not yet been created
debugPrint(SELF + " Adding a new bond between these atoms");
final MolBond newBond = new MolBond(atoms[0], atoms[1]);
molecule.add(newBond);
final int newBondIndex = molecule.indexOf(newBond);
// note: if there are shortcut groups, new bond
// may not be added to end of list of bonds in molecule
newBonds.add(newBondIndex); // store new bond's index
bondElecCts.add(newBondIndex,
Integer.valueOf(eFlow.getNumElectrons()));
} // if there is not already a bond there

In this particular case, eFlow.getSinkAtoms() would return atoms H5 and O8.  The note in the code is not correct: The bond is indeed added to the end of the list.  The problem is that it is later moved to the middle of the list, in front of the bonds of the shortcut group, during the toFormat() call.  We need bondElecCts to be a parallel list, so the change in bondIndex is not acceptable.

ChemAxon e500b51457

22-12-2010 10:44:04

Hi Bob,

Thanks for the help, I was able to reproduce the problem. The key is the addition of a new bond. We will investigate this issue, at the moment we cannot see any obvious reason why the MRV export modifies the molecule. We will try to get back with a solution shortly.

Regards,
Erika

User 870ab5b546

22-12-2010 14:16:37

Thanks.  In the meanwhile, I was able to devise a workaround.  The order of the bonds mattered because I was keeping a parallel array of electron counts.  I changed it to a HashMap of electron counts keyed by MolBonds, so the order of the bonds no longer matters.

User 870ab5b546

20-09-2011 15:08:04










Erika wrote:

Hi Bob,

Thanks for the help, I was able to reproduce the problem. The key is the addition of a new bond. We will investigate this issue, at the moment we cannot see any obvious reason why the MRV export modifies the molecule. We will try to get back with a solution shortly.

Regards,
Erika



Have you fixed this bug?

ChemAxon e500b51457

22-09-2011 06:00:32

Hi Bob,


Unfortunately, we haven't fixed this problem yet.

Best Regards,
Erika

User 870ab5b546

22-09-2011 12:25:40

OK, please see this request.

ChemAxon a202a732bf

25-11-2011 09:01:21

Hi Bob,


this bug has been fixed in version 5.7.


Best regards,


Zsuzsa