IMP logo
IMP Reference Guide  2.11.1
The Integrative Modeling Platform
pmi/selection.py
1 ## \example pmi/selection.py
2 """This script demonstrates a few different ways you can perform selection in PMI.
3 In PMI we first set up molecules at various resolutions.
4 Then you call System.build() and this creates all requested representations.
5 """
6 
7 import IMP
8 import IMP.atom
9 import IMP.rmf
10 import IMP.pmi
11 import IMP.pmi.topology
12 import IMP.pmi.dof
13 import IMP.pmi.macros
14 import IMP.pmi.restraints
16 import sys
17 
18 IMP.setup_from_argv(sys.argv, "Selection in PMI")
19 
20 ################ BEFORE BUILDING ###################
21 # Preliminaries: read sequences, create a system and a state
23 mdl = IMP.Model()
25 st = s.create_state()
26 
27 # Create a molecule. This sets up "TempResidues" for all elements in the sequence.
28 mol = st.create_molecule("Rpb4",seqs["1WCM:D"],chain_id="D")
29 
30 # No structure has been built yet - you have to call 'Molecule.add_representation'
31 # The first argument to that function is a set of "TempResidues"
32 # Here are some ways of getting them:
33 
34 # Slice a molecule (uses python-style 0-ordering)
35 myres1 = mol[0:10]
36 
37 # Use PDB numbering with residue_range (inclusive on both ends)
38 myres2 = mol.residue_range('1','10')
39 
40 # If you add a PDB, this returns the set of TempResidues that were in the PDB file
41 atomic = mol.add_structure(IMP.pmi.get_example_path('data/1WCM_fitted.pdb'),
42  chain_id="D")
43 
44 # You can also call these helper functions at any time
45 atomic = mol.get_atomic_residues()
46 non_atomic = mol.get_non_atomic_residues()
47 
48 # All of the above objects are OrderedSets, so you can actually perform set operations
49 myres3 = mol[0:50] - atomic # non-atomic residues from 0 to 50
50 myres4 = mol[0:50] & atomic # atomic residues between 0 and 50
51 
52 # Finally, pass your favorite handle to add_representation
53 mol.add_representation(myres3,
54  resolutions=[1]) #creates beads with size 1 (non-atomic can only have one beadsize)
55 mol.add_representation(myres4,
56  resolutions=[1,10]) #creates beads with size 1 and 10
57 
58 # When you have decided all representations, call build()
59 # This returns an IMP hierarchy
60 hier = s.build()
61 
62 # View your creation with this function
64 
65 
66 ################ AFTER BUILDING ###################
67 # After building, only what you requested with add_representation() can be selected
68 
69 # PMI selection
70 # Most PMI functions will let you pass Molecules or TempResidues and it will automatically gather things.
72  resolution=1)
73 
74 # Similarly for rigid body creation, we recommend passing PMI objects and it will gather all resolutions
76 dof.create_rigid_body(mol,
77  nonrigid_parts = non_atomic,
78  resolution='all')
79 
80 # Advanced: IMP selection
81 # Note if you request a resolution this will find the NEAREST available resolution.
82 # E.g. if only resolution 1 is built, those particles will be returned below:
83 sel = IMP.atom.Selection(hier,resolution=10,molecule="Rpb4",residue_indexes=range(1,10))
84 particles = sel.get_selected_particles()
85 
86 # Retrieving the molecule object
87 # The molecules are stored within the state, so you can do :
88 all_mol_copies = st.molecules["Rpb4"] # a list of all copies
89 mol = all_mol_copies[0]