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