Re: [Jmol-users] SelectionListener

2009-02-26 Thread Robert Hanson
That should read:

On Thu, Feb 26, 2009 at 10:59 AM, Robert Hanson  wrote:

> Alex, Jmol 11.7 SVN now includes a simpler jmolCallbackListener method that
> can be used instead of jmolStatusListener().


It consists of just these methods:

  public void setCallbackFunction(String callbackType, String
callbackFunction);
  public void notifyCallback(int type, Object[] data);
  public boolean notifyEnabled(int callback_pick);

If that is all you want to do, then you can just use the simpler
allocateViewer method followed by a call to setJmolCallbackListener()

viewer = JmolViewer.allocateViewer(display, modelAdapter);
viewer.setJmolCallbackListener(myCallbackListener);

Bob

-- 
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
--
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
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users


Re: [Jmol-users] SelectionListener

2009-02-26 Thread Robert Hanson
Alex, Jmol 11.7 SVN now includes a simpler jmolSetCallbackListener method
that can be used instead of jmolStatusListener().

On Thu, Feb 26, 2009 at 10:06 AM, Robert Hanson  wrote:

> Alex, the distinction you need to make is between a Jmol atom "selection"
> using the SELECT command and a mouse action to pick an atom, which is a
> callback. You are watching for the select command. What you want to do is
> implement org.jmol.api.JmolStatusListener. Check out how this is done in
> Jmol.java. The two specific methods you will want to implement are:
>
> public boolean notifyEnabled(int type)
> public void notifyCallback(int type, Object[] data)
>
>
> You register your status listener at Jmol viewer allocation time:
>
> viewer = JmolViewer.allocateViewer(display, modelAdapter,
> null, null, null, appletContext = commandOptions,
> new MyStatusListener());
>
> Where MyStatusListener() implements JmolStatusListener.
>
> Referring to Jmol 11.7 here.
>
>
> Bob
>
>
>
> On Thu, Feb 26, 2009 at 7:23 AM, Alexander Klenner <
> klen...@bioinformatik.uni-frankfurt.de> wrote:
>
>> Hi all,
>>
>> is there a way to add something like the 'SelectionListener' to my
>> instance of the viewer ( I am using the viewer to visualize some
>> molecules that are in CDK Molecule representation)
>> that actually will react if I mouse-klick an atom in the viewer?
>>
>> I tried the following but that won't do anything so far...
>>
>>  MyViewer.addSelectionListener(new JmolSelectionListener() {
>> public void selectionChanged(BitSet selection) {
>>   //do some nice stuff whenever atom is
>> klicked
>>   }
>>
>>});
>>
>> I do see the system outs from the StatusManager class that confirms,
>> that I did pick an atom.
>>
>> Is there a way to do this or do I have to implement something by myself?
>>
>> Thanks for any help or suggestions,
>>
>> Alex
>>
>>
>>
>> --
>> Alexander Klenner, Dipl.-Bioinf.
>> Johann Wolfgang Goethe-University Frankfurt
>> Department of Biosciences
>> Siesmayerstrasse 70
>> D-60323 Frankfurt
>> Tel: +49 (0) 69 798 24879
>> Fax: +49 (0) 69 798 24880
>> klen...@bioinformatik.uni-frankfurt.de
>>
>>
>>
>> --
>> 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
>> Jmol-users@lists.sourceforge.net
>> 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
>



-- 
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
--
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
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users


Re: [Jmol-users] findNearestAtomIndex() and select atomno=

2009-02-26 Thread Robert Hanson
On Thu, Feb 26, 2009 at 10:09 AM, Chris Foley <
christopher.fo...@strath.ac.uk> wrote:

>  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.
>

very nice. Could be a problem with multi-model PDB files, but


>
>
> When I move the mouse over Jmol it currently uses findNearestAtomIndex()
> and looks up the corresponding residue (if any).
>

good.


>
> 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.
>

ok.


>
>
> 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.
>

Once you have the atom Object, you can do anything with it. Most of the
methods there are public. To get a pointer to the atom set -- KEEP THIS
LOCAL!! --

 Atom[] atoms = viewer.getModelSet().atoms

And once you have that, you can, for instance, just check:

int atomNo = atoms[atomIndex].getAtomNumber();





>
>
> 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 <
> christopher.fo...@strath.ac.uk> 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.printS

Re: [Jmol-users] findNearestAtomIndex() and select atomno=

2009-02-26 Thread Chris Foley




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
  
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



   

Re: [Jmol-users] SelectionListener

2009-02-26 Thread Robert Hanson
Alex, the distinction you need to make is between a Jmol atom "selection"
using the SELECT command and a mouse action to pick an atom, which is a
callback. You are watching for the select command. What you want to do is
implement org.jmol.api.JmolStatusListener. Check out how this is done in
Jmol.java. The two specific methods you will want to implement are:

public boolean notifyEnabled(int type)
public void notifyCallback(int type, Object[] data)


You register your status listener at Jmol viewer allocation time:

viewer = JmolViewer.allocateViewer(display, modelAdapter,
null, null, null, appletContext = commandOptions,
new MyStatusListener());

Where MyStatusListener() implements JmolStatusListener.

Referring to Jmol 11.7 here.


Bob


On Thu, Feb 26, 2009 at 7:23 AM, Alexander Klenner <
klen...@bioinformatik.uni-frankfurt.de> wrote:

