IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
doc/examples/pmi/em.py
1## \example pmi/em.py
2"""This script shows how to create DENSITY representations
3and set up the Gaussian EM restraint.
4
5These representations are useful when you are doing EM fitting with
6rigid bodies.
7
8Preliminary step: you should convert your EM map to a GMM file
9with the command line utility create_gmm.py
10(located in isd/pyext/src/create_gmm.py):
11
12~~~
13python create_gmm.py emd_1883.mrc 50 emd_1883.gmm50.txt -m emd_1883.gmm50.mrc
14~~~
15"""
16
17import IMP
18import IMP.atom
19import IMP.algebra
20import IMP.rmf
21import IMP.pmi
23import IMP.pmi.dof
24import IMP.pmi.macros
26import sys
27try:
28 import sklearn
29except ImportError:
30 print("To run this example, please first install the 'sklearn'")
31 print("Python module.")
32 sys.exit(0)
33
34IMP.setup_from_argv(sys.argv, "Set up the EM restraint")
35
36# ##################### SYSTEM SETUP #####################
37# Preliminaries
38mdl = IMP.Model()
40
41# Setup just one molecule
43st = s.create_state()
44mol = st.create_molecule("Rpn4", sequence=seqs["1WCM:D"], chain_id="D")
45atomic_res = mol.add_structure(
46 IMP.pmi.get_example_path('data/1WCM_fitted.pdb'), chain_id="D", offset=0)
47
48# Below we create a GMM approximation for this moleucle
49# This "DENSITY" representation is used in the GaussianEMRestraint (and others
50# in the future)
51# For structure regions we "fit" GMM components to all atom centers
52mol.add_representation(
53 atomic_res,
54 resolutions=[1, 10],
55 # how much to coarsen this representation
56 density_residues_per_component=10,
57 # will write a .txt and .mrc file forcomponent
58 density_prefix="Rpn4_gmm",
59 # set True if you want to overwrite
60 density_force_compute=False,
61 # set to 0 if you don't care about writing the map
62 # if rasterizing takes too long, increase this value
63 density_voxel_size=3.0)
64
65# for the unstructured regions, we simply decorate each bead AS a Gaussian,
66# so no fitting is necessary
67mol.add_representation(mol.get_non_atomic_residues(),
68 resolutions=[10],
69 # just set this flag, nothing is written
70 setup_particles_as_densities=True)
71
72hier = s.build()
73
74# You can always check the representations with:
76
77# ##################### RESTRAINTS #####################
78output_objects = []
79
80# To add the GaussianEMRestraint, first select all densities
81densities = IMP.atom.Selection(
82 hier, representation_type=IMP.atom.DENSITIES).get_selected_particles()
84 densities,
85 # created by user, see top of file
86 target_fn=IMP.pmi.get_example_path('data/emd_1883.gmm50.txt'),
87 # a small number, helps drag bits into map
88 slope=0.01,
89 # if the model is the same size as map, usually set to True
90 scale_target_to_mass=False,
91 # manually set the mass of the target map (remove if you set above to True)
92 target_mass_scale=100000,
93 # the data weight
94 weight=100.0)
95emr.add_to_model()
96output_objects.append(emr)
97mdl.update()
98print(emr.evaluate())
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Select hierarchy particles identified by the biological name.
Definition Selection.h:76
Fit Gaussian-decorated particles to an EM map (also represented with a set of Gaussians).
A dictionary-like wrapper for reading and storing sequence data.
Represent the root node of the global IMP.atom.Hierarchy.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
Functionality for loading, creating, manipulating and scoring atomic structures.
void show_with_representations(Hierarchy h, std::ostream &out=std::cout)
Traverse through the tree and show atom info, including representations.
Create movers and set up constraints for PMI objects.
Protocols for sampling structures and analyzing them.
Definition macros.py:1
Restraints for handling electron microscopy maps.
Set of Python classes to create a multi-state, multi-resolution IMP hierarchy.
Python classes to represent, score, sample and analyze models.
std::string get_example_path(std::string file_name)
Return the full path to one of this module's example files.
Support for the RMF file format for storing hierarchical molecular data and markup.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.