IMP logo
IMP Reference Guide  2.7.0
The Integrative Modeling Platform
pmi/multiscale.py
1 ## \example pmi/multiscale.py
2 """This script shows how to represent a system at multiple scales and do basic sampling.
3 """
4 
5 from __future__ import print_function
6 import IMP
7 import RMF
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, "Representation at multiple scales")
20  print("This example is too slow to test in debug mode - run without")
21  print("internal tests enabled, or without the --run-quick-test flag")
22  sys.exit(0)
23 
24 ###################### SYSTEM SETUP #####################
25 # Read sequences etc
27 components = ["Rpb1","Rpb2","Rpb3","Rpb4"]
28 colors = ['medium purple','goldenrod','orchid','olive drab']
29 chains = "ABCD"
30 beadsize = 10
31 
32 # Setup System and add a State
33 mdl = IMP.Model()
35 st = s.create_state()
36 
37 # Add Molecules for each component as well as representations
38 mols = []
39 for n in range(len(components)):
40  print('PMI: setting up',components[n],'1WCM:'+chains[n])
41  mol = st.create_molecule( # create molecule
42  components[n],
43  sequence=seqs['1WCM:'+chains[n]],
44  chain_id=chains[n])
45  atomic = mol.add_structure(IMP.pmi.get_example_path('data/1WCM_fitted.pdb'),
46  chain_id=chains[n],
47  offset=0)
48  mol.add_representation(atomic, # res 1,10 for structured regions
49  resolutions=[1,10],
50  color=colors[n])
51  mol.add_representation(mol[:]-atomic, # res 10 for unstructured regions
52  resolutions=[beadsize],
53  color=colors[n])
54  mols.append(mol)
55 
56 # calling System.build() creates all States and Molecules (and their representations)
57 # Once you call build(), anything without representation is destroyed.
58 # You can still use handles like molecule[a:b], molecule.get_atomic_residues() or molecule.get_non_atomic_residues()
59 # However these functions will only return BUILT representations
60 root_hier = s.build()
61 
62 # Uncomment this for verbose output of the representation
63 #IMP.atom.show_with_representations(root_hier)
64 
65 # Setup degrees of freedom
66 # The DOF functions automatically select all resolutions
67 # Objects passed to nonrigid_parts move with the frame but also have their own independent movers.
69 for mol in mols:
70  dof.create_rigid_body(mol,
71  nonrigid_parts=mol.get_non_atomic_residues(),
72  max_trans=0.1,
73  max_rot=0.78,
74  nonrigid_max_trans=0.1)
75  # display the bonds between consecutive fragments,
76  # so that they are shown in the psf
78 
79 
80 ###################### RESTRAINTS #####################
81 output_objects = [] # keep a list of functions that need to be reported
82 
83 # Connectivity keeps things connected along the backbone (ignores if inside same rigid body)
84 crs = []
85 for mol in mols:
87  cr.add_to_model()
88  output_objects.append(cr)
89  crs.append(cr)
90 
91 # Excluded volume - automatically more efficient due to rigid bodies
93 evr.add_to_model()
94 output_objects.append(evr)
95 
96 
97 ###################### SAMPLING #####################
98 # First shuffle the system
100  max_translation=30)
101 
102 # Quickly move all flexible beads into place
103 dof.optimize_flexible_beads(100)
104 
105 # Run replica exchange Monte Carlo sampling
107  root_hier=root_hier, # pass the root hierarchy
108  crosslink_restraints=crs, # will display like XLs
109  monte_carlo_sample_objects=dof.get_movers(), # pass MC movers
110  global_output_directory='multiscale_output/',
111  output_objects=output_objects,
112  monte_carlo_steps=10,
113  number_of_best_scoring_models=0, # set >0 to store best PDB files (but this is slow to do online)
114  number_of_frames=1) # increase number of frames to get better results!
115 rex.execute_macro()