Pymol.stored

From PyMOLWiki
Revision as of 14:05, 3 April 2017 by Speleo3 (talk | contribs) (created)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to 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

  • iterate
  • label