[Chimera-users] Automatic Bond Rotating Script
pett at cgl.ucsf.edu
Tue Mar 29 14:04:45 PDT 2016
> On Mar 29, 2016, at 8:27 AM, Lisa Rohrwasser <rohrwasser at thphys.uni-heidelberg.de> wrote:
> I am currently trying to write a python script to rotate different bonds automatically many many times. The idea is to randomly chose a bond of a .pdb-File and rotate it by a certain angle.
> In principle the command line tool "rotation" is exactly what I would like to use, but i have difficulties implementing it.
> To start with rotating only one bond I already got:
> import chimera
> from chimera import runCommand as rc
> opened = chimera.openModels.open('~/Documents/rho.pdb')
> #open protein
> rho = opened
> #get random bond (it is set to bond 10 for now)
> b = rho.bonds
> #gives back both atoms corresponding to the bond (atom IDs are needed for command line tool "rotation")
> #select bond-atoms
> a1 = b.atoms
> a2 = b.atoms
> #now i would like to use command line tool "rotation", which gives many errors
> rc("rotation a1 a2 <angle>")
> So i think the problems are
> 1) objects a1, a2 have the wrong datatype
> 2) rc does not have access to a1, a2]
> Now i wonder if there is a solution at all to these problems or if i have to think of a completely different way?
I’ll offer two options: 1) fix up the “rc” approach, and 2) an all-Python approach.
1) The first thing is that you need to get the atom-spec equivalent of a1 and a2 into the command. The second thing is that for what you’re doing using the “turn” command is one less step that using a “rotation” command to specify the rotating bond and then a second “rotation” command to actually rotate it.
Internally Chimera refers to the #/:/@ style of atom specifier (rather than, say, “sel”) as the Object Selection Language. Therefore, the atom spec for a1 is returned by a1.oslIdent(). So the “turn” command you would want is:
rc(“turn %s%s %d” % (a1.oslIdent(), a2.oslIdent(), angle))
Note no space between the two “%s” format options so that the two atom specs will have no internal space and will therefore be treated as one big atom spec.
2) In Python, ongoing bond rotations (as opposed to “one shot” rotations like the “turn” command) are managed by the BondRotMgr module. So pure Python code to accomplish what you want would be:
from BondRotMgr import bondRotMgr as mgr
rot = mgr.rotationForBond(b)
(and when done with that rotation…)
UCSF Computer Graphics Lab
More information about the Chimera-users