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.)