This is a read-only mirror of pymolwiki.org

Difference between revisions of "Iterate"

From PyMOL Wiki
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
'''iterate''' iterates over an expression with a separate name space for each atom.  However, unlike the "alter" command, atomic properties can not be altered.  Thus, '''iterate''' is more efficient than '''alter'''.
 
'''iterate''' iterates over an expression with a separate name space for each atom.  However, unlike the "alter" command, atomic properties can not be altered.  Thus, '''iterate''' is more efficient than '''alter'''.
 
   
 
   
It can be used to perform operations and aggregations using atomic selections, and store the results in any global object, such as the predefined '''stored''' object.
+
Iterate is a powerful tool that can be used to perform operations and aggregations using atomic selections, and store the results in any global object, such as the predefined '''stored''' object.  For example, one could iterate over all of the alpha carbons and record their B Factors, or print out all of the secondary structure classifications of all the residues.
+
 
The local namespace for "iterate" contains the following names:
+
The '''iterate''' command only has access to certain properties.  Those properties are:
*name
+
*'''name''': the atom name
*resn
+
*'''resn''': the residue name
*resi
+
*'''resi''': the residue identifier (residue number)
*chain
+
*'''chain''': the chain name
*alt
+
*'''alt''':
*elem
+
*'''elem''': the chemical element
*q
+
*'''q'''
*b
+
*'''b''': the B Factor
*segi
+
*'''segi''':
*type (ATOM,HETATM)  
+
*'''type''' (ATOM,HETATM): the atom type
*formal_charge
+
*'''formal_charge''': the formal charge of the atom
*partial_charge
+
*'''partial_charge''': the partial charger of the ato
*numeric_type
+
*'''numeric_type'''
*text_type  
+
*'''text_type '''
*ID
+
*'''ID'''
*vdw
+
*'''vdw'''
  
 
All strings in the expression must be explicitly quoted.  This operation typically takes a second per thousand atoms.
 
All strings in the expression must be explicitly quoted.  This operation typically takes a second per thousand atoms.
 +
 +
'''Note''' that the coordinates of the atom are not accessible via '''iterate'''. To use the coordinates of the atoms, see iterate_state.
  
 
===USAGE===
 
===USAGE===
Line 28: Line 30:
  
 
===EXAMPLES===
 
===EXAMPLES===
 +
====Example====
 
*The following example calculates the net charge on an object.
 
*The following example calculates the net charge on an object.
 
<source lang="python">
 
<source lang="python">
 +
# create the global variable between Python and PyMOL
 
stored.net_charge = 0
 
stored.net_charge = 0
 +
# sum up the stored charges of all the atoms
 
iterate (all),stored.net_charge = stored.net_charge + partial_charge
 
iterate (all),stored.net_charge = stored.net_charge + partial_charge
 
</source>
 
</source>
  
 
+
====Example====
 
*The following example fills an array, '''stored.names''' with the names of all the residues.
 
*The following example fills an array, '''stored.names''' with the names of all the residues.
 
<source lang="python">
 
<source lang="python">
 +
# create the global variable between Python and PyMOL
 
stored.names = []
 
stored.names = []
 +
# get all of the names
 
iterate (all),stored.names.append(name)
 
iterate (all),stored.names.append(name)
 
</source>
 
</source>
  
 
+
====Example====
 
*The following prints the b-factors for all atoms around residue #1.
 
*The following prints the b-factors for all atoms around residue #1.
 
<source lang="python">
 
<source lang="python">

Revision as of 11:22, 9 April 2007

DESCRIPTION

iterate iterates over an expression with a separate name space for each atom. However, unlike the "alter" command, atomic properties can not be altered. Thus, iterate is more efficient than alter.

Iterate is a powerful tool that can be used to perform operations and aggregations using atomic selections, and store the results in any global object, such as the predefined stored object. For example, one could iterate over all of the alpha carbons and record their B Factors, or print out all of the secondary structure classifications of all the residues.

The iterate command only has access to certain properties. Those properties are:

  • name: the atom name
  • resn: the residue name
  • resi: the residue identifier (residue number)
  • chain: the chain name
  • alt:
  • elem: the chemical element
  • q
  • b: the B Factor
  • segi:
  • type (ATOM,HETATM): the atom type
  • formal_charge: the formal charge of the atom
  • partial_charge: the partial charger of the ato
  • numeric_type
  • text_type
  • ID
  • vdw

All strings in the expression must be explicitly quoted. This operation typically takes a second per thousand atoms.

Note that the coordinates of the atom are not accessible via iterate. To use the coordinates of the atoms, see iterate_state.

USAGE

iterate (selection),expression

EXAMPLES

Example

  • The following example calculates the net charge on an object.
# create the global variable between Python and PyMOL
stored.net_charge = 0
# sum up the stored charges of all the atoms
iterate (all),stored.net_charge = stored.net_charge + partial_charge

Example

  • The following example fills an array, stored.names with the names of all the residues.
# create the global variable between Python and PyMOL
stored.names = []
# get all of the names
iterate (all),stored.names.append(name)

Example

  • The following prints the b-factors for all atoms around residue #1.
iterate resi 1, print round(b,2)

SEE ALSO

Cmd iterate_state, Cmd alter, Cmd alter_state