IMP logo
IMP Reference Guide  2.20.0
The Integrative Modeling Platform
restraints.py
1 """@namespace IMP.EMageFit.restraints
2  Utility functions to handle restraints.
3 """
4 
5 import IMP
6 import IMP.core as core
7 import IMP.container as container
8 import IMP.em2d as em2d
9 import IMP.atom as atom
10 
11 import logging
12 
13 log = logging.getLogger("restraints")
14 
15 
16 def get_connectivity_restraint(particles, distance=10.,
17  n_pairs=1, spring_constant=1):
18  """
19  Set a connectivity restraint for the leaves of a set of particles
20 
21  The intended use is that the each particle is a hierarchy. Each
22  hierarchy contains leaves that are atoms, or particles
23  that are a coarse representation of a molecule
24  """
26  spring_constant)
28  # score based on the one pair (the closest leaves)
29  pair_score = IMP.core.KClosePairsPairScore(score, refiner, n_pairs)
30  cr = IMP.core.ConnectivityRestraint(pair_score)
31  cr.set_particles(particles)
32  return cr
33 
34 
35 def get_em2d_restraint(assembly,
36  images_selection_file,
37  restraint_params,
38  mode="fast",
39  n_optimized=1):
40  """ Sets a restraint for comparing the model to a set of EM images
41  """
42  model = assembly.get_model()
43  # Setup the restraint
44  sc = em2d.EM2DScore()
45  r = em2d.Em2DRestraint(model)
46  r.setup(sc, restraint_params)
47  names = em2d.read_selection_file(images_selection_file)
48  names = [IMP.get_relative_path(images_selection_file, x) for x in names]
49  log.debug("names of the images %s", names)
51  imgs = em2d.read_images(names, srw)
52  r.set_images(imgs)
53 
54  ps = atom.get_leaves(assembly)
56  r.set_particles(lsc)
57 
58  if mode == "coarse":
59  r.set_coarse_registration_mode(True)
60  elif mode == "fast":
61  r.set_fast_mode(n_optimized)
62  elif mode == "complete":
63  pass
64  else:
65  raise ValueError("Em2DRestraint mode not recognized")
66  return r
A harmonic upper bound on the distance between two spheres.
def get_connectivity_restraint
Set a connectivity restraint for the leaves of a set of particles.
Definition: restraints.py:16
Apply a score to a fixed number of close pairs from the two sets.
Restraints using electron microscopy 2D images (class averages).
Return the hierarchy leaves under a particle.
Definition: LeavesRefiner.h:25
Various classes to hold sets of particles.
ParticleIndexPairs get_indexes(const ParticlePairsTemp &ps)
Get the indexes from a list of particle pairs.
Store a list of ParticleIndexes.
Ensure that a set of particles remains connected with one another.
std::string get_relative_path(std::string base, std::string relative)
Return a path to a file relative to another file.
static const IMP::core::HierarchyTraits & get_traits()
Get the molecular hierarchy HierarchyTraits.
Basic functionality that is expected to be used by a wide variety of IMP users.
def get_em2d_restraint
Sets a restraint for comparing the model to a set of EM images.
Definition: restraints.py:35
Functionality for loading, creating, manipulating and scoring atomic structures.