Egon -- that was a bug in BondCollection -- returning atomIndex, not
modelIndex. Fixed in SVN. Or use

           int modelIndex =
set.getBondAt(bondIndex).getAtom1().getModelIndex();


On Fri, Oct 30, 2009 at 9:58 AM, Egon Willighagen <
[email protected]> wrote:

> Bob,
>
> I am using 11.8.7 in Jmol and writing CML serialization... my current
> code looks like (JmolMolecule actually just wraps a CMLMolecule):
>
>        List<IJmolMolecule> mols = new ArrayList<IJmolMolecule>();
>        ModelSet set = jmolPanel.getViewer().getModelSet();
>        System.out.println("model count: " + set.getModelCount());
>        Map<Integer,CMLMolecule> models = new
> HashMap<Integer,CMLMolecule>();
>        for (int atomIndex=0; atomIndex<set.getAtomCount(); atomIndex++) {
>            int modelIndex = set.getAtomModelIndex(atomIndex);
>            System.out.println("modelindex: " + modelIndex);
>            CMLMolecule model = models.get(modelIndex);
>            if (model == null) {
>                model = new CMLMolecule();
>                models.put(modelIndex, model);
>            }
>            CMLAtom atom = new CMLAtom(set.getAtomName(atomIndex));
>            atom.setElementType(set.getAtomLabel(atomIndex));
>            Point3f coord = set.getAtomPoint3f(atomIndex);
>            atom.setX3(coord.x);
>            atom.setY3(coord.y);
>            atom.setZ3(coord.z);
>            model.addAtom(atom);
>            System.out.println("Atom: " + atom.toXML());
>        }
>        for (int bondIndex=0; bondIndex<set.getBondCount(); bondIndex++) {
>            int modelIndex = set.getBondModelIndex(bondIndex);
>            System.out.println("modelindex: " + modelIndex);
>            CMLMolecule model = models.get(modelIndex);
>            if (model == null) {
>                model = new CMLMolecule();
>                models.put(modelIndex, model);
>            }
>            System.out.println("model: " + model.toXML());
>            System.out.println("bond: " + bondIndex);
>            System.out.println(" atom1: " +
> set.getBondAtom1(bondIndex).getAtomName());
>            System.out.println(" atom2: " +
> set.getBondAtom2(bondIndex).getAtomName());
>            CMLBond bond = new CMLBond(
>
>  model.getAtomById(set.getBondAtom1(bondIndex).getAtomName()),
>                model.getAtomById(set.getBondAtom2(bondIndex).getAtomName())
>            );
>            short order = set.getBondOrder(bondIndex);
>            if (order == 1) bond.setOrder("s");
>            if (order == 2) bond.setOrder("d");
>            if (order == 3) bond.setOrder("t");
>            model.addBond(bond);
>        }
>        for (CMLMolecule model : models.values())
>            mols.add(new JmolMolecule(model));
>        return mols;
>
> Now, this fails because the set.getBondModelIndex(bondIndex) is
> inconsistent...
>
> For the second atom, it actually returns model index = 2 while the
> model count is just 1:
>
> The above code gives to STDOUT:
>
> model count: 1
> modelindex: 0
> Atom: <atom id="C1" x3="-3.0290000438690186" y3="3.165299892425537"
> z3="-2.7702999114990234" />
> modelindex: 0
> Atom: <atom id="C2" x3="-2.1698999404907227" y3="2.392199993133545"
> z3="-3.8304998874664307" />
> modelindex: 0
> Atom: <atom id="C3" x3="-2.5147998332977295" y3="2.2920000553131104"
> z3="-1.2253999710083008" />
> modelindex: 0
> Atom: <atom id="C4" x3="-0.711199939250946" y3="2.7802999019622803"
> z3="-3.5488998889923096" />
> modelindex: 0
> Atom: <atom id="C5" x3="-0.7472000122070312" y3="2.002000093460083"
> z3="-1.2106000185012817" />
> modelindex: 0
> Atom: <atom id="C6" x3="-0.14259999990463257" y3="2.2487998008728027"
> z3="-2.3314998149871826" />
> modelindex: 0
> model: <molecule
> xmlns="http://www.xml-cml.org/schema";><atomArray><atom id="C1"
> x3="-3.0290000438690186" y3="3.165299892425537"
> z3="-2.7702999114990234" /><atom id="C2" x3="-2.1698999404907227"
> y3="2.392199993133545" z3="-3.8304998874664307" /><atom id="C3"
> x3="-2.5147998332977295" y3="2.2920000553131104"
> z3="-1.2253999710083008" /><atom id="C4" x3="-0.711199939250946"
> y3="2.7802999019622803" z3="-3.5488998889923096" /><atom id="C5"
> x3="-0.7472000122070312" y3="2.002000093460083"
> z3="-1.2106000185012817" /><atom id="C6" x3="-0.14259999990463257"
> y3="2.2487998008728027" z3="-2.3314998149871826"
> /></atomArray></molecule>
> bond: 0
>  atom1: C1
>  atom2: C2
> modelindex: 2
> model: <molecule xmlns="http://www.xml-cml.org/schema"; />
> bond: 1
>  atom1: C3
>  atom2: C1
>
> As you can see, the last modelIndex = 2, and does not allow me to look
> up the CMLMolecule matching that model number, resulting in the atoms
> C3 and C1 for the second atom not to be found, and consequently giving
> this CML error (because the CMLMolecule for the second 'model' does
> not contain any molecules, let alone C3 and C1):
>
> Caused by: java.lang.RuntimeException: Atoms in bond muct not be null
>        at org.xmlcml.cml.element.CMLBond.<init>(CMLBond.java:190)
>        at
> net.bioclipse.jmol.editors.JmolEditor.getJmolMolecules(JmolEditor.java:647)
>        at
> net.bioclipse.jmol.business.JmolManager.getMolecules(JmolManager.java:142)
>
> I have no clue why the ModelSet return 2 for the second bond... the
> input is this MDL molfile:
>
>
>  CDK    10/30/09,16:3
>
>  6  6  0  0  0  0  0  0  0  0999 V2000
>   -3.0290    3.1653   -2.7703 C   0  0  0  0  0  0  0  0  0  0  0  0
>   -2.1699    2.3922   -3.8305 C   0  0  0  0  0  0  0  0  0  0  0  0
>   -2.5148    2.2920   -1.2254 C   0  0  0  0  0  0  0  0  0  0  0  0
>   -0.7112    2.7803   -3.5489 C   0  0  0  0  0  0  0  0  0  0  0  0
>   -0.7472    2.0020   -1.2106 C   0  0  0  0  0  0  0  0  0  0  0  0
>   -0.1426    2.2488   -2.3315 C   0  0  0  0  0  0  0  0  0  0  0  0
>  1  2  1  0  0  0  0
>  3  1  1  0  0  0  0
>  2  4  1  0  0  0  0
>  5  3  1  0  0  0  0
>  4  6  1  0  0  0  0
>  6  5  2  0  0  0  0
> M  END
>
> Is this a bug in ModelSet.getBondModelIndex() or am I doing something
> wrong?
>
> Egon
>
> --
> Post-doc @ Uppsala University
> Homepage: http://egonw.github.com/
> Blog: http://chem-bla-ics.blogspot.com/
> PubList: http://www.citeulike.org/user/egonw/tag/papers
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> Jmol-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jmol-developers
>



-- 
Robert M. Hanson
Professor of Chemistry
St. Olaf College
1520 St. Olaf Ave.
Northfield, MN 55057
http://www.stolaf.edu/people/hansonr
phone: 507-786-3107


If nature does not answer first what we want,
it is better to take what answer we get.

-- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Jmol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-developers

Reply via email to