From: DeLano, W. <wa...@su...> - 2002-10-15 23:48:06
|
> From: Kristian Rother=20 > In this and other recent questions inside and outside this=20 > forum i have=20 > discovered that many of them could be solved quite easy if=20 > there was an=20 > easy way to access the atomic coordinates directly from the PyMOL API. >=20 > Is this achievable somehow? The actual C-langauge arrays aren't exposed, but there are at least = three different ways you can modify coordinates from within Python: #####=20 (1) You can get a python object which contains the molecular = information, modify the coordinates in that object, load the modified = molecule into PyMOL, update the modified coordinates to the original = model, and then delete the modified object. (in a python script) from pymol import cmd model =3D cmd.get_model("pept") for a in model.atom: a.coord=3D[ -a.coord[1], a.coord[0], a.coord[2]] cmd.load_model(model,"tmp") cmd.update("pept","tmp") cmd.delete("tmp") ###### (2) Another approach is the "alter_state" function, which can perform = the same transformation in a single PyMOL command statement: alter_state 1,pept,(x,y)=3D(-y,x) Likewise sub-selections can be transformed as well: alter_state 1,(pept and name ca),(x,y,z)=3D(x+5,y,z) ####### (3) A third approach is to use alter_state with the global "stored" = object: (in Python script) from pymol import cmd from pymol import stored stored.xyz =3D [] cmd.iterate_state(1,"pept","stored.xyz.append([x,y,z])") # at this point, stored.xyz is a native Python array holding # the coordinates, which you can modify as required stored.xyz =3D map(lambda v:[-v[1],v[0],v[2]],stored.xyz) # and now you can update the internal coordinate sets cmd.alter_state(1,"pept","(x,y,z)=3Dstored.xyz.pop(0)") ##### Approaches 2 gives the best performance, approach 3 gives more = flexibility, and approach 1 gives you a reusable and fully modifiable = Python object. Cheers, Warren |