Difference between revisions of "Editing atoms"

From PyMOLWiki
Jump to navigation Jump to search
m (→‎Get coordinates from Python: Fixed list numbering)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
==Altering atom types/elements==
 +
Example:
 +
 +
To transform a carbon into an oxygen,
 +
pick an atom by a ''select'' command or CTRL+middle.
 +
<source lang="python">
 +
alter pk1,elem='O'
 +
alter pk1,name='O2'
 +
</source>
 +
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==
 
==Altering atom coordinates==
 
Example:
 
Example:
Line 27: Line 39:
  
 
# 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)
 
# 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)
 
+
# Another approach is the "alter_state" function, which can perform the same transformation in a single PyMOL command statement:<source lang="python">
# Another approach is the "alter_state" function, which can perform the same transformation in a single PyMOL command statement:
 
<source lang="python">
 
 
alter_state 1,pept,(x,y)=(-y,x)
 
alter_state 1,pept,(x,y)=(-y,x)
</source>
+
</source>Likewise sub-selections can be transformed as well:<source lang="python">
Likewise sub-selections can be transformed as well:
 
<source lang="python">
 
 
alter_state 1,(pept and name ca),(x,y,z)=(x+5,y,z)
 
alter_state 1,(pept and name ca),(x,y,z)=(x+5,y,z)
 
</source>
 
</source>
 
# A third approach is to use alter_state with the global "stored" object: Example in a Python script)
 
# 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.
+
Approaches 2 gives the best [[:Category:Performance|performance]], approach 3 gives more flexibility, and approach 1 gives you a reusable and fully modifiable Python object.
  
 
[[Category:Modeling_and_Editing_Structures|Editing Atoms]]
 
[[Category:Modeling_and_Editing_Structures|Editing Atoms]]
 +
[[Category:Performance]]
 +
[[Category:States]]

Latest revision as of 16:49, 23 July 2012

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.