Reading Marvin Document with more than one <molecule>

User 953c0d67b0

05-03-2006 23:55:17

I have been using the following code to read mrv documents into my


program:





Molecule molecule = MolImporter.importMol(marvinString);





But now it is throwing an IO exception:


Line 135: java.io.IOException: cannot find atom "m1.a19"


(value of marvinString is below)





According to API for MolImporter, it only reads one <molecule>


from a document; my document has super groups in several


molecules.





What is the best way to import such a document into a java program?


I haven't found a simple IMPORT for this one...perhaps I need a


loop to import each <molecule> individually????





Thanks,


Kevin


========================





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


<MDocument>


  <MChemicalStruct>


    <molecule molID="m1">


      <atomArray


          atomID="a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15"


          elementType="Sn R R R Br C C C C C Sn R R R H"


          radical="0 0 0 0 0 0 0 0 0 monovalent 0 0 0 0 0"


          sgroupRef="0 sg1 sg2 sg3 0 0 0 0 0 0 0 sg4 sg5 sg6 0"


          x2="0.2069748081171232 -0.5630251918828764 -1.2805509643680422 0.2069748081171232 0.9500015423357207 4.640308178951712 3.3066681789517123 5.973948178951712 5.973948178951712 3.3066681789517123 2.2278995215510182 1.4578995215510187 0.7403737490658528 2.2278995215510182 2.7670559130008465"


          y2="2.6433452152856667 3.9770243371137024 2.244763885827785 1.1033452152856675 4.631345173562416 1.9363451020368423 4.246345102036843 4.246345102036843 2.706345102036842 2.706345102036842 -0.9766195382084515 0.35705958361958423 -1.375200867666333 -2.5166195382084506 0.46591655685426825"


          />


      <bondArray>


        <bond atomRefs2="a1 a5" order="1" />


        <bond atomRefs2="a6 a10" order="1" />


        <bond atomRefs2="a6 a9" order="1" />


        <bond atomRefs2="a10 a7" order="1" />


        <bond atomRefs2="a7 a8" order="1" />


        <bond atomRefs2="a8 a9" order="1" />


        <bond atomRefs2="a11 a15" order="1" />


        <bond atomRefs2="a1 a2" order="1" />


        <bond atomRefs2="a1 a3" order="1" />


        <bond atomRefs2="a1 a4" order="1" />


        <bond atomRefs2="a11 a12" order="1" />


        <bond atomRefs2="a11 a13" order="1" />


        <bond atomRefs2="a11 a14" order="1" />


      </bondArray>


      <molecule id="sg1" role="SuperatomSgroup" title="Bu" molID="m2">


        <atomArray


            atomID="a16 a17 a18 a19"


            elementType="C C C C"


            attachmentPoint="1 0 0 0"


            x2="1.3324934908591768 -0.0011856309688580424 -1.3348647527968938 -2.6685438746249295"


            y2="4.486678498948464 3.716678498948463 4.4866784989484625 3.716678498948463"


            />


        <bondArray>


          <bond atomRefs2="a16 a17" order="1" />


          <bond atomRefs2="a17 a18" order="1" />


          <bond atomRefs2="a18 a19" order="1" />


        </bondArray>


      </molecule>


      <molecule id="sg2" role="SuperatomSgroup" title="Bu" molID="m3">


        <atomArray


            atomID="a20 a21 a22 a23"


            elementType="C C C C"


            attachmentPoint="1 0 0 0"


            x2="0.574160284682419 -0.7595188371456159 -2.0931979589736516 -3.4268770808016873"


            y2="2.7950118884095048 2.0250118884095034 2.795011888409503 2.0250118884095034"


            />


        <bondArray>


          <bond atomRefs2="a20 a21" order="1" />


          <bond atomRefs2="a21 a22" order="1" />


          <bond atomRefs2="a22 a23" order="1" />


        </bondArray>


      </molecule>


      <molecule id="sg3" role="SuperatomSgroup" title="Bu" molID="m4">


        <atomArray


            atomID="a24 a25 a26 a27"


            elementType="C C C C"


            attachmentPoint="1 0 0 0"


            x2="2.0324937769614717 0.6988146551334369 -0.6348644666945988 -1.9685435885226346"


            y2="1.7450118839391564 0.975011883939155 1.7450118839391546 0.975011883939155"


            />


        <bondArray>


          <bond atomRefs2="a24 a25" order="1" />


          <bond atomRefs2="a25 a26" order="1" />


          <bond atomRefs2="a26 a27" order="1" />


        </bondArray>


      </molecule>


      <molecule id="sg4" role="SuperatomSgroup" title="Bu" molID="m5">


        <atomArray


            atomID="a28 a29 a30 a31"


            elementType="C C C C"


            attachmentPoint="1 0 0 0"


            x2="3.3534182042930727 2.019739082465037 0.6860599606370013 -0.647619161191034"


            y2="0.8667137454543461 0.09671374545434475 0.8667137454543443 0.09671374545434475"


            />


        <bondArray>


          <bond atomRefs2="a28 a29" order="1" />


          <bond atomRefs2="a29 a30" order="1" />


          <bond atomRefs2="a30 a31" order="1" />


        </bondArray>


      </molecule>


      <molecule id="sg5" role="SuperatomSgroup" title="Bu" molID="m6">


        <atomArray


            atomID="a32 a33 a34 a35"


            elementType="C C C C"


            attachmentPoint="1 0 0 0"


            x2="2.595084998116315 1.2614058762882792 -0.07227324553975611 -1.4059523673677918"


            y2="-0.8249528650846134 -1.5949528650846148 -0.8249528650846152 -1.5949528650846148"


            />


        <bondArray>


          <bond atomRefs2="a32 a33" order="1" />


          <bond atomRefs2="a33 a34" order="1" />


          <bond atomRefs2="a34 a35" order="1" />


        </bondArray>


      </molecule>


      <molecule id="sg6" role="SuperatomSgroup" title="Bu" molID="m7">


        <atomArray


            atomID="a36 a37 a38 a39"


            elementType="C C C C"


            attachmentPoint="1 0 0 0"


            x2="4.053418490395368 2.719739368567332 1.3860602467392962 0.0523811249112609"


            y2="-1.8749528695549618 -2.644952869554963 -1.8749528695549635 -2.644952869554963"


            />


        <bondArray>


          <bond atomRefs2="a36 a37" order="1" />


          <bond atomRefs2="a37 a38" order="1" />


          <bond atomRefs2="a38 a39" order="1" />


        </bondArray>


      </molecule>


    </molecule>


  </MChemicalStruct>


  <MEFlow arcAngle="206.91" headSkip="0.15" headFlags="2" headLength="0.5"


          headWidth="0.4" tailSkip="0.25">


    <MAtomSetPoint atomRefs="m1.a19" />


    <MAtomSetPoint atomRefs="m1.a19 m1.a24" />


  </MEFlow>


  <MEFlow arcAngle="-150.0" headSkip="0.15" headFlags="2" headLength="0.5"


          headWidth="0.4" tailSkip="0.15">


    <MAtomSetPoint atomRefs="m1.a20 m1.a24" />


    <MAtomSetPoint atomRefs="m1.a19 m1.a24" />


  </MEFlow>


  <MEFlow arcAngle="248.39738999999997" headSkip="0.25" headFlags="2"


          headLength="0.5" headWidth="0.4" tailSkip="0.15">


    <MAtomSetPoint atomRefs="m1.a20 m1.a24" />


    <MAtomSetPoint atomRefs="m1.a20" />


  </MEFlow>


  <MRectangle>


    <MPoint x="-1.7763582691645903" y="5.151678451264747" />


    <MPoint x="6.681974865486595" y="5.151678451264747" />


    <MPoint x="6.681974865486595" y="-3.4233215964189685" />


    <MPoint x="-1.7763582691645903" y="-3.4233215964189685" />


  </MRectangle>


