shortcut group coordinates after contraction

User 870ab5b546

15-10-2014 13:45:07

When we have students draw a mechanism or a multistep synthesis, we have them draw a series of molecules, each of which must be located within a rectangle. I've come across a problem, and I'm not sure whether it's a bug or a feature. A student has submitted a drawing which contains this individual molecule (obtained from fragmenting the Molecule of the whole drawing):


<?xml version="1.0" encoding="UTF-8"?>
<cml xmlns="http://www.chemaxon.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.chemaxon.com/marvin/schema/mrvSchema_14_8_4.xsd" version="ChemAxon file format v14.8.4, generated by v14.9.8.0">
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray atomID="a1 a2 a3 a4 a5 a6 a7 a8 a9" elementType="C R C C C O O C C" sgroupRef="0 sg2 0 0 0 sg1 0 sg1 sg1" attachmentPoint="0 0 0 0 0 1 0 0 0" sgroupAttachmentPoint="0 0 0 0 0 1 0 0 0" x2="20.84526680419656 22.178945926024596 19.51158768236852 19.51158768236852 18.177908560540487 16.844229438712453 18.177908560540487 15.51055031688442 15.51055031688442" y2="-0.4246380682505705 -1.1946380682505704 -1.1946380682505708 -2.734638068250571 -0.4246380682505705 -1.1946380682505726 1.1153619317494297 -0.42463806825057315 1.1153619317494243"/>
<bondArray>
<bond id="b1" atomRefs2="a1 a2" order="1"/>
<bond id="b2" atomRefs2="a1 a3" order="1"/>
<bond id="b3" atomRefs2="a3 a4" order="1">
<bondStereo>W</bondStereo>
</bond>
<bond id="b4" atomRefs2="a3 a5" order="1"/>
<bond id="b5" atomRefs2="a5 a6" order="1"/>
<bond id="b6" atomRefs2="a5 a7" order="2"/>
<bond id="b7" atomRefs2="a8 a6" order="1"/>
<bond id="b8" atomRefs2="a9 a8" order="1"/>
</bondArray>
<molecule id="sg1" role="SuperatomSgroup" title="EtO" leftName="EtO" rightName="OEt" molID="m2">
<AttachmentPointArray>
<attachmentPoint atom="a6" order="1" bond="b5"/>
</AttachmentPointArray>
</molecule>
<molecule id="sg2" role="SuperatomSgroup" title="Ph" molID="m3">
<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="18.32894592602459 17.55894592602459 18.328945926024595 19.868945926024594 20.63894592602459 19.86894592602459" y2="-2.5283171900786066 -1.1946380682505682 0.139041053577467 0.1390410535774652 -1.1946380682505717 -2.5283171900786066"/>
<bondArray>
<bond id="b9" atomRefs2="a10 a11" order="2"/>
<bond id="b10" atomRefs2="a10 a15" order="1"/>
<bond id="b11" atomRefs2="a11 a12" order="1"/>
<bond id="b12" atomRefs2="a12 a13" order="2"/>
<bond id="b13" atomRefs2="a13 a14" order="1"/>
<bond id="b14" atomRefs2="a14 a15" order="2"/>
</bondArray>
<AttachmentPointArray>
<attachmentPoint atom="a10" order="1" bond="b1"/>
</AttachmentPointArray>
</molecule>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>

Note that the EtO group is in an expanded state. The coordinates of all of the atoms in the EtO group are located within rectangles in the drawing. We then contract all the shortcut groups with the command:


aMolecule.contractSgroups(Expandable.LEAVE_COORDS_UNCHANGED);

This action generates coordinates of [0, 0] for the EtO shortcut group, even though the atoms of the shortcut group are left where they belong:


