Tina,
I wrote a CdkConvertor class which does similar things
to what I think you need, but deals only
with whole molecules.
It is attached.
It wasn't really designed for general use, but
do let me know if it is or isn't helpful.
Dave
On Fri, 27 Oct 2006 07:02:53 -0500 (CDT), [EMAIL PROTECTED] said:
> [switching to jmol-developers]
>
> Tina, I think what you are looking for is simply:
>
> Vector bonds =
> (Vector)viewer.getProperty("object","bondInfo","selected");
>
> for (int i = 0; i < bonds.size(); i++) {
> Hashtable bond = (Hashtable) bonds.get(i);
> Hashtable atom1 = (Hashtable) bond.get("atom1");
> Hashtable atom2 = (Hashtable) bond.get("atom2");
> int atomIndex1 = ((Integer) atom1.get("_pt")).intValue();
> int atomIndex1 = ((Integer) atom2.get("_pt")).intValue();
> String atomSymbol1 = (String) atom1.get("sym");
> String atomSymbol2 = (String) atom2.get("sym");
> int order = ((Integer) bond.get("order")).intValue();
>
> ...
> }
>
> Take a look for getBondInfo in ModelManager.java to see all that is in
> there.
>
> The only caveate there is that you will have to check with your atomList
> to remove bonds that are connections OUTSIDE the selected atom set. So
> you
> might use something like:
>
> Vector atomSet =
> (Vector)viewer.getProperty("object","atomList","selected");
> BitSet atoms = new BitSet();
> for (int i = 0; i < atomSet.size(); i++)
> atoms.set(((Integer) atomSet.get(i)).intValue());
>
> and then check for
>
> if(atoms.get(atomIndex1) && atoms.get(atomIndex2))....
>
>
> Bob Hanson
>
>
> > Hi everybody,
> > I want to select atoms graphically, save these atoms(something like
> > atom[i].isSelected ? selected[j] = atom[i]) and use themfor further
> > calculations within my code. Primarily I need to know whichof the selected
> > atoms are bonded together (something likeisBonded(atom1, atom2)), the
> > coordinates of the atoms (I know how to doTHIS) and other atoms which are
> > bonded to this selected atoms. I have noidea how to do this...I´m using
> > Jmol jmol-10.9.76 and the CdkJmolAdapter. What I did so far is:
> > I read in a SDF File ,eval the String "select none;set picking atom;set
> > display selected;";select some atoms by clicking.I know I can get the
> > coordinates of the SELECTED atoms like this:Vector atomInfo =
> > (Vector)viewer.getProperty("object", "atomList","selected");
> > for(int i = 0; i< atomInfo.size(); i++){ int x = (Integer)
> > atomInfo.elementAt(i); coord = viewer.getAtomPoint3f(x);
> > }I also understood I can get the mol file like
> > this:viewer.getProperty("string","extractModel","selected");
> > But how can I get the atoms or ask something like
> > "aBond(atomList[1],atomList[2])?". And can I save these selected atoms in
> > a "model" so thatI can convert them into a CDK AtomContainer (with atoms
> > and bonds)?
> > I tried to get the selected BitSet, but getSelectedSet is a privatemethod,
> > SelectionManager (and getAtomBitSet("selected")) or ModelManagercannot be
> > accesed outside the package (I had a look how the bonds andatoms are
> > extracted for "modelExtract"). Is there any other way? Can Iiterate over
> > atoms and bonds of the molecule in the viewer?
> > Maybe it´s totally easy, but I don´t have any idea how to do this.
> > Thankyou!
> > Kind regards,Tina
> >
> >
> > -------------------------------------------------------------------------Using
> > Tomcat but need to do more? Need to support web services, security?Get
> > stuff done quickly with pre-integrated technology to make your job
> > easierDownload IBM WebSphere Application Server v.1.0.1 based on Apache
> > Geronimohttp://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642_______________________________________________Jmol-users
> > mailing
> > [EMAIL PROTECTED]://lists.sourceforge.net/lists/listinfo/jmol-users
> >
>
>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job
> easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache
> Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Jmol-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jmol-developers
--
Dave Evans
[EMAIL PROTECTED]
http://www.davidaevans.org
/* $RCSfile: CdkConvertor.java,v $
* $Author: u6x8497 $
* $Date: 2005/08/04 14:36:30 $
* $Revision: 1.13 $
*
* Copyright (C) 2004-2005 The Chemistry Development Kit (CDK) project
*
* Contact: [EMAIL PROTECTED]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* All we ask is that proper credit is given for our work, which includes
* - but is not limited to - adding the above copyright notice to the beginning
* of your source code files, and to any copyright notice that you may
distribute
* with programs based on this work.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
package org.openscience.jmol.app;
import org.jmol.api.*;
import java.util.Hashtable;
import java.util.Vector;
import org.openscience.cdk.Atom;
import org.openscience.cdk.AtomContainer;
import org.openscience.cdk.Bond;
import org.openscience.cdk.exception.CDKException;
public class CdkConvertor {
Vector va;
Vector vb;
JmolViewer viewer;
public CdkConvertor() {
}
/**
* Converts the currently visible atoms to a CDK AtomContainer.
*
* @param viewer the JmolViewer object
* Relies on getProperty for conversion, uses hard-coded 'visible' flag
* Therefore there will be problems if you start hiding atoms
*/
public AtomContainer convert(JmolViewer viewer) throws CDKException {
this.viewer = viewer;
va = (Vector)viewer.getProperty("Object","atomInfo","all");
vb = (Vector)viewer.getProperty("Object","bondInfo","all");
int mn = viewer.getDisplayModelIndex();
// If all frames are displayed mn is set to -1
// For now, let the first frame be converted and used for calculations
if (mn < 0) {
mn = 0;
}
AtomContainer atomContainer = getAtomContainer(mn);
return atomContainer;
};
/**
* Converts the atoms in all models to an array of CDK AtomContainer.
*
*/
public AtomContainer[] convertAll(JmolViewer viewer) throws CDKException {
this.viewer = viewer;
AtomContainer[] atomContainers;
va = (Vector)viewer.getProperty("Object","atomInfo","all");
vb = (Vector)viewer.getProperty("Object","bondInfo","all");
int nmodel = viewer.getModelCount();
atomContainers = new AtomContainer[nmodel];
for (int j=0; j < nmodel; j++) {
AtomContainer ac = getAtomContainer(j);
atomContainers[j] = ac;
}
return atomContainers;
};
private AtomContainer getAtomContainer(int mn) {
Hashtable htMapIndexToAtoms = new Hashtable();
int nmodel = viewer.getModelCount();
int natot = viewer.getAtomCount();
int na;
if (nmodel > 0) {
na = natot/nmodel;
}
else {
na = 0;
}
int nbtot = viewer.getBondCount();
int nb;
if (nmodel > 0) {
nb = nbtot/nmodel;
}
else {
nb = 0;
}
AtomContainer atomContainer = new AtomContainer();
int minindex = 1;
for (int i=0; i < na; i++) {
int index = mn*na + i;
Hashtable atomi = (Hashtable)va.get(index);
int k = ((Integer)atomi.get("atomno")).intValue();
if (k < minindex) {
minindex = k;
}
Atom atom = new Atom((String)atomi.get("sym"));
atom.setX3d(((Float)atomi.get("x")).doubleValue());
atom.setY3d(((Float)atomi.get("y")).doubleValue());
atom.setZ3d(((Float)atomi.get("z")).doubleValue());
htMapIndexToAtoms.put(new Integer(i), atom);
atomContainer.addAtom(atom);
}
System.out.println("hello " + minindex);
for (int i=0; i < nb; i++) {
int index = mn*nb + i;
Hashtable b = (Hashtable)vb.get(index);
Hashtable a1 = (Hashtable)b.get("atom1");
Hashtable a2 = (Hashtable)b.get("atom2");
int numa1 = ((Integer)a1.get("atomno")).intValue() - minindex;
int numa2 = ((Integer)a2.get("atomno")).intValue() - minindex;
int order = ((Integer)b.get("order")).intValue();
// now, look up the uids in our atom map.
Atom atom1 = (Atom)htMapIndexToAtoms.get(new Integer(numa1));
Atom atom2 = (Atom)htMapIndexToAtoms.get(new Integer(numa2));
Bond bond = new Bond(atom1, atom2, (double)order);
atomContainer.addBond(bond);
}
return atomContainer;
}
}
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jmol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-developers