IMP logo
IMP Reference Guide  2.21.0
The Integrative Modeling Platform
nude_modeling.py
1 ##########################################################################################
2 ######################### IMP Modeling Script for NuDe Complex ###########################
3 ##########################################################################################
4 
5 
6 # Imports
7 from __future__ import print_function
8 import IMP
9 import RMF
10 import IMP.rmf
11 import IMP.pmi
12 import IMP.pmi.io
14 import IMP.pmi.tools
15 import IMP.pmi.topology
16 import IMP.pmi.macros
17 import IMP.pmi.restraints
20 import ihm.cross_linkers
23 import IMP.pmi.dof
24 from IMP.nestor import NestedSampling
25 import IMP.atom
26 import contextlib
27 
28 # import IMP.saxs
29 import os
30 import sys
31 
32 IMP.setup_from_argv(sys.argv, "Application of NestOR to the NuDe subcomplex")
33 
34 dat_dir = IMP.nestor.get_example_path("input")
35 
36 if not os.path.exists(os.path.join(dat_dir, 'gmm/emd_22904.mrc')):
37  print("To run this example, first download the EM map from EMD22094,")
38  print("extract it, rename it as `emd_22904.mrc` and place it in")
39  print("the `input/gmm/` directory.")
40  sys.exit(0)
41 
42 run_output_dir = "run_" + "0" # sys.argv[1]
43 topology_file = os.path.join(dat_dir, "topology50.txt") # sys.argv[2]
44 h_param_file = os.path.join(dat_dir, "nestor_params_optrep.yaml") # sys.argv[3]
45 
46 max_shuffle_core = 5
47 max_shuffle_set2 = 50
48 rex_max_temp = 2.4
49 
50 # Identify data files
51 sampling_adh_xl_data = os.path.join(dat_dir, "xlms/sampling_filtered_adh.dat")
52 sampling_bs3dss_xl_data = os.path.join(dat_dir, "xlms/sampling_filtered_bs3dss.dat")
53 sampling_dmtmm_xl_data = os.path.join(dat_dir, "xlms/sampling_filtered_dmtmm.dat")
54 
55 evi_adh_xl_data = os.path.join(dat_dir, "xlms/evicalc_filtered_adh.dat")
56 evi_bs3dss_xl_data = os.path.join(dat_dir, "xlms/evicalc_filtered_adh.dat")
57 evi_dmtmm_xl_data = os.path.join(dat_dir, "xlms/evicalc_filtered_adh.dat")
58 
59 gmm_data = os.path.join(dat_dir, "gmm/emd_22904.gmm.40.txt")
60 # Restraint weights
61 intra_xl_weight = 1.0
62 inter_xl_weight = 10.0
63 xl_weight = 10
64 em_weight = 1000.0
65 
66 
67 def modeling(output_dir, topology_file, h_param_file):
68  mdl = IMP.Model()
70  topology_file,
71  pdb_dir=os.path.join(dat_dir, 'pdb'),
72  fasta_dir=os.path.join(dat_dir, 'fasta'),
73  gmm_dir=os.path.join(dat_dir, 'gmm'))
75  bs.add_state(t)
76 
77  root_hier, dof = bs.execute_macro(
78  max_rb_trans=1,
79  max_rb_rot=0.1,
80  max_bead_trans=3.2,
81  max_srb_trans=0.01,
82  max_srb_rot=0.04,
83  )
84 
85  # Fixing particles
86  set1_core = []
87  for prot in ["MTA1"]:
88  for cp in [0, 1]:
89  set1_core += IMP.atom.Selection(
90  root_hier, molecule=prot, copy_index=cp, residue_indexes=range(165, 334)
91  ).get_selected_particles()
92  for prot in ["HDAC1"]:
93  for cp in [0, 1]:
94  set1_core += IMP.atom.Selection(
95  root_hier, molecule=prot, copy_index=cp, residue_indexes=range(8, 377)
96  ).get_selected_particles()
97 
98  set2 = []
99  for prot in ["MTA1"]:
100  for cp in [0, 1]:
101  set2 += IMP.atom.Selection(
102  root_hier, molecule=prot, copy_index=cp, residue_indexes=range(1, 165)
103  ).get_selected_particles()
104  for prot in ["MTA1"]:
105  for cp in [0, 1]:
106  set2 += IMP.atom.Selection(
107  root_hier, molecule=prot, copy_index=cp, residue_indexes=range(334, 432)
108  ).get_selected_particles()
109  for prot in ["HDAC1"]:
110  for cp in [0, 1]:
111  set2 += IMP.atom.Selection(
112  root_hier, molecule=prot, copy_index=cp, residue_indexes=range(1, 8)
113  ).get_selected_particles()
114  for prot in ["HDAC1"]:
115  for cp in [0, 1]:
116  set2 += IMP.atom.Selection(
117  root_hier, molecule=prot, copy_index=cp, residue_indexes=range(377, 483)
118  ).get_selected_particles()
119  for prot in ["MBD3"]:
120  set2 += IMP.atom.Selection(
121  root_hier, molecule=prot, copy_index=0, residue_indexes=range(1, 296)
122  ).get_selected_particles()
123  for prot in ["P66A"]:
124  set2 += IMP.atom.Selection(
125  root_hier, molecule=prot, copy_index=0, residue_indexes=range(136, 179)
126  ).get_selected_particles()
127  for prot in ["RBBP4"]:
128  for cp in [0, 1, 2, 3]:
129  set2 += IMP.atom.Selection(
130  root_hier, molecule=prot, copy_index=cp, residue_indexes=range(1, 425)
131  ).get_selected_particles()
132 
133  fixed_set1_core_beads, fixed_set1_core = dof.disable_movers(
135  )
136 
137  fixed_set2_beads, fixed_set2 = dof.disable_movers(
139  )
140  molecules = t.get_components()
141 
142  #####################################################
143  ##################### RESTRAINTS ####################
144  #####################################################
145 
146  output_objects = []
147  nestor_restraints = []
148 
149  # -----------------------------
150  # CONNECTIVITY RESTRAINT
151 
152  for m in root_hier.get_children()[0].get_children():
154  cr.add_to_model()
155  output_objects.append(cr)
156 
157  print("Connectivity restraint applied")
158 
159  # -----------------------------
160  # EXCLUDED VOLUME RESTRAINT
161 
163  included_objects=[root_hier], resolution=1000
164  )
165  output_objects.append(evr)
166 
167  print("Excluded volume restraint applied")
168 
169  # -------------------------
170  # CROSSLINKING RESTRAINT
171  # Sampling XL restraints
172 
174  xldbkc.set_standard_keys()
175 
176  xldb_adh_sampling = IMP.pmi.io.crosslink.CrossLinkDataBase()
177  xldb_adh_sampling.create_set_from_file(
178  file_name=sampling_adh_xl_data, converter=xldbkc
179  )
180  xlr_adh_sampling = (
182  root_hier=root_hier,
183  database=xldb_adh_sampling,
184  length=25,
185  resolution=1,
186  slope=0.0001,
187  label="adh",
188  weight=xl_weight,
189  linker=ihm.cross_linkers.edc,
190  )
191  )
192 
193  xldb_bs3dss_sampling = IMP.pmi.io.crosslink.CrossLinkDataBase()
194  xldb_bs3dss_sampling.create_set_from_file(
195  file_name=sampling_bs3dss_xl_data, converter=xldbkc
196  )
197  xlr_bs3dss_sampling = (
199  root_hier=root_hier,
200  database=xldb_bs3dss_sampling,
201  length=25,
202  resolution=1,
203  slope=0.0001,
204  label="bs3dss",
205  weight=xl_weight,
206  linker=ihm.cross_linkers.bs3,
207  )
208  )
209 
210  xldb_dmtmm_sampling = IMP.pmi.io.crosslink.CrossLinkDataBase()
211  xldb_dmtmm_sampling.create_set_from_file(
212  file_name=sampling_dmtmm_xl_data, converter=xldbkc
213  )
214  xlr_dmtmm_sampling = (
216  root_hier=root_hier,
217  database=xldb_dmtmm_sampling,
218  length=16,
219  resolution=1,
220  slope=0.0001,
221  label="dmtmm",
222  weight=xl_weight,
223  linker=ihm.cross_linkers.dsso,
224  )
225  )
226 
227  output_objects.append(xlr_adh_sampling)
228  output_objects.append(xlr_bs3dss_sampling)
229  output_objects.append(xlr_dmtmm_sampling)
230 
231  # ----------------------------------------------------
232  # Nesting XL restraints
233 
235  xldbkc.set_standard_keys()
236 
237  xldb_adh_evicalc = IMP.pmi.io.crosslink.CrossLinkDataBase()
238  xldb_adh_evicalc.create_set_from_file(file_name=evi_adh_xl_data, converter=xldbkc)
239  xlr_adh_evicalc = (
241  root_hier=root_hier,
242  database=xldb_adh_evicalc,
243  length=25,
244  resolution=1,
245  slope=0.0001,
246  label="adh",
247  weight=0,
248  linker=ihm.cross_linkers.edc,
249  )
250  )
251 
252  xldb_bs3dss_evicalc = IMP.pmi.io.crosslink.CrossLinkDataBase()
253  xldb_bs3dss_evicalc.create_set_from_file(
254  file_name=evi_bs3dss_xl_data, converter=xldbkc
255  )
256  xlr_bs3dss_evicalc = (
258  root_hier=root_hier,
259  database=xldb_bs3dss_evicalc,
260  length=25,
261  resolution=1,
262  slope=0.0001,
263  label="bs3dss",
264  weight=0,
265  linker=ihm.cross_linkers.bs3,
266  )
267  )
268 
269  xldb_dmtmm_evicalc = IMP.pmi.io.crosslink.CrossLinkDataBase()
270  xldb_dmtmm_evicalc.create_set_from_file(
271  file_name=evi_dmtmm_xl_data, converter=xldbkc
272  )
273  xlr_dmtmm_evicalc = (
275  root_hier=root_hier,
276  database=xldb_dmtmm_evicalc,
277  length=16,
278  resolution=1,
279  slope=0.0001,
280  label="dmtmm",
281  weight=0,
282  linker=ihm.cross_linkers.dsso,
283  )
284  )
285 
286  output_objects.append(xlr_adh_evicalc)
287  output_objects.append(xlr_bs3dss_evicalc)
288  output_objects.append(xlr_dmtmm_evicalc)
289 
290  nestor_restraints.append(xlr_adh_evicalc)
291  nestor_restraints.append(xlr_bs3dss_evicalc)
292  nestor_restraints.append(xlr_dmtmm_evicalc)
293 
294  print("Cross-linking restraint applied")
295 
296  # EM RESTRAINT
297  densities = IMP.atom.Selection(
298  root_hier, representation_type=IMP.atom.DENSITIES
299  ).get_selected_particles()
300 
302  densities,
303  target_fn=gmm_data,
304  slope=0.00000001,
305  scale_target_to_mass=True,
306  weight=0,
307  )
308 
309  output_objects.append(emr)
310  nestor_restraints.append(emr)
311  print("EM Restraint Applied")
312 
313  #####################################################
314  ###################### SAMPLING #####################
315  #####################################################
316 
317  exit_code = None
318  try:
320  root_hier,
321  max_translation=max_shuffle_set2,
322  excluded_rigid_bodies=fixed_set1_core,
323  )
324 
326  root_hier,
327  max_translation=max_shuffle_core,
328  excluded_rigid_bodies=fixed_set2,
329  )
330 
331  except ValueError:
332  exit_code = 11
333  with open("shuffle_config.err", "w") as shufferr:
334  shufferr.write(str(11))
335  shufferr.flush()
336 
337  print(f"{'-'*50}\nExit code: {exit_code}\n{'-'*50}")
338  dof.optimize_flexible_beads(50)
339 
341 
342  # Now, add all of the other restraints to the scoring function to start sampling
343  evr.add_to_model()
344  emr.add_to_model()
345  xlr_adh_sampling.add_to_model()
346  xlr_bs3dss_sampling.add_to_model()
347  xlr_dmtmm_sampling.add_to_model()
348  xlr_adh_evicalc.add_to_model()
349  xlr_bs3dss_evicalc.add_to_model()
350  xlr_dmtmm_evicalc.add_to_model()
351 
352  print("Replica Exchange Maximum Temperature : " + str(rex_max_temp))
353 
355  mdl,
356  root_hier=root_hier,
357 
358  monte_carlo_temperature=1.0,
359  replica_exchange_minimum_temperature=1.0,
360  replica_exchange_maximum_temperature=rex_max_temp,
361  monte_carlo_sample_objects=dof.get_movers(),
362  global_output_directory=run_output_dir,
363  output_objects=output_objects,
364  monte_carlo_steps=10,
365  number_of_best_scoring_models=0,
366  number_of_frames=0,
367  use_nestor=True,
368  )
369 
370  ns = NestedSampling(
371  rex_macro=rex,
372  nestor_restraints=nestor_restraints,
373  h_param_file=h_param_file,
374  exit_code=exit_code,
375  )
376 
377  ns_return, ns_exit_code = ns.execute_nested_sampling2()
378  return ns_return, ns_exit_code
379 
380 
381 with open("errors.log", "w") as errf:
382  with contextlib.redirect_stdout(None):
383  with contextlib.redirect_stderr(errf):
384  nested_sampling_output, nested_sampling_exitcode = modeling(
385  run_output_dir, topology_file, h_param_file
386  )
387 
388 
389 if nested_sampling_output is not None:
390  print(f"////{nested_sampling_output}")
391 
392 sys.exit(nested_sampling_exitcode)
Setup cross-link distance restraints from mass spectrometry data.
Restraints for keeping correct stereochemistry.
Fit Gaussian-decorated particles to an EM map (also represented with a set of Gaussians) ...
def shuffle_configuration
Shuffle particles.
Definition: tools.py:1258
A macro to help setup and run replica exchange.
Definition: macros.py:70
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)
Some miscellaneous simple restraints.
Utility classes and functions for reading and storing PMI files.
def enable_all_movers
Re-enable all movers: previously fixed particles will be released.
Miscellaneous utilities.
Definition: tools.py:1
Modify the transformation of a rigid body.
A macro to build a IMP::pmi::topology::System based on a TopologyReader object.
Definition: macros.py:635
Protocols for sampling structures and analyzing them.
Definition: macros.py:1
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
Classes to handle different kinds of restraints.
Restraints for handling electron microscopy maps.
Modify the transformation of a rigid body.
Nested sampling-based optimization of representation.
Create a restraint between consecutive TempResidue objects or an entire PMI Molecule object...
Create movers and set up constraints for PMI objects.
A class to create an excluded volume restraint for a set of particles at a given resolution.
Automatically setup System and Degrees of Freedom with a formatted text file.
Restraints for handling cross-linking data.
Python classes to represent, score, sample and analyze models.
Functionality for loading, creating, manipulating and scoring atomic structures.
Select hierarchy particles identified by the biological name.
Definition: Selection.h:70
Support for the RMF file format for storing hierarchical molecular data and markup.