</MDocument>

ChemAxon 7c2d26e5cf

07-03-2006 11:37:38

Hi Kevin,


Your MRV source is invalid. Electron flows point to s-group members. ("a19" is the ID of an atom in an s-group, not in the main graph.) Currently, MarvinSketch does not support drawing electron flows between contracted s-groups.


How did you create this MRV file?


By the way, next time please use the [code] ... [/code] tags to insert a molecule source in your comment or upload it as an attachment. If you don't use these tags, browser will delete extra spaces from your code.


By using format tags, comments would be more readable to us and other users.

User 953c0d67b0

07-03-2006 23:31:33

Hmm, it is a VERY LONG story as to how I get this MRV document. I'll


investigate the many transformations it goes through from the


"original" up to the point where the error occurs (Its a long sequence


of API calls on what starts out as a valid MRV document with


SGroups).





You may ignore this question ... if I find something I need help with,


I'll post another reply.





Thanks for pointing out that this particular document is invalid....


I hadn't noticed!





Kevin

User 953c0d67b0

08-03-2006 01:46:29

Problem solved! I thought you might be interested in what happened:


Given: an MRV document with Sgroups and MEFlows (from Marvin Sketch)





- extract list of molecules (Molecule::convertToFrags())


- extract list of MEFlow's from the MDocument





THEN





- create a new molecule with a subset of the original molecules and flows


(obviously using only the flows working on the subset of molecules)





- By the time I get to the following code, the "subsets" of molecules


and flows are now each in their own array....so the point is to take


all molecules and all flows in the 2 arrays (ArrayLists actually) and


combine into one Molecule object:





Code:



// ArrayList<Molecule> molecule = subset of original frag list


// ArrayList<MEFlow> flow = subset of original flow list


private String fun(ArrayList<Molecule> molecule, ArrayList<MEFlow> flow)


{


    int i;


   Molecule allMolecules = new Molecule();


   for (i=0; i<molecule.size(); i++)


         allMolecules.fuse(molecule.get(i)); // <-- problem here





   allMolecules.expandSgroups();  // <--- fix here


   


   MDocument mDoc = new MDocument(allMolecules);


   


   for (i=0; i<flow.size(); i++)


      mDoc.addObject(flow.get(i));





    return mDoc.exportToFormat("mrv");


    // this is the origin of the MRV doc in the original post


}








Originally I did NOT have the expandSgroups() instruction. Apparently,


eventhough I'm sure the Sgroups were EXPANDED in the molecule


list, fuse() seems to have CONTRACTED them.





So to answer your question: "How did you get this MRV document"...


that's it.





Obviously the "fix" was to add the expandSgroups() invocation.





Topic terminated! (I think)





FYI,





Kevin