Next: An atom selection example
Up: Python Text Interface
Previous: Using the Python interpreter
  Contents
  Index
VMD provides an atom selection class for use in the Python interpreter.
Instances of this class correspond to a set of atom indicies in a
particular molecule for a particular coordinate set. Once an atom
selection is made, you can query the properties of the selected atoms,
such as their names, residue ids, or coordinates. In a similar fashion,
you can set the values of these properties. You can also perform logical
operations on atom selections, including finding the intersection or
union of two atom selections or finding the inverse of the set. Finally,
you can perform tuple operations on the atom selection object to query
the indices of the atoms in the selection.
Below we summarize the methods available from the AtomSel module.
- AtomSel(selection = 'all', molid = 0, frame = 0):
Creates a new atom selection object.
sel = AtomSel('name CA', 1) # Selects the alpha carbons of molecule 1
- select(selection):
Change the selected atoms.
sel.select('resid 5')
- frame(value = -1):
Set/get the coordinate frame for the selection. Nonpositive values
will return the current value of the frame without changing it.
sel.frame(5)
sel.frame()
5
- get(attr1, attr2, ...):
Takes any number of string arguments, which should correspond to a
valid atom property such as "name", "x", or "water". Returns a list
of the value of the property for each atom in the selection. For
boolean properties such as "water", the returned value will be
1 if true and 0 if false.
x, y, z = sel.get('x', 'y', 'z')
- set(attr, val):
Set the atom property corresponding to attr using the values in
val. The number of elements in val should be either 1 or
the number in the atom selection.
len(sel)
12
sel.set('beta',3)
sel.set('beta',(1,2,3,4,5,6,7,8,9,10,11,12))
- sel1 & sel2:
Create a new atom selection using the atoms found in both sel1
and sel2.
- sel1 sel2:
Create a new atom selection using the atoms found in either sel1
or sel2.
- -sel:
Create a new atom selection using the atoms not found in sel.
- len(sel):
Returns the number of atoms in the selection.
- sel[0], sel[0:3]:
Index and slice operations return the corresponding atoms in the
selection.
Subsections
Next: An atom selection example
Up: Python Text Interface
Previous: Using the Python interpreter
  Contents
  Index
vmd@ks.uiuc.edu