> Hi all,
>
> is there a way to add something like the 'SelectionListener' to my
> instance of the viewer ( I am using the viewer to visualize some
> molecules that are in CDK Molecule representation)
> that actually will react if I mouse-klick an atom in the viewer?
>
> I tried the following but that won't do anything so far...
>
>  MyViewer.addSelectionListener(new JmolSelectionListener() {
> public void selectionChanged(BitSet selection) {
>   //do some nice stuff whenever atom is
> klicked
>   }
>
>});
>
> I do see the system outs from the StatusManager class that confirms,
> that I did pick an atom.
>
> Is there a way to do this or do I have to implement something by myself?
>
> Thanks for any help or suggestions,
>
> Alex
>
>
>
> --
> Alexander Klenner, Dipl.-Bioinf.
> Johann Wolfgang Goethe-University Frankfurt
> Department of Biosciences
> Siesmayerstrasse 70
> D-60323 Frankfurt
> Tel: +49 (0) 69 798 24879
> Fax: +49 (0) 69 798 24880
> klen...@bioinformatik.uni-frankfurt.de
>
>
>
> --
> 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
> Jmol-users@lists.sourceforge.net
> 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
--
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
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users


Re: [Jmol-users] SelectionListener

2009-02-26 Thread Angel Herraez
Alex,

it is possible to do that from the javascript side with the applet, 
using pickCallback, as well as from the JmolScript language:
http://jmol.sourceforge.net/jslibrary/#jmolSetCallback
http://chemapps.stolaf.edu/jmol/docs/#setcallback

so I bet that there is a way inside the code to have it done at an 
inner level (but cannot help you out there)



--
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
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users


Re: [Jmol-users] findNearestAtomIndex() and select atomno=

2009-02-26 Thread Robert Hanson
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  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
> Jmol-users@lists.sourceforge.net
> 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
--
Open 

[Jmol-users] findNearestAtomIndex() and select atomno=

2009-02-26 Thread Chris Foley
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
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users


[Jmol-users] SelectionListener

2009-02-26 Thread Alexander Klenner
Hi all,

is there a way to add something like the 'SelectionListener' to my 
instance of the viewer ( I am using the viewer to visualize some 
molecules that are in CDK Molecule representation)
that actually will react if I mouse-klick an atom in the viewer?

I tried the following but that won't do anything so far...

 MyViewer.addSelectionListener(new JmolSelectionListener() {
 public void selectionChanged(BitSet selection) {
   //do some nice stuff whenever atom is 
klicked
   }
   
});

I do see the system outs from the StatusManager class that confirms, 
that I did pick an atom.

Is there a way to do this or do I have to implement something by myself?

Thanks for any help or suggestions,

Alex
 
  

-- 
Alexander Klenner, Dipl.-Bioinf.
Johann Wolfgang Goethe-University Frankfurt
Department of Biosciences
Siesmayerstrasse 70
D-60323 Frankfurt
Tel: +49 (0) 69 798 24879
Fax: +49 (0) 69 798 24880
klen...@bioinformatik.uni-frankfurt.de


--
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
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users


Re: [Jmol-users] Jmol-users Digest, Vol 33, Issue 27

2009-02-26 Thread Dan Damelin
Thanks. This was helpful. I'm working with all mol2 files.

-Dan

On Feb 26, 2009, at - February 26 - 4:56 AM, 
jmol-users-requ...@lists.sourceforge.net 
  wrote:

> 2. if the file is MOL format (not sure about others like XYZ,
> certainly not in PDB), you can use a combination of element symbol +
> atom number, like
> select C3,O5,C18,C26


--
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
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users


Re: [Jmol-users] selecting list of atoms

2009-02-26 Thread Robert Hanson
Dan, presuming you are working with a relatively simple system (you aren't
doing a lot of atom deletion, for example), you can use the atom "bitset"
notation:

select ({0,3:6,9})

This selects atoms 0, 3, 4, 5, 6, and 9.

Note that the numbers here are one less than the numbers used in atomno, and
the numbers span all models -- no restarting when multiple models are
loaded. "0" is the first atom of the first model, and it just goes up from
there. Also, if atoms are deleted, these numbers will change.

This syntax can be used anywhere atomno can be used. For example:

select ({1:3}) and hydrogen

Bob



-- 
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
--
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
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users


Re: [Jmol-users] selecting list of atoms

2009-02-26 Thread Chris Foley
Hi Dan

I'm not sure how much use this will be to you but for contiguous atoms 
you can use this syntax:
select atomno>0 and atomno<8;

Sometimes it can cut things down a bit.

Cheers,
Chris.



Dan Damelin wrote:
> Hi folks,
>
> Is there a shorter way to select a set of atoms other than saying
> "select atomno=3 or atomno=5 or atomno=18 or atomno=26". Assume there
> is no other group name like residue or molecule, etc. that I can use
> to select the group all at once.
>
> Thanks,
> -Dan
>
> --
> 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
> Jmol-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jmol-users
>   

--
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
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users


Re: [Jmol-users] selecting list of atoms

2009-02-26 Thread Angel Herraez
Hi Dan

I'm afraid there is not much that can be done:

1. you can put commas instead of "or"
select atomno=3,atomno=5,atomno=18,atomno=26

2. if the file is MOL format (not sure about others like XYZ, 
certainly not in PDB), you can use a combination of element symbol + 
atom number, like
select C3,O5,C18,C26

3. there is a chance that there is a Jmol math syntax to do that in 
some way like {3,5,18,26} but I cannot help with that, if even 
possible. Bob can tell you.


--
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
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users