IMP logo
IMP Reference Guide  2.7.0
The Integrative Modeling Platform
pmi/em.py
1 ## \example pmi/em.py
2 """This script shows how to create DENSITY representations.
3 and set up the Gaussian EM restraint.
4 
5 These representations are useful when you are doing EM fitting with rigid bodies.
6 
7 Preliminary step: you should convert your EM map to a GMM file
8 with the command line utility create_gmm.py (located in isd/pyext/src/create_gmm.py):
9 python create_gmm.py emd_1883.mrc 50 emd_1883.gmm50.txt -m emd_1883.gmm50.mrc
10 """
11 
12 import IMP
13 import RMF
14 import IMP.atom
15 import IMP.algebra
16 import IMP.rmf
17 import IMP.pmi
18 import IMP.pmi.topology
19 import IMP.pmi.dof
20 import IMP.pmi.macros
22 import tempfile
23 import os
24 import sys
25 
26 IMP.setup_from_argv(sys.argv, "Set up the EM restraint")
27 
28 ###################### SYSTEM SETUP #####################
29 # Preliminaries
30 mdl = IMP.Model()
32 
33 # Setup just one molecule
35 st = s.create_state()
36 mol = st.create_molecule("Rpn4",sequence=seqs["1WCM:D"],chain_id="D")
37 atomic_res = mol.add_structure(IMP.pmi.get_example_path('data/1WCM_fitted.pdb'),
38  chain_id="D",
39  offset=0)
40 
41 # Below we create a GMM approximation for this moleucle
42 # This "DENSITY" representation is used in the GaussianEMRestraint (and others in the future)
43 # For structure regions we "fit" GMM components to all atom centers
44 mol.add_representation(atomic_res,
45  resolutions=[1,10],
46  density_residues_per_component=10, #how much to coarsen this representation
47  density_prefix="Rpn4_gmm", # will write a .txt and .mrc file forcomponent
48  density_force_compute=False, # set True if you want to overwrite
49  density_voxel_size=3.0) # set to 0 if you don't care about writing the map
50  # if rasterizing takes too long, increase this value
51 
52 # for the unstructured regions, we simply decorate each bead AS a gaussian, so no fitting is necessary
53 mol.add_representation(mol.get_non_atomic_residues(),
54  resolutions=[10],
55  setup_particles_as_densities=True) # just set this flag, nothing is written
56 
57 hier = s.build()
58 
59 # You can always check the representations with:
61 
62 ###################### RESTRAINTS #####################
63 output_objects = []
64 
65 # To add the GaussianEMRestraint, first select all densities
66 densities = IMP.atom.Selection(hier,representation_type=IMP.atom.DENSITIES).get_selected_particles()
68  densities,
69  target_fn=IMP.pmi.get_example_path('data/emd_1883.gmm50.txt'), # created by user, see top of file
70  slope=0.01, # a small number, helps drag bits into map
71  scale_target_to_mass=False, # if the model is the same size as map, usually set to True
72  target_mass_scale=100000, # manually set the mass of the target map (remove if you set above to True)
73  weight=100.0) # the data weight
74 emr.add_to_model()
75 output_objects.append(emr)
76 mdl.update()
77 print(emr.evaluate())