<?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=SelInside</id>
	<title>SelInside - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pymol.org/index.php?action=history&amp;feed=atom&amp;title=SelInside"/>
	<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=SelInside&amp;action=history"/>
	<updated>2026-10-15T21:21:27Z</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=SelInside&amp;diff=9693&amp;oldid=prev</id>
		<title>Bell: 1 revision</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=SelInside&amp;diff=9693&amp;oldid=prev"/>
		<updated>2014-03-28T03:49:38Z</updated>

		<summary type="html">&lt;p&gt;1 revision&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[selInside]] selects all atoms of a certain type that are located within the bounding box defined by some selection.  See examples.&lt;br /&gt;
&lt;br /&gt;
= Usage =&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# find all atoms inside the box spanned by (0,0,0) and (10,10,10)&lt;br /&gt;
# for the example PDB, 1hpv&lt;br /&gt;
fetch 1hpv&lt;br /&gt;
pseudoatom b1, pos=[0,0,0]&lt;br /&gt;
pseudoatom b2, pos=[10,10,10]&lt;br /&gt;
selInside b1 or b2&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&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;
import pymol&lt;br /&gt;
from pymol import cmd, stored&lt;br /&gt;
from random import randint&lt;br /&gt;
&lt;br /&gt;
def selInside(bounding_object, target=&amp;quot;*&amp;quot;, radius=None):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    Selects all atoms of a given target type inside some selection that acts like a bounding box.&lt;br /&gt;
&lt;br /&gt;
    PARAMS:&lt;br /&gt;
        bounding_object -- [PyMOL object/selection] the object/selection inside of which we want to choose atoms&lt;br /&gt;
        target -- [PyMOL selection] that defines the atoms to select.  Use &amp;quot;solvent&amp;quot; to select&lt;br /&gt;
                  only solvent atoms inside the selection&lt;br /&gt;
        radius -- [float] expand the box by this many angstroms on all sides&lt;br /&gt;
&lt;br /&gt;
    RETURNS:&lt;br /&gt;
        (string) name of the selection created&lt;br /&gt;
&lt;br /&gt;
    NOTES:&lt;br /&gt;
       assumes a single-state setup; for multi-state you must modify this script&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    # get the extents of the bounding object into two arrays&lt;br /&gt;
    (bMin, bMax) = cmd.get_extent(bounding_object)&lt;br /&gt;
&lt;br /&gt;
    # if the user supplied a size by which we need to expand the box, we do that here&lt;br /&gt;
    if radius!=None:&lt;br /&gt;
        try:&lt;br /&gt;
            # try to convert a string to a float&lt;br /&gt;
            radius = float(str(radius))&lt;br /&gt;
        except ValueError:&lt;br /&gt;
            print &amp;quot;ERROR: Invalid radius declared.  Please make sure the radius is a number or left blank&amp;quot;&lt;br /&gt;
            return&lt;br /&gt;
        # add/subtract the radius to the bounds&lt;br /&gt;
        bMin = map( lambda f: f-radius, bMin)&lt;br /&gt;
        bMax = map( lambda f: f+radius, bMax)&lt;br /&gt;
 &lt;br /&gt;
    # initialize a selection; selections starting with underscores are hidden by PyMOL&lt;br /&gt;
    cmd.select(&amp;quot;__toRemove&amp;quot;, &amp;quot;None&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    # for each atom in the target selection, if it's inside the box, add it to the selection&lt;br /&gt;
    for at in cmd.get_model(target).atom:&lt;br /&gt;
        if at.coord[0] &amp;gt; bMin[0] and at.coord[0] &amp;lt; bMax[0] and at.coord[1] &amp;gt; bMin[1] and at.coord[1] &amp;lt; bMax[1] and at.coord[2] &amp;gt; bMin[2] and at.coord[2] &amp;lt; bMax[2] :&lt;br /&gt;
           cmd.select(&amp;quot;__toRemove&amp;quot;, &amp;quot;__toRemove or index %d&amp;quot; % at.index)&lt;br /&gt;
&lt;br /&gt;
    # prepare the return values&lt;br /&gt;
    rName = &amp;quot;insideBoundingObj&amp;quot;&lt;br /&gt;
    cmd.set_name(&amp;quot;__toRemove&amp;quot;, rName)&lt;br /&gt;
&lt;br /&gt;
    return rName&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;selInside&amp;quot;, selInside)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Script_Library]] [[Category:ObjSel_Scripts]]&lt;/div&gt;</summary>
		<author><name>Bell</name></author>
	</entry>
</feed>