Iterate State: Difference between revisions

From PyMOLWiki
Jump to navigation Jump to search
No edit summary
(redirect iterate)
 
(11 intermediate revisions by 5 users not shown)
Line 1: Line 1:
===DESCRIPTION===
#REDIRECT [[iterate]]
'''iterate_state''' is to "alter_state" as "iterate" is to "alter".
 
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===
===USAGE===
iterate_state state,(selection),expression
iterate_state state, (selection), expression
 
=== ARGUMENTS ===
 
* state = integer: state-index if positive number or any of these:
** state = 0: all states
** state = -1: current state
* selection = string: atom selection
* expression = string: expression in valid [http://en.wikipedia.org/wiki/Python_syntax_and_semantics python syntax]
* space = dict: namespace dictionary (API only) {default: pymol namespace}
* atomic = 0/1: provide atomic properties as variables if 1, or only x/y/z if 0 (atomic=0 gives some speed improvement) {default: 1}


===EXAMPLES===
===EXAMPLES===
==From PyMOL command line==
To get the sum of x coordinates:
<source lang="python">
<source lang="python">
stored.sum_x = 0.0
stored.sum_x = 0.0
iterate 1,(all),stored.sum_x = stored.sum_x + x
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">
# either with global stored object
from pymol import stored
stored.pos = []
cmd.iterate_state(1, 'all', 'stored.pos.append((x,y,z))')
 
# or with local object, passed with space argument
pos = []
cmd.iterate_state(1, 'all', 'pos.append((x,y,z))', space={'pos': pos})
</source>
</source>


===SEE ALSO===
===SEE ALSO===
[[Cmd iterate]], [[Cmd alter]], [[Cmd alter_state]]
[[iterate]], [[alter]], [[Alter_State]]


[[Category:Commands|iterate_state]]
[[Category:Commands|Iterate State]]
[[Category:States|Iterate State]]

Latest revision as of 16:02, 23 December 2015

Redirect to:

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

ARGUMENTS

  • state = integer: state-index if positive number or any of these:
    • state = 0: all states
    • state = -1: current state
  • selection = string: atom selection
  • expression = string: expression in valid python syntax
  • space = dict: namespace dictionary (API only) {default: pymol namespace}
  • atomic = 0/1: provide atomic properties as variables if 1, or only x/y/z if 0 (atomic=0 gives some speed improvement) {default: 1}

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

# either with global stored object
from pymol import stored
stored.pos = []
cmd.iterate_state(1, 'all', 'stored.pos.append((x,y,z))')

# or with local object, passed with space argument
pos = []
cmd.iterate_state(1, 'all', 'pos.append((x,y,z))', space={'pos': pos})

SEE ALSO

iterate, alter, Alter_State