Pymol.stored: Difference between revisions

From PyMOLWiki
Jump to navigation Jump to search
(created)
 
m (see also links)
 
Line 27: Line 27:
== See Also ==
== See Also ==


* iterate
* [[iterate]]
* label
* [[label]]
 
[[Category:Scripting]]

Latest revision as of 14:21, 3 April 2017

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