On Thursday 20 May 2004 00:19, Miguel wrote:
> Egon wrote:
> > it seems that I have made progress with CDK wrapping JME IO classes...
> > I've added a cdk.io.JMEReader, but I have some problems...
>
> I got confused earlier because I do not understand why this is called 'JME'

The code should actually be in cdk.libio.jmol.Convertor... in that class 
already was some code for some weeks now... but I needed a example where it 
was used... CDK does not have a JME reader yet, so that was my example use of 
the more general ModelAdapter to AtomContainer code :)

> In any case:
> > The code I use looks like:
> >
> >     private Molecule readMolecule(Molecule molecule) throws CDKException {
>
> // use this hashtable to map the ModelAdapter Unique IDs to
> // our cdk Atoms
> Hashtable htMapUidsToAtoms = new Hashtable();
>
> >         ModelAdapter adapter = new SmarterModelAdapter(null);
> >         Object model = adapter.openBufferedReader("", input);
> >         AtomIterator atomIterator = adapter.getAtomIterator(model);
> >         while (atomIterator.hasNext()) {
> >             Atom atom = new Atom(atomIterator.getElementSymbol());
> >             atom.setX3d(atomIterator.x);
>
> this should be atomIterator.getX()
>
> >             atom.setY3d(atomIterator.y);
>
> atomIterator.getY()
>
> >             atom.setZ3d(atomIterator.z);
>
> atomIterator.getZ()
>
> >             molecule.addAtom(atom);
>
> Object atomUID = atomIterator.getUniqueID();
>
> // associate this unique ID with the atom so that
> // we can retrieve it later to connect the bonds
> htMapUidsToAtoms.put(atomUID, atom); // where hash
>
> >         }
> >         BondIterator bondIterator = adapter.getBondIterator(model);
> >         while (bondIterator.hasNext()) {
>
> // delete these lines ...
>
> >             Object atom1 = bondIterator.getgetAtomUid1();
> >             Object atom2 = bondIterator.getgetAtomUid2();
>
> // ... down to here
>
> // you need to understand these next 4 lines
> // if it is not clear then tell me
> Object uid1 = bondIterator.getAtomUid1();
> Object uid2 = bondIterator.getAtomUid2();
> int order = bondIterator.getOrder();
> // now, look up the uids in our atom map.
> Atom atom1 = (Atom)htMapUidsToAtoms.get(uid1);
> Atom atom2 = (Atom)htMapUidsToAtoms.get(uid2);
> // now, you have atom1 and atom2
> // do whatever you need to do to bond them together
>
> // delete all of this
>
> >             if (atom1 instanceof org.jmol.adapter.smarter.Atom) {
> >                 org.jmol.adapter.smarter.Atom atomOne =
> >                     (org.jmol.adapter.smarter.Atom)atom1;
> >                 org.jmol.adapter.smarter.Atom atomTwo =
> >                     (org.jmol.adapter.smarter.Atom)atom2;
> >                 // now I'm stuck... no idea which atoms this bond
> >                 // connects... consulting Miguel
> >             }
> >         }
>
> // down to here

That was very helpfull... now that I look through it, I vagelue remember that 
you explained this to me before... apologies for that...

Anyway, I've adapted the code, and the JME reader should be working... I'll 
ask around for an example file... I have the applet at home, but not in a 
webpage, and in the JME instances that I found on the web, I could not find a 
way to save a file locally... (which makes sense because of security 
reasons...)

> >             return molecule;
> >     }
> >
> > You'll see the "now I'm stuck" message...
> >
> > The problem here is the the getAtomUidX() methods returns a object...
> > matching this object against one of the CDK Atom's created in the while()
> > loop a bit earlier is difficult
>
> A hash table is perfect for this type of mapping. Store the atoms along
> with their UniqueID objects as the keys.
>
> Later, in the bond iterator, you will get back the same UniqueID objects.
> Look them up in your hash table.
>
> > and likely to be impossible when incomplete info
> > is read from the file...
>
> The model adapter should never do this. If so, then it is a bug in the
> model adapter implementation.
>
> > So, I rather have a method like: getAtomIndex1() and getAtomIndex2()
> > which would be implemented like:
> >
> > SmarterModelAdapter.BondIterator.getAtomIndex1() {
> >   return bond.atomIndex1;
> > }
>
> I felt it was better to use 'unique IDs' rather than integer numbers.

I understand.

> For example, if the API had specified integer numbers then it would have
> been very difficult to make the CDKModelAdapter. Because CDK does not use
> integers to identify the atoms.
>
> As it was, I just returned the CDK.Atom objects as the unique IDs. Then
> the hash table associates the unique IDs with the data structures that I
> am using on the other side.

Ok, this excersise was insightfull... (is that a word?)

Thanx,

Egon


-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
Jmol-developers mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jmol-developers

Reply via email to