User c23c5e9da4
09-03-2007 21:35:22
when using the arrangeComponents() method on a RxnMolecue if there is a group (like NO2) then the molecules end up positioned wrong. Please see sample code below.
import chemaxon.formats.MolImporter;
import chemaxon.struc.RxnMolecule;
import javax.swing.*;
import java.awt.*;
public class MarvinGroups {
public static void main(String[] args) throws Exception {
RxnMolecule orginalRxn = (RxnMolecule) MolImporter.importMol("<?xml version=\"1.0\" ?>\n" +
"<MDocument>\n" +
" <MChemicalStruct>\n" +
" <reaction>\n" +
" <reactantList>\n" +
" <molecule molID=\"m1\">\n" +
" <atomArray\n" +
" atomID=\"a1 a2 a3 a4 a5 a6\"\n" +
" elementType=\"N C C C C R\"\n" +
" sgroupRef=\"0 0 0 0 0 sg1\"\n" +
" x2=\"-15.364680037388974 -16.683703699331744 -16.65493642961884 -13.988121836020401 -14.016889105733304 -17.72334933421448\"\n" +
" y2=\"-0.5901183809130967 0.20465971946152162 1.744391009068011 1.6945660979252635 0.15483480831877428 2.853486976644085\"\n" +
" />\n" +
" <bondArray>\n" +
" <bond atomRefs2=\"a1 a2\" order=\"1\" />\n" +
" <bond atomRefs2=\"a1 a5\" order=\"1\" />\n" +
" <bond atomRefs2=\"a2 a3\" order=\"2\" />\n" +
" <bond atomRefs2=\"a3 a4\" order=\"1\" />\n" +
" <bond atomRefs2=\"a3 a6\" order=\"1\" />\n" +
" <bond atomRefs2=\"a4 a5\" order=\"2\" />\n" +
" </bondArray>\n" +
" <molecule id=\"sg1\" role=\"SuperatomSgroup\" title=\"NO2\"\n" +
" leftName=\"O2N\" molID=\"m2\">\n" +
" <atomArray\n" +
" atomID=\"a7 a8 a9\"\n" +
" elementType=\"N O O\"\n" +
" attachmentPoint=\"1 0 0\"\n" +
" x2=\"-29.69166660308838 -28.15166660308838 -31.231666603088378\"\n" +
" y2=\"15.166666746139526 15.166666746139526 15.166666746139526\"\n" +
" />\n" +
" <bondArray>\n" +
" <bond atomRefs2=\"a8 a7\" order=\"2\" />\n" +
" <bond atomRefs2=\"a7 a9\" order=\"2\" />\n" +
" </bondArray>\n" +
" </molecule>\n" +
" </molecule>\n" +
" </reactantList>\n" +
" <productList>\n" +
" <molecule molID=\"m3\">\n" +
" <atomArray\n" +
" atomID=\"a1 a2 a3 a4 a5 a6\"\n" +
" elementType=\"C C C C C C\"\n" +
" x2=\"9.274999618530273 7.941330277482015 7.941330277482015 9.274999618530273 10.608668959578532 10.608668959578532\"\n" +
" y2=\"2.765033904959939 1.9950169644009002 0.45498308328281745 -0.315033857276223 0.45498308328281745 1.9950169644009002\"\n" +
" />\n" +
" <bondArray>\n" +
" <bond atomRefs2=\"a1 a2\" order=\"1\" />\n" +
" <bond atomRefs2=\"a2 a3\" order=\"2\" />\n" +
" <bond atomRefs2=\"a3 a4\" order=\"1\" />\n" +
" <bond atomRefs2=\"a4 a5\" order=\"2\" />\n" +
" <bond atomRefs2=\"a5 a6\" order=\"1\" />\n" +
" <bond atomRefs2=\"a1 a6\" order=\"2\" />\n" +
" </bondArray>\n" +
" </molecule>\n" +
" </productList>\n" +
" </reaction>\n" +
" </MChemicalStruct>\n" +
"</MDocument>");
RxnMolecule rxn = new RxnMolecule();
for(int i=0; i<orginalRxn.getReactantCount(); i++) {
rxn.addComponent(orginalRxn.getReactant(i).cloneMolecule(), RxnMolecule.REACTANTS);
}
for(int i=0; i<orginalRxn.getProductCount(); i++) {
rxn.addComponent(orginalRxn.getProduct(i).cloneMolecule(), RxnMolecule.PRODUCTS);
}
rxn.arrangeComponents();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new GridLayout(2, 1));
f.add(new JLabel(new ImageIcon((Image) orginalRxn.toObject("imagew300,h300"))));
f.add(new JLabel(new ImageIcon((Image) rxn.toObject("imagew300,h300"))));
f.pack();
f.setVisible(true);
}
}
import chemaxon.formats.MolImporter;
import chemaxon.struc.RxnMolecule;
import javax.swing.*;
import java.awt.*;
public class MarvinGroups {
public static void main(String[] args) throws Exception {
RxnMolecule orginalRxn = (RxnMolecule) MolImporter.importMol("<?xml version=\"1.0\" ?>\n" +
"<MDocument>\n" +
" <MChemicalStruct>\n" +
" <reaction>\n" +
" <reactantList>\n" +
" <molecule molID=\"m1\">\n" +
" <atomArray\n" +
" atomID=\"a1 a2 a3 a4 a5 a6\"\n" +
" elementType=\"N C C C C R\"\n" +
" sgroupRef=\"0 0 0 0 0 sg1\"\n" +
" x2=\"-15.364680037388974 -16.683703699331744 -16.65493642961884 -13.988121836020401 -14.016889105733304 -17.72334933421448\"\n" +
" y2=\"-0.5901183809130967 0.20465971946152162 1.744391009068011 1.6945660979252635 0.15483480831877428 2.853486976644085\"\n" +
" />\n" +
" <bondArray>\n" +
" <bond atomRefs2=\"a1 a2\" order=\"1\" />\n" +
" <bond atomRefs2=\"a1 a5\" order=\"1\" />\n" +
" <bond atomRefs2=\"a2 a3\" order=\"2\" />\n" +
" <bond atomRefs2=\"a3 a4\" order=\"1\" />\n" +
" <bond atomRefs2=\"a3 a6\" order=\"1\" />\n" +
" <bond atomRefs2=\"a4 a5\" order=\"2\" />\n" +
" </bondArray>\n" +
" <molecule id=\"sg1\" role=\"SuperatomSgroup\" title=\"NO2\"\n" +
" leftName=\"O2N\" molID=\"m2\">\n" +
" <atomArray\n" +
" atomID=\"a7 a8 a9\"\n" +
" elementType=\"N O O\"\n" +
" attachmentPoint=\"1 0 0\"\n" +
" x2=\"-29.69166660308838 -28.15166660308838 -31.231666603088378\"\n" +
" y2=\"15.166666746139526 15.166666746139526 15.166666746139526\"\n" +
" />\n" +
" <bondArray>\n" +
" <bond atomRefs2=\"a8 a7\" order=\"2\" />\n" +
" <bond atomRefs2=\"a7 a9\" order=\"2\" />\n" +
" </bondArray>\n" +
" </molecule>\n" +
" </molecule>\n" +
" </reactantList>\n" +
" <productList>\n" +
" <molecule molID=\"m3\">\n" +
" <atomArray\n" +
" atomID=\"a1 a2 a3 a4 a5 a6\"\n" +
" elementType=\"C C C C C C\"\n" +
" x2=\"9.274999618530273 7.941330277482015 7.941330277482015 9.274999618530273 10.608668959578532 10.608668959578532\"\n" +
" y2=\"2.765033904959939 1.9950169644009002 0.45498308328281745 -0.315033857276223 0.45498308328281745 1.9950169644009002\"\n" +
" />\n" +
" <bondArray>\n" +
" <bond atomRefs2=\"a1 a2\" order=\"1\" />\n" +
" <bond atomRefs2=\"a2 a3\" order=\"2\" />\n" +
" <bond atomRefs2=\"a3 a4\" order=\"1\" />\n" +
" <bond atomRefs2=\"a4 a5\" order=\"2\" />\n" +
" <bond atomRefs2=\"a5 a6\" order=\"1\" />\n" +
" <bond atomRefs2=\"a1 a6\" order=\"2\" />\n" +
" </bondArray>\n" +
" </molecule>\n" +
" </productList>\n" +
" </reaction>\n" +
" </MChemicalStruct>\n" +
"</MDocument>");
RxnMolecule rxn = new RxnMolecule();
for(int i=0; i<orginalRxn.getReactantCount(); i++) {
rxn.addComponent(orginalRxn.getReactant(i).cloneMolecule(), RxnMolecule.REACTANTS);
}
for(int i=0; i<orginalRxn.getProductCount(); i++) {
rxn.addComponent(orginalRxn.getProduct(i).cloneMolecule(), RxnMolecule.PRODUCTS);
}
rxn.arrangeComponents();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new GridLayout(2, 1));
f.add(new JLabel(new ImageIcon((Image) orginalRxn.toObject("imagew300,h300"))));
f.add(new JLabel(new ImageIcon((Image) rxn.toObject("imagew300,h300"))));
f.pack();
f.setVisible(true);
}
}