On Sat, 13 Mar 2004, Egon Willighagen wrote:
> > public ChemModel getChemModel();
> > public ChemFile getChemFile();
> >
> > but how can I access JmolViewer or JmolModelAdapter using these?
>
> Tommi,
>
> can you explain me what you want to do? Then I can better respond to the
> actual problem. Like Christoph said, the EditBus is not fixed yet... not at
> all...
Hello,
I studied this a bit more and now I think I have a solution. It seems that
the implementations of the above methods are not yet ok, and some weeks
ago Miguel adviced I could use JmolModelAdapter to find out things about
atoms and bonds. This was the question, but now it's clear.
So I wrote an implementation for getChemModel() and it is in the
attachments (it is a cvs diff file and I hope it's readable). The first
part is for getChemModel() at JmolEditBus.java and the second part is a
minor bugfix for FrameExportModelAdapter.java. The problem in
FrameExportModelAdapter.java was that unique ID's given by AtomIterator
were incompatible to those given by BondIterator (AtomIterator generated
them starting from 1 while BondIterator started from 0).
> So let's discuss what you need, and how the EditBus can be extended to support
> this, while keeping in mind that the EditBus is a general interface and not
> Jmol specific...
Using fixes in the attachment I now have successfully read the atom/bond
information that I need at the plugin side using getChemModel() so there
is no problems with the current EditBus.
Regards,
Tommi
diff -r1.2 JmolEditBus.java
32a33,35
> import org.openscience.cdk.Bond; //th
> import org.openscience.cdk.Molecule; //th
> import org.openscience.cdk.SetOfMolecules; //th
41a45
> import org.openscience.jmol.viewer.JmolModelAdapter; //th
43a48
> import java.util.Hashtable; //th
101c106,157
< throw new NoSuchMethodError();
---
> // 1) take JmolModelAdaptor and get the atoms/bonds.
> // 2) make an AtomContainer (or a Molecule) object and copy the stuff there.
> // 3) make an new ChemModel and add Molecule (or AtomContainer) into it.
> // 4) return the ChemModel.
>
> // what the heck is "clientFile" that is needed by jma? deprecated???
>
> JmolModelAdapter jma = viewer.getExportModelAdapter();
> Molecule mol = new Molecule();
>
> Hashtable id2atom = new Hashtable();
>
> JmolModelAdapter.AtomIterator ai = jma.getAtomIterator(null);
> while (ai.hasNext())
> {
> String el_symb = ai.getElementSymbol();
> float x = ai.getX(); float y = ai.getY(); float z = ai.getZ();
> Object id = ai.getUniqueID();
>
> //System.out.println("ATOM id = " + ((Integer) id).intValue()); //DEBUG
>
> javax.vecmath.Point3d p3d = new javax.vecmath.Point3d(x, y, z);
>
> Atom a = new Atom(el_symb, p3d);
> mol.addAtom(a);
>
> id2atom.put(id, a);
> }
>
> JmolModelAdapter.BondIterator bi = jma.getBondIterator(null);
> while (bi.hasNext())
> {
> Object id1 = bi.getAtomUid1();
> Object id2 = bi.getAtomUid2();
> int order = bi.getOrder();
>
> //System.out.println("BOND id's " + ((Integer) id1).intValue() + " " +
> ((Integer) id2).intValue()); //DEBUG
>
> Atom a1 = (Atom) id2atom.get(id1);
> Atom a2 = (Atom) id2atom.get(id2);
>
> Bond b = new Bond(a1, a2, order);
> mol.addBond(b);
> }
>
> SetOfMolecules som = new SetOfMolecules(); //cm.getSetOfMolecules(); bad
> idea...
> som.addMolecule(mol);
>
> ChemModel cm = new ChemModel();
> cm.setSetOfMolecules(som);
>
> return cm;
105c161
< throw new NoSuchMethodError();
---
> throw new NoSuchMethodError();
diff -r1.3 FrameExportModelAdapter.java
80c80
< public Object getUniqueID() { return new Integer(iatom); }
---
> public Object getUniqueID() { return new Integer(iatom); } //
> counts 1,2,3...
99,100c99,100
< public Object getAtomUid1() { return new Integer(bond.atom1.atomIndex); }
< public Object getAtomUid2() { return new Integer(bond.atom2.atomIndex); }
---
> public Object getAtomUid1() { return new Integer(bond.atom1.atomIndex + 1); }
> // counts 1,2,3...
> public Object getAtomUid2() { return new Integer(bond.atom2.atomIndex + 1); }
> // counts 1,2,3...