Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#624 Custom atom/bond properties do not survive CML roundtrip

cdk-1.2.x
closed
Stefan Kuhn
9
2012-11-03
2008-03-31
Anonymous
No

Custom atom and/or bond properties set in a molecule are saved by CMLWriter() as <scalar...> elements, however, the CMLReader() does not parse them back. The attached JUnit file illustrates the problem.

Discussion

  • JUnit test file for custom atom/bond properties

     
  • Stefan Kuhn
    Stefan Kuhn
    2008-07-01

    Logged In: YES
    user_id=452972
    Originator: NO

    Tests are in CMLRoundtripTest. Note I commented out the "compare whole xml" asserts, since these don't make sense for me.

     
  • Logged In: NO

    What did you replace those whole-CML-compares with?

     
  • Stefan Kuhn
    Stefan Kuhn
    2008-07-01

    Logged In: YES
    user_id=452972
    Originator: NO

    With nothing right now. There are still tests for the properties. I think this would be the way to go, i. e. if other things are liable to be lost or added, test them individually. The whole-xml-test has the disadvantage that e. g. a change of attribute order makes them fail

     
  • Logged In: YES
    user_id=1025007
    Originator: NO

    Bug found when reading from a CML where atoms has more than one property.
    - only a single property is assigned to an atom
    - properties are not assigned on correct atoms (scattered across atoms)
    - atom aromatic flags are lost

    Example CMLs and test are attached.

     
  • Logged In: YES
    user_id=1025007
    Originator: NO

    Can't find how to attach files - perhaps because the bug has a closed status?

    Original CML

    <molecule id="m1" xmlns="http://www.xml-cml.org/schema"> <atomArray> <atom id="1" elementType="C" formalCharge="0" hydrogenCount="3"> <scalar title="PropSecond_ID1" dataType="xsd:string">1</scalar> <scalar title="PropFirst_ID1" dataType="xsd:string">1</scalar> </atom> <atom id="2" elementType="C" formalCharge="0" hydrogenCount="2"> <scalar title="PropFirst_ID2" dataType="xsd:string">2</scalar> <scalar title="PropSecond_ID2" dataType="xsd:string">2</scalar> </atom> <atom id="3" elementType="C" formalCharge="0" hydrogenCount="2"> <scalar title="PropSecond_ID3" dataType="xsd:string">3</scalar> <scalar title="PropFirst_ID3" dataType="xsd:string">3</scalar> </atom> <atom id="4" elementType="C" formalCharge="0" hydrogenCount="3"> <scalar title="PropFirst_ID4" dataType="xsd:string">4</scalar> <scalar title="PropSecond_ID4" dataType="xsd:string">4</scalar> </atom> </atomArray> <bondArray> <bond id="b1" atomRefs2="2 1" order="S"/> <bond id="b2" atomRefs2="3 2" order="S"/> <bond id="b3" atomRefs2="4 3" order="S"/> </bondArray> </molecule>

    CML after reading and writing the molecule above

    <molecule id="m1" xmlns="http://www.xml-cml.org/schema"> <atomArray> <atom id="1" elementType="C" formalCharge="0" hydrogenCount="3" isotopeNumber="12"> <scalar title="PropSecond_ID1" dataType="xsd:string">1</scalar> </atom> <atom id="2" elementType="C" formalCharge="0" hydrogenCount="2" isotopeNumber="12"> <scalar title="PropFirst_ID1" dataType="xsd:string">1</scalar> </atom> <atom id="3" elementType="C" formalCharge="0" hydrogenCount="2" isotopeNumber="12"> <scalar title="PropFirst_ID2" dataType="xsd:string">2</scalar> </atom> <atom id="4" elementType="C" formalCharge="0" hydrogenCount="3" isotopeNumber="12"> <scalar title="PropSecond_ID2" dataType="xsd:string">2</scalar> </atom> </atomArray> <bondArray> <bond id="b1" atomRefs2="2 1" order="S"/> <bond id="b2" atomRefs2="3 2" order="S"/> <bond id="b3" atomRefs2="4 3" order="S"/> </bondArray> </molecule>
     
  • Logged In: YES
    user_id=25678
    Originator: NO

    Reopened bug report. Not fixed in trunk/.

     
  • Logged In: YES
    user_id=1025007
    Originator: NO

    Not a fix (yet), but hope it will help somehow.

    The culprit seems to be the way atom properties are hanled in CMLCoreModule

    Line 117
    protected List<String> atomCustomProperty;

    During the execution the list will contain something like

    [PropSecond_ID1, 1, PropFirst_ID1, 1, PropFirst_ID2, 2, PropSecond_ID2, 2]

    And finally when assigning properties to an atom, it is implicitly assumed only a single property is taken from the atomCustomProperty list and the next properties are left for the subsequent atoms, resulting in the shifted pattern as in the example.

    Line 1142
    protected void storeAtomData() {
    ....
    Line 1161
    ...
    Iterator customs = atomCustomProperty.iterator();
    ...
    Line 1409
    if(customs.hasNext()){
    String nextCustom = (String)customs.next();
    if(!nextCustom.equals("")){
    currentAtom.setProperty(nextCustom,(String)customs.next());
    }
    }

     
  • Stefan Kuhn
    Stefan Kuhn
    2008-09-08

    Logged In: YES
    user_id=452972
    Originator: NO

    Test added, bug fixed.