Personal tools
Document Actions

Select Atoms inside AutoGrid Box

This How-to applies to: Any version.
This How-to is intended for: Any audience.

Shows how to select atoms inside AutoGrid Box and print their residue names using Python script.

If you would like to select all atoms inside a Grid Box, use shown below. Run this script by clicking on the fist button off the ADT/PMV toolbar that reads "Read Molecule or Python Script", and select Python scripts (*.py) for "Files of type:". You can also run Python Scripts from ADT/PMV by using File → Read → "Python or Session Script" menu.

Here are comments that should help you understand this code. The script start by importing AtomSet (line 5). Then it declares selection variable that is set to an empty ([]) AtomSet. In line 7 we get a handle for grid box object that is used for AutoGrid (autogpf_geoms), then on line 8 we compute the bounding box (ComputeBB). Line 9 to 14 loops through all atoms in the viewer and appends it to selection if its inside the box. Line 15 calls command to set the selection and line 17 prints residues in the selection.

 1  """   
2 Selects atoms inside AutoGrid Box and
3 print their residue names
4 """
5 from MolKit.molecule import AtomSet
6 selection = AtomSet([])
7 box = self.GUI.VIEWER.FindObjectByName('root|misc|autogpf_geoms|box')
8 minV, maxV = box.ComputeBB()
9 for mol in self.Mols:
10 for atom in mol.allAtoms:
11 if minV[0] <= atom.coords[0] and atom.coords[0] <= maxV[0]:
12 if minV[1] <= atom.coords[1] and atom.coords[1] <= maxV[1]:
13 if minV[2] <= atom.coords[2] and atom.coords[2] <= maxV[2]:
14 selection.append(atom)
16 print "Residues in the selection:"
17 print selection.parent.uniq().name

If you have similar code that you would like to share, please use Registration form to create an account then send an email by using Contact form. Once you have appropriate privileges set, you'll be able to post under Documentation and other sections of this website.

Thank you.

Attached files
by Sargis Dallakyan last modified 2008-12-30 20:23 Molecular Graphics Laboratory, TSRI

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: