IMP logo
IMP Reference Guide  2.7.0
The Integrative Modeling Platform
pmi/automatic.py
1 ## \example pmi/automatic.py
2 """This script shows how to use the BuildSystem macro to construct large systems with minimal code
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 tempfile,os
17 import sys
18 
19 IMP.setup_from_argv(sys.argv, "Automatic setup of a large system")
21  print("This example is too slow to test in debug mode - run without")
22  print("internal tests enabled, or without the --run-quick-test flag")
23  sys.exit(0)
24 
25 # This is the topology table format.
26 # It allows you to create many components in a simple way
27 # By default it sets up each molecule as a rigid body, filling in missing pieces with beads
28 # You can create multiple domains by specifying different segments, as in Rpb1 below
29 # You can also create copies of molecules by appending '.X' to the name, as in Rpb4 below
30 topology='''
31 |molecule_name|color|fasta_fn|fasta_id|pdb_fn|chain|residue_range|pdb_offset|bead_size|em_residues_per_gaussian|rigid_body|super_rigid_body|chain_of_super_rigid_bodies|
32 |Rpb1 |blue |1WCM.fasta|1WCM:A|1WCM_fitted.pdb|A|1,100 |0 |5|0 |1|1,2| |
33 |Rpb1 |cyan |1WCM.fasta|1WCM:A|BEADS |A|101,150|0 |5|0 |2|1,2| |
34 |Rpb2 |red |1WCM.fasta|1WCM:B|1WCM_fitted.pdb|B|1,END |0 |5|0 |3|1 | |
35 |Rpb3 |green |1WCM.fasta|1WCM:C|1WCM_fitted.pdb|C|1,END |0 |5|0 |4|1 | |
36 |Rpb4 |orange |1WCM.fasta|1WCM:D|1WCM_fitted.pdb|D|1,END |0 |5|0 |5|1,3| |
37 |Rpb4.1|yellow |1WCM.fasta|1WCM:D|1WCM_fitted.pdb|D|1,END |0 |5|0 |6|1,3| |
38 |Rpb4.2|salmon |1WCM.fasta|1WCM:D|1WCM_fitted.pdb|D|1,END |0 |5|0 |7|1,3| |
39 |Rpb5 |gold |1WCM.fasta|1WCM:E|BEADS | |1,50 | |5|0 |8|1 | |
40 |Rpb5 |pink |1WCM.fasta|1WCM:E|IDEAL_HELIX | |51,100 | |5|0 |8|1 | |
41 '''
42 
43 # Normally the topology table is kept in a text file but here we just write it to a temporary one
44 tf = tempfile.NamedTemporaryFile(delete=False, mode='w')
45 tf.write(topology)
46 tf.close()
47 
48 # The TopologyReader reads the text file, and the BuildSystem macro constructs it
49 mdl = IMP.Model()
50 reader = IMP.pmi.topology.TopologyReader(tf.name,
51  pdb_dir = IMP.pmi.get_example_path('data/'),
52  fasta_dir = IMP.pmi.get_example_path('data/'),
53  gmm_dir = IMP.pmi.get_example_path('data/'))
55 bs.add_state(reader) # note you can call this multiple times to create a multi-state system
56 hier, dof = bs.execute_macro()
57 
58 ###################### RESTRAINTS #####################
59 output_objects = [] # keep a list of functions that need to be reported
60 
61 # Connectivity keeps things connected along the backbone (ignores if inside same rigid body)
62 crs = []
63 moldict = bs.get_molecules()[0]
64 mols = []
65 for molname in moldict:
66  for mol in moldict[molname]:
68  cr.add_to_model()
69  output_objects.append(cr)
70  crs.append(cr)
71  mols.append(mol)
72 
73 # Excluded volume - automatically more efficient due to rigid bodies
75 evr.add_to_model()
76 output_objects.append(evr)
77 
78 
79 ###################### SAMPLING #####################
80 
81 
82 # mix it up so it looks cool
84 
85 # Quickly move all flexible beads into place
86 dof.optimize_flexible_beads(100)
87 
89  root_hier=hier,
90  monte_carlo_sample_objects=dof.get_movers(),
91  global_output_directory='auto_output/',
92  output_objects=output_objects,
93  monte_carlo_steps=10,
94  number_of_best_scoring_models=0,
95  number_of_frames=5)
96 rex.execute_macro()
97 
98 
99 
100 os.remove(tf.name)