[Chimera-users] Making chimera selections on the fly

Eric Pettersen pett at cgl.ucsf.edu
Thu Apr 19 12:51:38 PDT 2018

Hi Bala!

> On Apr 19, 2018, at 6:09 AM, Bala subramanian <bala.biophysics at gmail.com> wrote:
> Dear chimera lovers,
> Good day. I wrote a small script (pasted below) to monitor the dipole vector of water molecules during MD. The script was adopted based available example.
> rc('close #1-500')
> m = chimera.openModels.list()[0]
> wat = m.residues[2449]
> com = Point([a.coord() for a in wat.atoms], [a.element.mass for a in wat.atoms])
> # dipl = Vector() No working, Use numpy instead
> dipl = np.array( [0.0,0.0,0.0] )
> for atm in wat.atoms: 
>      #dipl += atm.charge * atm.coord()
>      dipl += atm.charge * np.array( atm.coord().data() )
> vend = np.array(com) + 5 * dipl
> of = open('current.bild','w')
> of.write('.color green\n')
> of.write('.cone %f %f %f %f %f %f 0.5 \n' % (com.x,com.y,com.z,vend[0],vend[1],vend[2]))
> of.close()
> rc('open current.bild')
> Query 1)
> The following syntax given in a example doesnt work. What is the chimera point object indeed, an array or list ?. How to do math operations on point object.
> dipl += atm.charge * a.coord()
> Error:
> TypeError: unsupported operand type(s) for *: 'float' and '_chimera.Point'

Well, Chimera has Point and Vector classes and is kind of pedantic about the allowed operations on them.  So you can multiply a Vector but not a Point.  You can add a Point and a Vector, but not a Point and a Point.  Therefore, for the above to work you would need to convert the Point (what .coord() returns) to a Vector, e.g.:

dial += atm.charge * a.coord().toVector()

> Query 2) In my example, I choose a specific water molecule by residue index. I am looking for some way to select the water (or get list of water residues) that satisfy a selection on the fly, lets say that water within 3 A from a prot. residue.
> In short, how to handle selections inside python script in chimera framework. I tried to play with chimera.selections but I didnt succeed. Any example could be of help.

If you select the atoms (by whatever code/commands desired), then you can get a list of them from chimera.selection.currentAtoms()

> Query 3) Invoke data calculated out of chimera inside a perframe script.
> If I have say 100 frames. I can do the dipole vector calculation outside chimera and write separate “.bild” files, 1.bild, 2.bild, …..n.bild. Then inside the perframe script, I can invoke a particular .bild fine corresponding to the frame no. Please help me with an syntax example if this is possible.

We’re talking about MD Movie’s per-frame scripting dialog, right?  In that dialog, make sure “Interpret script as” is set to “Chimera commands”, then your script could be:

close #25
open 25 folder_your_bild_files_are_in/<FRAME>.bild

Literally the string “<FRAME>”.  Chimera will substitute in the actual frame number there.  If you don’t have the frame number to have leading zeroes (e.g. 001 vs. 1) then uncheck the “Use leading zeroes…” box near the top of the dialog.  The above first closes any model #25 that is open, then opens your BILD file as model #25.


	Eric Pettersen
	UCSF Computer Graphics Lab

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-users/attachments/20180419/4bfba471/attachment.html>

More information about the Chimera-users mailing list