Pymol.stored

From PyMOLWiki
Jump to: navigation, search

The pymol.stored helper variable serves as a namespace for user defined globals which are accessible from iterate-like commands. The iterate commands by default expose the pymol module namespace as the globals dictionary, so pymol.stored is accessible as stored, and (user defined) members as stored.membername.

Example

Count number of atoms with a PyMOL script:

stored.count = 0
iterate all, stored.count += 1
print("number of atoms:", stored.count)

Count number of atoms with a Python script:

from pymol import cmd
from pymol import stored
stored.count = 0
cmd.iterate("all", "stored.count += 1")
print("number of atoms:", stored.count)

Problems

There is no guarantee that other scripts or plugins don't use the same stored member names. It is recommended that properly written plugins use the "space" argument with cmd.iterate and cmd.alter to define their own global namespace.

See Also