IMP logo
IMP Reference Guide  2.7.0
The Integrative Modeling Platform
ambiguity.py
1 ## \example pmi/ambiguity.py
2 """This script shows how to create a system with multiple copies of the same molecule.
3 We also create some crosslinks which take into account the ambiguity.
4 The key to ambiguity is using the same molecule name for ambiguous copies.
5 That way when you perform Selection it automatically finds all relevant molecules.
6 """
7 
8 import IMP
9 import RMF
10 import IMP.atom
11 import IMP.algebra
12 import IMP.rmf
13 import IMP.pmi
14 import IMP.pmi.topology
15 import IMP.pmi.dof
16 import IMP.pmi.macros
19 import tempfile
20 import os
21 import sys
22 
23 IMP.setup_from_argv(sys.argv, "ambiguity example")
24 
25 ###################### SYSTEM SETUP #####################
26 
27 ### Setup multistate system
28 mdl = IMP.Model()
30 st1 = s.create_state()
31 st2 = s.create_state()
32 
33 ### For each state add some molecules - we'll make some bead only structures
34 # State 1: ProtA (chainA), ProtA (chainB), ProtC (chainC)
35 sequence = 'A'*10
36 m1A = st1.create_molecule('ProtA',sequence,chain_id='A')
37 m1A.add_representation(m1A,resolutions=[1])
38 m1B = m1A.create_clone(chain_id='B') # create_clone() will copy name/structure/representation
39  # You cannot edit it!
40  # There is also a function create_copy() which
41  # only copies the name, then you can change reps
42 m1C = st1.create_molecule('ProtC',sequence,chain_id='C')
43 m1C.add_representation(m1C,resolutions=[1])
44 
45 # State 2: ProtA (chainA), ProtC (chainC)
46 m2A = st2.create_molecule('ProtA',sequence,chain_id='A')
47 m2A.add_representation(m2A,resolutions=[1])
48 m2C = st2.create_molecule('ProtC',sequence,chain_id='C')
49 m2C.add_representation(m2C,resolutions=[1])
50 root_hier = s.build()
51 
52 ### Display all the states, molecules, representations
54 
55 ### Setup all molecules to move as flexible beads and super rigid bodies
56 # "Super rigid bodies" aren't really rigid, it's just a mover that moves the whole body together
58 for mol in (m1A,m1B,m1C,m2A,m2C):
59  dof.create_flexible_beads(mol,
60  max_trans=0.1)
61  dof.create_super_rigid_body(mol)
62 
63 
64 ###################### RESTRAINTS #####################
65 output_objects = [] # keep a list of functions that need to be reported
66 rmf_restraints = [] # display these restraints as springs in the RMF
67 
68 ### Crosslinks setup
69 # 1) Create file. This one XL has 3 ambiguity options: State1 has 2, State2 has 1
70 lines = '''id,mol1,res1,mol2,res2,score
71 1,ProtA,3,ProtC,9,1.0
72 '''
73 tf = tempfile.NamedTemporaryFile(delete=False, mode='w')
74 tf.write(lines)
75 tf.close()
76 
77 # 2) Define the columns
79 kw.set_unique_id_key("id")
80 kw.set_protein1_key("mol1")
81 kw.set_protein2_key("mol2")
82 kw.set_residue1_key("res1")
83 kw.set_residue2_key("res2")
84 kw.set_id_score_key("score")
85 xldb = IMP.pmi.io.crosslink.CrossLinkDataBase(kw)
86 xldb.create_set_from_file(tf.name)
87 os.remove(tf.name)
88 
89 # 3) Add the restraint
91  root_hier=root_hier,
92  CrossLinkDataBase=xldb,
93  length=21,
94  label="XL",
95  resolution=1,
96  slope=0.01)
97 xlr.add_to_model()
98 output_objects.append(xlr)
99 rmf_restraints.append(xlr)
100 dof.get_nuisances_from_restraint(xlr) # needed to sample the nuisance particles (noise params)
101 
102 ### Connectivity keeps things connected along the backbone
103 crs = []
104 for mol in (m1A,m1B,m1C,m2A,m2C):
106  cr.add_to_model()
107  output_objects.append(cr)
108  rmf_restraints.append(cr)
109 
110 ### Excluded volume - one for each state (they don't interact)
111 evr1 = IMP.pmi.restraints.stereochemistry.ExcludedVolumeSphere(included_objects = (m1A,m1B,m1C))
112 evr1.add_to_model()
113 output_objects.append(evr1)
114 evr2 = IMP.pmi.restraints.stereochemistry.ExcludedVolumeSphere(included_objects = (m2A,m2C))
115 evr2.add_to_model()
116 output_objects.append(evr2)
117 
118 ###################### SAMPLING #####################
119 # randomize particles a bit
121  max_translation=20)
122 
123 # Shift state 2
124 # Even though the two states don't interact,
125 # it'll be easier to look at the RMF if we separate them
126 trans = IMP.algebra.Transformation3D([50,0,0])
127 for fb in IMP.core.get_leaves(m2A.get_hierarchy())+IMP.core.get_leaves(m2C.get_hierarchy()):
129 
130 # Run replica exchange Monte Carlo sampling
132  root_hier=root_hier, # pass the root hierarchy
133  crosslink_restraints=rmf_restraints, # will display as springs
134  monte_carlo_sample_objects=dof.get_movers(), # pass MC movers
135  global_output_directory='ambiguity_output/',
136  output_objects=output_objects,
137  monte_carlo_steps=10,
138  number_of_frames=1) # increase number of frames to get better results!
139 rex.execute_macro()
A class to simplify create of constraints and movers for an IMP Hierarchy.
Setup cross-link distance restraints from mass spectrometry data.
Definition: crosslinking.py:23
Restraints for keeping correct stereochemistry.
Simple 3D transformation class.
void show_with_representations(Hierarchy h, std::ostream &out=std::cout)
Traverse through the tree and show atom info, including representations.
def shuffle_configuration
Shuffle particles.
Definition: tools.py:1913
Set of python classes to create a multi-state, multi-resolution IMP hierarchy.
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
GenericHierarchies get_leaves(Hierarchy mhd)
Get all the leaves of the bit of hierarchy.
Protocols for sampling structures and analyzing them.
Definition: macros.py:1
This class initializes the root node of the global IMP.atom.Hierarchy.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
void transform(XYZ a, const algebra::Transformation3D &tr)
Apply a transformation to the particle.
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
This class creates a restraint between consecutive TempResidue objects OR an entire PMI MOlecule obje...
Create movers and setup constraints for PMI objects.
A class to create an excluded volume restraint for a set of particles at a given resolution.
Restraints for handling crosslinking data.
Definition: crosslinking.py:1
Python classes to represent, score, sample and analyze models.
A macro to help setup and run replica exchange.
Definition: macros.py:24
Functionality for loading, creating, manipulating and scoring atomic structures.
Support for the RMF file format for storing hierarchical molecular data and markup.