IMP logo
IMP Reference Guide  2.10.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.domino as domino
8 import IMP.container as container
9 import IMP.em2d as em2d
10 import IMP.EMageFit.imp_general.representation as representation
11 import IMP.atom as atom
12 import os
13 
14 import logging
15 
16 log = logging.getLogger("restraints")
17 
18 
19 def get_connectivity_restraint(particles, distance=10.,
20  n_pairs=1, spring_constant=1):
21  """
22  Set a connectivity restraint for the leaves of a set of particles
23 
24  The intended use is that the each particle is a hierarchy. Each
25  hierarchy contains leaves that are atoms, or particles
26  that are a coarse representation of a molecule
27  """
29  spring_constant)
31  # score based on the one pair (the closest leaves)
32  pair_score = IMP.core.KClosePairsPairScore(score, refiner, n_pairs)
33  cr = IMP.core.ConnectivityRestraint(pair_score)
34  cr.set_particles(particles)
35  return cr
36 
37 
38 def get_em2d_restraint(assembly,
39  images_selection_file,
40  restraint_params,
41  mode="fast",
42  n_optimized=1):
43  """ Sets a restraint for comparing the model to a set of EM images
44  """
45  model = assembly.get_model()
46  # Setup the restraint
47  sc = em2d.EM2DScore()
48  r = em2d.Em2DRestraint(model)
49  r.setup(sc, restraint_params)
50  names = em2d.read_selection_file(images_selection_file)
51  names = [IMP.get_relative_path(images_selection_file, x) for x in names]
52  log.debug("names of the images %s", names)
54  imgs = em2d.read_images(names, srw)
55  r.set_images(imgs)
56 
57  ps = atom.get_leaves(assembly)
59  r.set_particles(lsc)
60 
61  if (mode == "coarse"):
62  r.set_coarse_registration_mode(True)
63  elif (mode == "fast"):
64  r.set_fast_mode(n_optimized)
65  elif(mode == "complete"):
66  pass
67  else:
68  raise ValueError("Em2DRestraint mode not recognized")
69  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:19
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.
Utility functions to handle representation.
ParticleIndexPairs get_indexes(const ParticlePairsTemp &ps)
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:38
Functionality for loading, creating, manipulating and scoring atomic structures.
Divide-and-conquer inferential optimization in discrete space.