IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
fit_restraint.py
1## \example em/fit_restraint.py
2# A simple example showing how to set up a fit restraint. The number of
3# spheres and resolution are randomly chosen and so should not be
4# considered significant.
5
6import IMP.em
7import IMP.core
8import IMP.atom
9import sys
10
11IMP.setup_from_argv(sys.argv, "fit restraint")
12
13IMP.set_log_level(IMP.SILENT)
14m = IMP.Model()
15# 1. setup the input protein
16# 1.1 select a selector.
18# 1.2 read the protein
19mh = IMP.atom.read_pdb(IMP.em.get_example_path("input.pdb"), m, sel)
22# 2. read the density map
23resolution = 8.
24voxel_size = 1.5
25dmap = IMP.em.read_map(
27dmap.get_header_writable().set_resolution(resolution)
28# 3. calculate the cross correlation between the density and the map
29print("The cross-correlation score is:",
30 1. - IMP.em.compute_fitting_score(ps, dmap))
31# 4. add a fitting restraint
32r = IMP.em.FitRestraint(ps, dmap)
33print("The fit of the particles in the density is:", r.evaluate(False))
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Select all non-water non-alternative ATOM and HETATM records.
Definition pdb.h:362
DensityMap * read_map(std::string filename, MapReaderWriter *reader)
Read a density map from a file (using the given reader) and return it.
Calculate score based on fit to EM map.
Functionality for loading, creating, manipulating and scoring atomic structures.
void add_radii(Hierarchy d, const ForceFieldParameters *ffp=get_all_atom_CHARMM_parameters(), FloatKey radius_key=FloatKey("radius"))
Add vdW radius from given force field.
Hierarchy read_pdb(TextInput input, Model *model, PDBSelector *selector=get_default_pdb_selector(), bool select_first_model=true)
Read all the molecules in the first model of the PDB file.
Basic functionality that is expected to be used by a wide variety of IMP users.
GenericHierarchies get_leaves(Hierarchy mhd)
Get all the leaves of the bit of hierarchy.
Basic utilities for handling cryo-electron microscopy 3D density maps.
Float compute_fitting_score(const ParticlesTemp &ps, DensityMap *em_map, FloatKey wei_key=atom::Mass::get_mass_key())
Compute fitting scores for a given set of rigid transformations.
std::string get_example_path(std::string file_name)
Return the full path to one of this module's example files.
void set_log_level(LogLevel l)
Set the current global log level.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.