<?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=FindObjectsNearby</id>
	<title>FindObjectsNearby - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pymol.org/index.php?action=history&amp;feed=atom&amp;title=FindObjectsNearby"/>
	<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=FindObjectsNearby&amp;action=history"/>
	<updated>2026-06-19T09:30:07Z</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=FindObjectsNearby&amp;diff=7957&amp;oldid=prev</id>
		<title>Pyadmin: 1 revision</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=FindObjectsNearby&amp;diff=7957&amp;oldid=prev"/>
		<updated>2014-03-28T02:16:24Z</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;== Overview ==&lt;br /&gt;
This script returns the names of all objects (in state 1) that are within a certain cutoff distance from your provided target.  For example, if you load an MD trajectory and are watching the binding pocket, you can select the ligand and then find out which loaded files are within 5 Ang, say, of that ligand atom.&lt;br /&gt;
&lt;br /&gt;
== The Code ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot; enclose=&amp;quot;pre&amp;quot;&amp;gt;&lt;br /&gt;
# -*- coding: utf-8 -*-&lt;br /&gt;
#&lt;br /&gt;
# findObjectsNearby.pml -- Get object names within a given radius of the target&lt;br /&gt;
#&lt;br /&gt;
def findObjectsNearby( target=&amp;quot;&amp;quot;, radius=2.0, doPrint=False, fileName=&amp;quot;&amp;quot; ):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	DESCRIPTION:&lt;br /&gt;
		finds all PyMOL object names within [radius] Angstroms of [target].&lt;br /&gt;
	&lt;br /&gt;
	PARAMETERS:&lt;br /&gt;
		target,		the base selection/object around which to search for things&lt;br /&gt;
		radius,		the radius of the sphere centered around target within which to search&lt;br /&gt;
		doPrint,	boolean, if True print the results to console, False no printing&lt;br /&gt;
		fileName,	string, if not blank the list called [fileName] is written to disk&lt;br /&gt;
	&lt;br /&gt;
	RETURNS:&lt;br /&gt;
		[list] of results or None if bad input.&lt;br /&gt;
		&lt;br /&gt;
	NOTES:&lt;br /&gt;
		* This function ALWAYS returns a list of results or None if the user submits malformed input.&lt;br /&gt;
		* The user may opt to print the list to console and also save it to a file.&lt;br /&gt;
&lt;br /&gt;
        EXAMPLE:&lt;br /&gt;
		* Find all objects nearby 1j01 and heteroatoms that aren't water.  (Contrived example)&lt;br /&gt;
		findObjectsNearby 1j01 and (het not resn HOH), 5.5, doPrint=True&lt;br /&gt;
&lt;br /&gt;
	AUTHOR:&lt;br /&gt;
		Jason Vertrees, 2009.  Simplified with the help of Warren DeLano.&lt;br /&gt;
	&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	if ( len(target)==0 ):&lt;br /&gt;
		print &amp;quot;Error: please provide a target selection.&amp;quot;&lt;br /&gt;
		return None&lt;br /&gt;
	&lt;br /&gt;
	stored.objs = {}&lt;br /&gt;
	cmd.iterate_state(1, &amp;quot;(&amp;quot; + target + &amp;quot;) around &amp;quot; + str(radius), &amp;quot;stored.objs[model]=1&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
	# save to file?&lt;br /&gt;
	if len(fileName) != 0:&lt;br /&gt;
		try:&lt;br /&gt;
			outFile = open(fileName, 'wb')&lt;br /&gt;
			for x in stored.objs.keys(): f.write( x + &amp;quot;\n&amp;quot; )&lt;br /&gt;
			outFile.close()&lt;br /&gt;
		except IOError:&lt;br /&gt;
			print &amp;quot;Error: couldn't open/write to output file, &amp;quot;, fileName&lt;br /&gt;
	# print?&lt;br /&gt;
	if doPrint:&lt;br /&gt;
		print stored.objs.keys()&lt;br /&gt;
&lt;br /&gt;
	return stored.objs.keys()&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;findObjectsNearby&amp;quot;, findObjectsNearby)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
If the script isn't working like you think it should, then make sure that you're in '''state #1'''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Script_Library|FindObjectsNearby]]&lt;br /&gt;
[[Category:ObjSel_Scripts]]&lt;/div&gt;</summary>
		<author><name>Pyadmin</name></author>
	</entry>
</feed>