<?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=FilterByMol</id>
	<title>FilterByMol - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pymol.org/index.php?action=history&amp;feed=atom&amp;title=FilterByMol"/>
	<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=FilterByMol&amp;action=history"/>
	<updated>2026-07-18T15:02:18Z</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=FilterByMol&amp;diff=7334&amp;oldid=prev</id>
		<title>Pyadmin: 3 revisions</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=FilterByMol&amp;diff=7334&amp;oldid=prev"/>
		<updated>2014-03-28T02:00:42Z</updated>

		<summary type="html">&lt;p&gt;3 revisions&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 02:00, 28 March 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Pyadmin</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=FilterByMol&amp;diff=7333&amp;oldid=prev</id>
		<title>Newacct at 08:13, 27 November 2009</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=FilterByMol&amp;diff=7333&amp;oldid=prev"/>
		<updated>2009-11-27T08:13:34Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Overview ==&lt;br /&gt;
This script filters through all the PDBs in the parent dir (you can easily the the directory it scans).  For each molecule, it saves '''just''' the ligands/heteroatoms (excluding the waters).  This gives you a simple way to filter through a database of proteins looking only at their ligands.&lt;br /&gt;
&lt;br /&gt;
This script, as noted below, works on the objects at the level of a '''molecule'''.  While we can [[iterate]] over atom number (ID), residue number (resi), etc we do not have any such &amp;quot;MOLID&amp;quot;.  So, we provide this simple workaround.  You might need this file because if you have a residue (like #111 from 3BEP) that consists of a molecule and an atom then there's no other way to save the separate pieces (of molecule/atom) into two (or more files).  As you can see in the following listing, if we iterate over the hetero atoms (and not waters) in 3BEP we get,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
PyMOL&amp;gt;iterate bymol het, print resi, resn, ID, chain, segi, alt&lt;br /&gt;
111 5CY 6473 C  &lt;br /&gt;
111 5CY 6474 C  &lt;br /&gt;
111 5CY 6476 C  &lt;br /&gt;
111 5CY 6477 C  &lt;br /&gt;
111 5CY 6478 C  &lt;br /&gt;
111 5CY 6479 C  &lt;br /&gt;
111 5CY 6480 C  &lt;br /&gt;
111 5CY 6481 C  &lt;br /&gt;
111 5CY 6482 C  &lt;br /&gt;
111 5CY 6483 C  &lt;br /&gt;
111 5CY 6484 C  &lt;br /&gt;
111 5CY 6485 C  &lt;br /&gt;
111 5CY 6486 C  &lt;br /&gt;
111 5CY 6487 C  &lt;br /&gt;
111 5CY 6488 C  &lt;br /&gt;
111 5CY 6489 C  &lt;br /&gt;
111 5CY 6490 C  &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
which does not allow us to separate the two pieces.&lt;br /&gt;
&lt;br /&gt;
== The Code ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
python&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# This simple script will filter through all PDBs in a directory, and for each one&lt;br /&gt;
# save all the ligands/heterotoms (that aren't waters) to their own file.  This&lt;br /&gt;
# script operates at the level of molecules, not residues, atoms, etc.  Thus, if&lt;br /&gt;
# you have a ligand that PyMOL is treating as ONE residue, but is actually two&lt;br /&gt;
# separate molecules, or a molecule and an atom, then you will get multiple files.&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
from glob import glob&lt;br /&gt;
from os import path&lt;br /&gt;
from pymol import stored&lt;br /&gt;
&lt;br /&gt;
theFiles = glob(&amp;quot;../*.pdb&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
for f in theFiles:&lt;br /&gt;
    # load the file&lt;br /&gt;
    cmd.load(f);&lt;br /&gt;
    # remove the protein and waters&lt;br /&gt;
    cmd.remove(&amp;quot;polymer or resn HOH&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    cmd.select(&amp;quot;input&amp;quot;, &amp;quot;all&amp;quot;)&lt;br /&gt;
    cmd.select(&amp;quot;processed&amp;quot;, &amp;quot;none&amp;quot;)&lt;br /&gt;
    mol_cnt = 0&lt;br /&gt;
&lt;br /&gt;
    while cmd.count_atoms(&amp;quot;input&amp;quot;):&lt;br /&gt;
        # filter through the selections, updating the lists&lt;br /&gt;
        cmd.select(&amp;quot;current&amp;quot;,&amp;quot;bymolecule first input&amp;quot;)&lt;br /&gt;
        cmd.select(&amp;quot;processed&amp;quot;,&amp;quot;processed or current&amp;quot;)&lt;br /&gt;
        cmd.select(&amp;quot;input&amp;quot;,&amp;quot;input and not current&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        # prepare the output parameters&lt;br /&gt;
        curOut = path.basename(f).split(&amp;quot;.&amp;quot;)[0] + &amp;quot;_&amp;quot; + str(mol_cnt).zfill(5) + &amp;quot;_het.pdb&amp;quot;&lt;br /&gt;
        curSel = &amp;quot;current&amp;quot;&lt;br /&gt;
        &lt;br /&gt;
        # save the file&lt;br /&gt;
        cmd.save( curOut, curSel );&lt;br /&gt;
        print &amp;quot;Saved &amp;quot; + curSel + &amp;quot; to &amp;quot; + curOut&lt;br /&gt;
        &lt;br /&gt;
        mol_cnt = mol_cnt + 1;&lt;br /&gt;
&lt;br /&gt;
    # remove all to move to next molecule&lt;br /&gt;
    cmd.delete(&amp;quot;*&amp;quot;);        &lt;br /&gt;
&lt;br /&gt;
python end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Script_Library]]&lt;br /&gt;
[[Category:System_Scripts]]&lt;/div&gt;</summary>
		<author><name>Newacct</name></author>
	</entry>
</feed>