next up previous contents index
Next: selection.add() add Up: The selection class: handling Previous: The selection class: handling   Contents   Index

selection() -- create a new selection

selection(*atoms)

This creates a new empty selection object. An initial group of atoms or other objects can be added to the selection by listing them here; see Section 6.9 for more information.

Example: examples/python/selection.py


from modeller import *

env = environ()
env.io.atom_files_directory = '../atom_files'
env.libs.topology.read(file='$(LIB)/top_heav.lib')
env.libs.parameters.read(file='$(LIB)/par.lib')

mdl = model(env, file='1fdx')

# New empty selection
s = selection()

# Add all atoms from residues 4 through 10 inclusive (PDB numbering)
s.add(mdl.residue_range('4', '10'))

# Selection of all atoms currently within 5A of atom CA:1 (this destroys the
# previous selection):
s = mdl.atoms['CA:1'].select_sphere(5)

# Is the CB:1 atom in the selection?
print mdl.atoms['CB:1'] in s

# All atoms currently within 5A of atom CA:1, OR currently within 3A of the
# point (1,10,1):
s = mdl.atoms['CA:1'].select_sphere(5) | mdl.point(1,10,1).select_sphere(3)

# All atoms currently within 5A of atom CA:1, AND also currently within 3A
# of the point (1,10,1):
s = mdl.atoms['CA:1'].select_sphere(5) & mdl.point(1,10,1).select_sphere(3)

# All atoms currently within 5A of atom CA:1, OR currently within 3A of the
# point (1,10,1), but not BOTH:
s = mdl.atoms['CA:1'].select_sphere(5) ^ mdl.point(1,10,1).select_sphere(3)

# Create a selection containing the CA atom from residue 1,
# and all of residue 2 (PDB numbering)
s = selection(mdl.atoms['CA:1'], mdl.residues['2'])

# All residues EXCEPT 5-10 (i.e. all atom selection minus the selection
# of residues 5-10, otherwise known as an inverted selection):
s = selection(mdl) - selection(mdl.residue_range('5', '10'))

# Selection of residues 1, 4, 8 and 10-15 (PDB numbering):
s = selection(mdl.residues['1'], mdl.residues['4'], mdl.residues['8'],
              mdl.residue_range('10', '15'))

# Print the center of mass (note: not mass weighted)
print s.mass_center

# Rotate by 90 degrees about the z axis through the origin (0,0,0)
# (right handed rotation)
s.rotate_origin([0,0,1], 90)

# The same thing, except that the axis passes through the center of mass:
s.rotate_mass_center([0,0,1], 90)

# Translate by 5 angstroms along the x axis
s.translate([5.0, 0, 0])

# Equivalent (but less efficient, as it involves calculating the COM)
s.x += 5.0

Example: examples/commands/pick_atoms.py


# This will pick various subsets of atoms in the MODEL and compare them 
# with MODEL2.

from modeller import *

env = environ()
env.io.atom_files_directory = '../atom_files'
log.level(1, 1, 1, 1, 0)

# Read the models and the alignment:
mdl  = model(env, file='1fas')
mdl2 = model(env, file='2ctx')
aln = alignment(env, file='toxin.ali', align_codes=('1fas', '2ctx'))
aln.write(file='toxin.pap', alignment_format='PAP')

# Pick and superpose mainchain atoms:
atmsel = selection(mdl).only_mainchain()
atmsel.superpose(mdl2, aln)

# Pick and superpose sidechain atoms:
atmsel = selection(mdl).only_sidechain()
atmsel.superpose(mdl2, aln)

# Pick and superpose CA and CB atoms:
atmsel = selection(mdl).only_atom_types('CA CB')
atmsel.superpose(mdl2, aln)

# Pick and superpose all atoms:
atmsel = selection(mdl)
atmsel.superpose(mdl2, aln)

# Pick and superpose CA and CB atoms in one segment only:
atmsel = selection(mdl.residue_range('2:', '10:')).only_atom_types('CA CB')
atmsel.superpose(mdl2, aln)

# Pick and superpose all atoms within 6 angstroms of the 'CA' atom in residue '10:':
atmsel = mdl.atoms['CA:10'].select_sphere(6.0)
atmsel.superpose(mdl2, aln)

# Pick and superpose all atoms within 6 angstroms of any atom in 
# segment 2: to 10:
atmsel = selection(mdl.residue_range('2:', '10:')).select_sphere(6.0)
atmsel.superpose(mdl2, aln)

# Pick all atoms in the model
atmsel = selection(mdl)

# Pick all atoms in all loops (ie residues within 2 positions 
# of any gap in the alignment):
loops = mdl2.loops(aln, minlength=5, maxlength=15, insertion_ext=2,
                   deletion_ext=2)
atmsel = selection(loops)

# Pick all atoms within 6 angstroms of all loops
atmsel = selection(loops).select_sphere(6.0)



Ben Webb 2007-01-19