IMP  2.3.1
The Integrative Modeling Platform
restraints.py
1 """@namespace IMP.em2d.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.em2d.imp_general.representation as representation
11 import IMP.atom as atom
12 import IMP.base as base
13 import os
14 
15 import logging
16 
17 log = logging.getLogger("restraints")
18 
19 
20 def get_connectivity_restraint(particles, distance=10.,
21  n_pairs=1, spring_constant=1):
22  """
23  Set a connectivity restraint for the leaves of a set of particles
24 
25  The intended use is that the each particle is a hierarchy. Each
26  hierarchy contains leaves that are atoms, or particles
27  that are a coarse representation of a molecule
28  """
30  spring_constant)
32  # score based on the one pair (the closest leaves)
33  pair_score = IMP.core.KClosePairsPairScore(score, refiner, n_pairs)
34  cr = IMP.core.ConnectivityRestraint(pair_score)
35  cr.set_particles(particles)
36  return cr
37 
38 
39 def get_em2d_restraint(assembly,
40  images_selection_file,
41  restraint_params,
42  mode="fast",
43  n_optimized=1):
44  """ Sets a restraint for comparing the model to a set of EM images
45  """
46  model = assembly.get_model()
47  # Setup the restraint
48  sc = em2d.EM2DScore()
49  r = em2d.Em2DRestraint(model)
50  r.setup(sc, restraint_params)
51  names = em2d.read_selection_file(images_selection_file)
52  names = [base.get_relative_path(images_selection_file, x) for x in names]
53  log.debug("names of the images %s", names)
55  imgs = em2d.read_images(names, srw)
56  r.set_images(imgs)
57 
58  ps = atom.get_leaves(assembly)
60  r.set_particles(lsc)
61 
62  if (mode == "coarse"):
63  r.set_coarse_registration_mode(True)
64  elif (mode == "fast"):
65  r.set_fast_mode(n_optimized)
66  elif(mode == "complete"):
67  pass
68  else:
69  raise ValueError("Em2DRestraint mode not recognized")
70  return r
A harmonic upper bound on the distance between two spheres.
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.
Low level functionality (logging, error handling, profiling, command line flags etc) that is used by ...
Store a kernel::ParticleIndexes.
Ensure that a set of particles remains connected with one another.
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_connectivity_restraint
Set a connectivity restraint for the leaves of a set of particles.
Definition: restraints.py:20
Functionality for loading, creating, manipulating and scoring atomic structures.
Divide-and-conquer inferential optimization in discrete space.
def get_em2d_restraint
Sets a restraint for comparing the model to a set of EM images.
Definition: restraints.py:39