This is a read-only mirror of pymolwiki.org

Editing atoms

From PyMOL Wiki
Revision as of 20:49, 23 July 2012 by Sbliven (talk | contribs) (→‎Get coordinates from Python: Fixed list numbering)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Altering atom types/elements

Example:

To transform a carbon into an oxygen, pick an atom by a select command or CTRL+middle.

alter pk1,elem='O'
alter pk1,name='O2'

Note that the name field should contain something more descriptive than just the element symbol. For reasons unknown (?), util.cbag() and similar methods will not recognize the new element.

Altering atom coordinates

Example:

alter_state 1,(pdb1cse),x=x-10.0

The latter section can contain formulae involving at least the xyz coordinates, lots of constants and the (+-*/) operators.


Translate or rotate individual objects

There is a "translate" function similar to "rotate", the docs for these don't exist yet, because the implementation isn't finished. However, feel free to use them in the following forms:

translate vector,object-name,state
   vector needs to be something like [x,y,z]

   translate [1,0,0],pept
rotate axis,angle,object-name,state
   axis can be either the letter x,y,z or a 3D vector [x,y,z]

   rotate x,90,pept
   rotate [1,1,1],10,pept

Get coordinates from Python

  1. The actual C-langauge arrays aren't exposed, but there are at least three different ways you can modify coordinates from within Python: 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. (link to example)
  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)=(-y,x)
    
    Likewise sub-selections can be transformed as well:
    alter_state 1,(pept and name ca),(x,y,z)=(x+5,y,z)
    
  3. A third approach is to use alter_state with the global "stored" object: Example in a Python script)

Approaches 2 gives the best performance, approach 3 gives more flexibility, and approach 1 gives you a reusable and fully modifiable Python object.