IMP logo
IMP Reference Guide  2.20.1
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
3  basic sampling.
4 """
5 
6 from __future__ import print_function
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, "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(
46  IMP.pmi.get_example_path('data/1WCM_fitted.pdb'),
47  chain_id=chains[n], 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
57 # representations)
58 # Once you call build(), anything without representation is destroyed.
59 # You can still use handles like molecule[a:b], molecule.get_atomic_residues()
60 # or molecule.get_non_atomic_residues()
61 # However these functions will only return BUILT representations
62 root_hier = s.build()
63 
64 # Uncomment this for verbose output of the representation
65 # IMP.atom.show_with_representations(root_hier)
66 
67 # Setup degrees of freedom
68 # The DOF functions automatically select all resolutions
69 # Objects passed to nonrigid_parts move with the frame but also have
70 # their own independent movers.
72 for mol in mols:
73  dof.create_rigid_body(mol,
74  nonrigid_parts=mol.get_non_atomic_residues(),
75  max_trans=0.1,
76  max_rot=0.78,
77  nonrigid_max_trans=0.1)
78  # display the bonds between consecutive fragments,
79  # so that they are shown in the psf
81 
82 
83 # ##################### RESTRAINTS #####################
84 output_objects = [] # keep a list of functions that need to be reported
85 
86 # Connectivity keeps things connected along the backbone (ignores if inside
87 # same rigid body)
88 crs = []
89 for mol in mols:
91  cr.add_to_model()
92  output_objects.append(cr)
93  crs.append(cr)
94 
95 # Excluded volume - automatically more efficient due to rigid bodies
97  included_objects=mols)
98 evr.add_to_model()
99 output_objects.append(evr)
100 
101 
102 # ##################### SAMPLING #####################
103 # First shuffle the system
104 IMP.pmi.tools.shuffle_configuration(root_hier, max_translation=30)
105 
106 # Quickly move all flexible beads into place
107 dof.optimize_flexible_beads(100)
108 
109 # Run replica exchange Monte Carlo sampling
111  mdl,
112  # pass the root hierarchy
113  root_hier=root_hier,
114  # pass MC movers
115  monte_carlo_sample_objects=dof.get_movers(),
116  global_output_directory='multiscale_output/',
117  output_objects=output_objects,
118  monte_carlo_steps=10,
119  # set >0 to store best PDB files (but this is slow to do online)
120  number_of_best_scoring_models=0,
121  # increase number of frames to get better results!
122  number_of_frames=1)
123 rex.execute_macro()