<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pymol.org/index.php?action=history&amp;feed=atom&amp;title=Example_Scripts</id>
	<title>Example Scripts - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pymol.org/index.php?action=history&amp;feed=atom&amp;title=Example_Scripts"/>
	<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Example_Scripts&amp;action=history"/>
	<updated>2026-05-25T02:19:52Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Example_Scripts&amp;diff=5825&amp;oldid=prev</id>
		<title>Pyadmin: 3 revisions</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Example_Scripts&amp;diff=5825&amp;oldid=prev"/>
		<updated>2014-03-28T01:46:40Z</updated>

		<summary type="html">&lt;p&gt;3 revisions&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Multiple Object Manipulation Scripts==&lt;br /&gt;
&lt;br /&gt;
===Dis/Enable Objects===&lt;br /&gt;
If someone has many (possibly hundreds) of objects -- say distance objects -- one can turn them all on or off by using Python scripts within PyMol.  The following script will extend the commands &amp;quot;sd&amp;quot; and &amp;quot;hd&amp;quot; for &amp;quot;show distance&amp;quot; and &amp;quot;hide distance,&amp;quot; respectively.  The first script,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from pymol import cmd &lt;br /&gt;
num_dist = 100 &lt;br /&gt;
        &lt;br /&gt;
def show_dist(): &lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; show all of my distance objects &amp;quot;&amp;quot;&amp;quot; &lt;br /&gt;
    for i in range(num_dist): &lt;br /&gt;
        cmd.enable('_dist%s'%i) &lt;br /&gt;
        &lt;br /&gt;
def hide_dist(): &lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; hide all of my distance objects &amp;quot;&amp;quot;&amp;quot; &lt;br /&gt;
    for i in range(num_dist): &lt;br /&gt;
        cmd.disable('_dist%s'%i) &lt;br /&gt;
        &lt;br /&gt;
cmd.extend('sd',show_dist) &lt;br /&gt;
cmd.extend('hd',hide_dist) &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
works on 100 objects.  We can extend the idea with more elegant scripting to work w/o forcing us to keep track of the number of objects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def show_dist(): &lt;br /&gt;
    dists = [name for name in cmd.get_names() if cmd.get_type(name) == 'object:distance'] &lt;br /&gt;
    for name in dists: cmd.enable(name) &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, just running &amp;quot;sd&amp;quot; would show all the distance objects.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Comments in Scripts===&lt;br /&gt;
The hash-mark, &amp;quot;#&amp;quot; is the Python comment.  However, when scripting in Python for PyMol note that the hash character (#) works to include comments on separate lines, but not at the end of a line that contains commands. So you can do&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# Create separate dimer&lt;br /&gt;
create dimer,(chain A,B)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
but not&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
create dimer,(chain A,B)  # Create separate dimer&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sources====&lt;br /&gt;
Taken from the PyMol Users list.  Python source by Michael Lerner.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting|Example Scripts]]&lt;/div&gt;</summary>
		<author><name>Pyadmin</name></author>
	</entry>
</feed>