Molecule::getDocument() returns NULL

User 953c0d67b0

27-02-2006 20:22:05

Why would Molecule::getDocument() return null????





The following code demonstrates what's happening.





Strange that when given the FIRST xml example, getDocument() returns null.


But it doesn't with the second xml example (only difference...I added a


Rectangle to the drawing!!!). [ in Marvin, I just drew a Carbon Atom,


and CH4 appeared as usual. Just drew a rectangle around that for the


second XML]





public void test(String xmlString) {


System.out.println(xmlString); // looks good


MolImporter importer = new MolImporter();


Molecule aMolecule = importer.importMol(xmlString);


System.out.println(aMolecule.getAtomCount()); // prints "1"





// all seems well up to this point!





MDocument mDoc = aMolecule.getDocument();


if (mDoc == null)


System.out.println("MDocument is empty!!!!");


// mDoc is NULL with first xml given below, is NOT NULL with 2nd!


}





THIS IS THE XML GIVEN TO THE METHOD: (getDocument() returns NULL)





<?xml version="1.0" encoding="Cp1252" ?>


<MDocument>


<MChemicalStruct>


<molecule molID="m1">


<atomArray


atomID="a1"


elementType="C"


x2="-5.483333110809326"


y2="0.46666666865348816"


/>


<bondArray>


</bondArray>


</molecule>


</MChemicalStruct>


</MDocument>





XML2: getDocument() does NOT return NULL





<?xml version="1.0" encoding="Cp1252" ?>


<MDocument>


<MChemicalStruct>


<molecule molID="m1">


<atomArray


atomID="a1"


elementType="C"


x2="-5.483333110809326"


y2="0.46666666865348816"


/>


<bondArray>


</bondArray>


</molecule>


</MChemicalStruct>


<MRectangle>


<MPoint x="-7.233333110809326" y="1.8666666746139526" />


<MPoint x="-3.2666666507720947" y="1.8666666746139526" />


<MPoint x="-3.2666666507720947" y="-1.1083333492279053" />


<MPoint x="-7.233333110809326" y="-1.1083333492279053" />


</MRectangle>


</MDocument>

ChemAxon 7c2d26e5cf

28-02-2006 00:10:39

Quote:
But it doesn't with the second xml example (only difference...I added a


Rectangle to the drawing!!!). [ in Marvin, I just drew a Carbon Atom,
Molecule class is the representation of the chemical structure. MDocument is required to be able to store non-chemical info (like rectangle, arrow or textbox).


Each MDocument contains one or more Molecule objects but there may be Molecule objects without MDocument-s. Molecule.getDocument() determines the parent (document) of the molecule.


If you draw a molecule that does not contains graphical components (like rectangle), creating MDocument is needless.


Thus, Molecule.getDocument() is null if your molecule does not contains any graphical component.


The <MDocument> tag is the main level in an MRV document. It can contains one or more chemical structures. As you can see above, there is a bit difference between the role of the <MDocument> tag and the MDocument class.

User 953c0d67b0

28-02-2006 03:44:50

Ok that makes sense. Yes, because the no-graphics XML has the


<MDOCUMENT> tag, I assumed the method would return SOMETHING!





Thanks for the tip!





Kevin