<?xml version="1.0" encoding="UTF-8"?>
<cml xmlns="http://www.chemaxon.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.chemaxon.com/marvin/schema/mrvSchema_14_8_4.xsd" version="ChemAxon file format v14.8.4, generated by v14.9.8.0">
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray atomID="a1 a2 a3 a4 a5 a6 a7" elementType="C R C C C R O" sgroupRef="0 sg2 0 0 0 sg1 0" x2="20.84526680419656 22.178945926024596 19.51158768236852 19.51158768236852 18.177908560540487 0.0 18.177908560540487" y2="-0.4246380682505705 -1.1946380682505704 -1.1946380682505708 -2.734638068250571 -0.4246380682505705 0.0 1.1153619317494297"/>
<bondArray>
<bond id="b1" atomRefs2="a1 a2" order="1"/>
<bond id="b2" atomRefs2="a1 a3" order="1"/>
<bond id="b3" atomRefs2="a3 a4" order="1">
<bondStereo>W</bondStereo>
</bond>
<bond id="b4" atomRefs2="a3 a5" order="1"/>
<bond id="b5" atomRefs2="a5 a6" order="1"/>
<bond id="b6" atomRefs2="a5 a7" order="2"/>
</bondArray>
<molecule id="sg1" role="SuperatomSgroup" title="EtO" leftName="EtO" rightName="OEt" molID="m2">
<atomArray atomID="a8 a9 a10" elementType="O C C" attachmentPoint="1 0 0" sgroupAttachmentPoint="1 0 0" x2="16.844229438712453 15.51055031688442 15.51055031688442" y2="-1.1946380682505726 -0.42463806825057315 1.1153619317494243"/>
<bondArray>
<bond id="b7" atomRefs2="a9 a8" order="1"/>
<bond id="b8" atomRefs2="a10 a9" order="1"/>
</bondArray>
<AttachmentPointArray>
<attachmentPoint atom="a8" order="1" bond="b5"/>
</AttachmentPointArray>
</molecule>
<molecule id="sg2" role="SuperatomSgroup" title="Ph" molID="m3">
<atomArray atomID="a11 a12 a13 a14 a15 a16" elementType="C C C C C C" attachmentPoint="1 0 0 0 0 0" sgroupAttachmentPoint="1 0 0 0 0 0" x2="18.32894592602459 17.55894592602459 18.328945926024595 19.868945926024594 20.63894592602459 19.86894592602459" y2="-2.5283171900786066 -1.1946380682505682 0.139041053577467 0.1390410535774652 -1.1946380682505717 -2.5283171900786066"/>
<bondArray>
<bond id="b9" atomRefs2="a11 a12" order="2"/>
<bond id="b10" atomRefs2="a11 a16" order="1"/>
<bond id="b11" atomRefs2="a12 a13" order="1"/>
<bond id="b12" atomRefs2="a13 a14" order="2"/>
<bond id="b13" atomRefs2="a14 a15" order="1"/>
<bond id="b14" atomRefs2="a15 a16" order="2"/>
</bondArray>
<AttachmentPointArray>
<attachmentPoint atom="a11" order="1" bond="b1"/>
</AttachmentPointArray>
</molecule>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>

Then, when I loop through all of the atoms of the molecule (which I get with getAtomArray()), when it reaches the EtO group, it finds that it is not located within a rectangle.


So. my question is, is there a bug in the contractSgroups() method that causes it to assign coordinates of [0, 0] to the shortcut group? (It seems to me that it should assign the coordinates of the first attachment point.) Or am I using the API incorrectly? Do you have a suggestion for a solution or workaround? 


I should also note that we used to use setGUIContracted(true) instead of contractSgroups(), on a previous recommendation, but we changed back to contractSgroups() recently because you have deprecated setGUIContracted().

ChemAxon a202a732bf

17-10-2014 07:28:24

Hi Bob, 


If the methods aMolecule.contractSgroups() or aMolecule.expandSgroups() are called with option Expandable.LEAVE_COORDS_UNCHANGED then new coordinates will not be calculated.  Coordinates for the SgroupAtom will not be recalculated if the group is contracted and no new new coordinates will be calculated for the contained atoms if the group is expanded. In your case the SgroupAtom must have been created with default (0, 0) coordinates since the group was originally expanded, and it was not adjusted at the contraction. This option is introduced for performance reasons to eliminate the cost of coordinate calculation if contract/expand is performed only to obtain the required topology of the molecule.


To get the right coordinates, please do not use this option setting or simply call contractSgroups() with no parameters.


Best regards,


Zsuzsa