IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
pmi/em.py

This script shows how to create DENSITY representations and set up the Gaussian EM restraint.

These representations are useful when you are doing EM fitting with rigid bodies.

Preliminary step: you should convert your EM map to a GMM file with the command line utility create_gmm.py (located in isd/pyext/src/create_gmm.py):

python create_gmm.py emd_1883.mrc 50 emd_1883.gmm50.txt -m emd_1883.gmm50.mrc
## \example pmi/em.py
"""This script shows how to create DENSITY representations
and set up the Gaussian EM restraint.
These representations are useful when you are doing EM fitting with
rigid bodies.
Preliminary step: you should convert your EM map to a GMM file
with the command line utility create_gmm.py
(located in isd/pyext/src/create_gmm.py):
~~~
python create_gmm.py emd_1883.mrc 50 emd_1883.gmm50.txt -m emd_1883.gmm50.mrc
~~~
"""
import IMP
import IMP.atom
import IMP.rmf
import IMP.pmi
import sys
try:
import sklearn
except ImportError:
print("To run this example, please first install the 'sklearn'")
print("Python module.")
sys.exit(0)
IMP.setup_from_argv(sys.argv, "Set up the EM restraint")
# ##################### SYSTEM SETUP #####################
# Preliminaries
mdl = IMP.Model()
# Setup just one molecule
st = s.create_state()
mol = st.create_molecule("Rpn4", sequence=seqs["1WCM:D"], chain_id="D")
atomic_res = mol.add_structure(
IMP.pmi.get_example_path('data/1WCM_fitted.pdb'), chain_id="D", offset=0)
# Below we create a GMM approximation for this moleucle
# This "DENSITY" representation is used in the GaussianEMRestraint (and others
# in the future)
# For structure regions we "fit" GMM components to all atom centers
mol.add_representation(
atomic_res,
resolutions=[1, 10],
# how much to coarsen this representation
density_residues_per_component=10,
# will write a .txt and .mrc file forcomponent
density_prefix="Rpn4_gmm",
# set True if you want to overwrite
density_force_compute=False,
# set to 0 if you don't care about writing the map
# if rasterizing takes too long, increase this value
density_voxel_size=3.0)
# for the unstructured regions, we simply decorate each bead AS a Gaussian,
# so no fitting is necessary
mol.add_representation(mol.get_non_atomic_residues(),
resolutions=[10],
# just set this flag, nothing is written
setup_particles_as_densities=True)
hier = s.build()
# You can always check the representations with:
# ##################### RESTRAINTS #####################
output_objects = []
# To add the GaussianEMRestraint, first select all densities
densities = IMP.atom.Selection(
hier, representation_type=IMP.atom.DENSITIES).get_selected_particles()
densities,
# created by user, see top of file
target_fn=IMP.pmi.get_example_path('data/emd_1883.gmm50.txt'),
# a small number, helps drag bits into map
slope=0.01,
# if the model is the same size as map, usually set to True
scale_target_to_mass=False,
# manually set the mass of the target map (remove if you set above to True)
target_mass_scale=100000,
# the data weight
weight=100.0)
emr.add_to_model()
output_objects.append(emr)
mdl.update()
print(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.