Hi Robert,
Thanks for the reply, but unfortunately it introduces another problem.
My application offers several views of PDB files, one of which is Jmol
(others include graphs and tables). Moving the mouse over any of the
views highlights all the appropriate atoms in the other views (e.g. all
the atoms in an amino acid residue or just a single single atom on a
small molecule). Up until now I have done this by maintaining a list of
all the PDB atom serial numbers for each residue in memory.
When I move the mouse over Jmol it currently uses
findNearestAtomIndex() and looks up the corresponding residue (if any).
When I move the mouse over one of my other views, it correctly pulls
out the residue and I "select atomno=" for all the associated PDB atom
serials.
In light of your last email, this is obviously flawed. Does Jmol
provide a mechanism for converting between the serial numbers in the
PDB file and its own atom indexes? Thanks again for the help.
Chris.
Robert Hanson wrote:
Chris, we can't use the atomno property to uniquely
identify an atom, because there may be multiple models loaded, and
more than one may have, say, atomno=1. So instead we indicate an "atom
index" which is a unique number relating to the entire set of models.
These numbers start with 0. So all you need to do is
select atomindex=
instead of
select atomno=
On Thu, Feb 26, 2009 at 9:44 AM, Chris Foley
<[email protected]>
wrote:
Hi
all,
I'm having a bit of trouble with atom indexes. I'm using mouse over
events to get the atom under the mouse cursor and then trying to select
the same atom in Jmol. In essence it's this:
int atom = findNearestAtomIndex(e.getPoint()); // e is of type
MouseEvent
evalString("select atomno=" + atom + ";");
However, the selected atom is not the same as under the mouse. Here's a
demo app so you can see what I mean (please excuse the messy use of
reflection). You will need Jmol and the 2 PDB files in the same
directory as the compiled class file to run it.
Thanks in advance for any help.
Cheers,
Chris Foley.
package JmolAtomDemo;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.lang.reflect.Method;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jmol.adapter.smarter.SmarterJmolAdapter;
import org.jmol.viewer.Viewer;
public class JmolAtomDemo extends JPanel {
private static final long serialVersionUID = 1L;
// Oh so messy!
private static Method findNearestAtomIndex;
static {
Class<?> c = Viewer.class;
Class<?>[] findNearestAtomIndexParams = {int.class,
int.class};
try {findNearestAtomIndex =
c.getDeclaredMethod("findNearestAtomIndex", findNearestAtomIndexParams);
} catch (Exception e) {e.printStackTrace();}
findNearestAtomIndex.setAccessible(true);
}
private Viewer viewer;
public JmolAtomDemo(String pdb) {
viewer = new Viewer(this, new SmarterJmolAdapter() );
viewer.setAppletContext("",null,null,"");
viewer.openFile(pdb);
viewer.evalString("selectionHalos ON;");
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
int atomIndex = findNearestAtomIndex(e.getPoint());
String script = "select atomno=" + atomIndex + ";";
System.out.println(script);
viewer.evalString(script);
}
});
} // constructor
private final Dimension currentSize = new Dimension();
private final Rectangle rectClip = new Rectangle();
@Override
public void paint(Graphics g) {
getSize(currentSize);
g.getClipBounds(rectClip);
viewer.renderScreenImage(g, currentSize, rectClip);
} // paint
public int findNearestAtomIndex(Point mousePosition) {
Integer rv = -1;
try {
rv = (Integer)findNearestAtomIndex.invoke(
viewer, mousePosition.x, mousePosition.y);
} catch (Exception e) {
e.printStackTrace();
} // try
return rv;
} // findNearestAtomIndex
public static void main(String[] args) {
JFrame frame1 = new JFrame("1NCP");
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.getContentPane().add(new JmolAtomDemo("1NCP.pdb"));
frame1.setSize(300, 300);
frame1.setVisible(true);
JFrame frame2 = new JFrame("1CDH");
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.getContentPane().add(new JmolAtomDemo("1cdh.pdb"));
frame2.setLocation(300, 0);
frame2.setSize(300, 300);
frame2.setVisible(true);
} // main
}
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San
Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the
Enterprise
-Strategies to boost innovation and cut costs with open source
participation
-Receive a $600 discount off the registration fee with the source code:
SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Jmol-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-users
--
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
|