This is a read-only mirror of pymolwiki.org

Difference between revisions of "Iterate State"

From PyMOL Wiki
Jump to navigation Jump to search
 
(Made this useful)
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
===DESCRIPTION===
 
===DESCRIPTION===
   
+
Iterate state can be used to extract position data from an object or selection.  The expression can use the variables x, y, and z which are the position of the current atom. One common usage is to extract the positions as a python list to alter then write back to the molecule using alter_state.
  "iterate_state" is to "alter_state" as "iterate" is to "alter"
+
 
 
 
===USAGE===
 
===USAGE===
+
iterate_state state,(selection),expression
  iterate_state state,(selection),expression
+
 
 
 
===EXAMPLES===
 
===EXAMPLES===
+
==From PyMOL command line==
  stored.sum_x = 0.0
+
To get the sum of x coordinates:
  iterate 1,(all),stored.sum_x = stored.sum_x + x
+
<source lang="python">
+
stored.sum_x = 0.0
 +
iterate_state 1,(all),stored.sum_x = stored.sum_x + x
 +
</source>
 +
To get a list of the positions in a selection
 +
<source lang="python">
 +
stored.pos = []
 +
iterate_state 1, (all), stored.pos.append((x,y,z))
 +
</source>
 +
==From Python==
 +
To get a list of positions
 +
<source lang="python">
 +
stored.pos = []
 +
cmd.iterate_state(1, 'all', 'stored.pos.append((x,y,z))')
 +
</source>
 +
 
 
===SEE ALSO===
 
===SEE ALSO===
+
[[Cmd iterate]], [[Cmd alter]], [[Cmd alter_state]]
  [[Cmd iterate]], [[Cmd alter]], [[Cmd alter_state]]
 
  
 
[[Category:Commands|iterate_state]]
 
[[Category:Commands|iterate_state]]

Revision as of 12:39, 6 July 2006

DESCRIPTION

Iterate state can be used to extract position data from an object or selection. The expression can use the variables x, y, and z which are the position of the current atom. One common usage is to extract the positions as a python list to alter then write back to the molecule using alter_state.

USAGE

iterate_state state,(selection),expression

EXAMPLES

From PyMOL command line

To get the sum of x coordinates:

stored.sum_x = 0.0
iterate_state 1,(all),stored.sum_x = stored.sum_x + x

To get a list of the positions in a selection

stored.pos = []
iterate_state 1, (all), stored.pos.append((x,y,z))

From Python

To get a list of positions

stored.pos = []
cmd.iterate_state(1, 'all', 'stored.pos.append((x,y,z))')

SEE ALSO

Cmd iterate, Cmd alter, Cmd alter_state