The
iterate command executes a Python expression for all atoms in a selection. The local namespace exposes all atomic identifiers and properties as read-only Python variables. The global namespace by default is the
pymol module namespace, and thus exposes objects like
cmd and
stored. The order of iteration is that of the internal atom ordering.
The alter command is equivalent to iterate, but provides read-write access to the exposed variables. This can for example be used to rename a chain or to assign new b-factors. If changing identifiers which would affect atom ordering, calling sort is necessary to reorder based on the new identifiers.
The iterate_state command is similar to iterate, but iterates over the coordinates in the given state and selection, and exposes x, y, z in addition to the atomic identifiers and properties.
The alter_state command is equivalent to iterate_state, but allows modification of x, y, z (and atom-state level ..→