1 """@namespace IMP.pmi.restraints.basic
2 Some miscellaneous simple restraints.
5 from __future__
import print_function
17 """Restraint to keep all structures inside sphere."""
19 def __init__(self, hierarchies, radius=10.0, resolution=10, weight=1.0,
20 center=
None, label=
None):
21 """Setup external barrier restraint.
22 @param radius Size of external barrier
23 @param hierarchies Can be one of the following inputs: IMP Hierarchy,
24 PMI System/State/Molecule/TempResidue, or a list/set of them
25 @param resolution Select which resolutions to act upon
26 @param weight Weight of restraint
27 @param center Center of the external barrier restraint
28 (IMP.algebra.Vector3D object)
29 @param label A unique label to be used in outputs and
30 particle/restraint names.
34 model = hiers[0].get_model()
35 particles = [h.get_particle()
for h
in hiers]
37 super(ExternalBarrier, self).
__init__(model, label=label,
43 elif type(center)
is IMP.algebra.Vector3D:
47 "%s: @param center must be an IMP.algebra.Vector3D object" % (
56 self.rs.add_restraint(r3)
61 """A simple distance restraint"""
63 def __init__(self, root_hier, tuple_selection1, tuple_selection2,
64 distancemin=0, distancemax=100, resolution=1.0, kappa=1.0,
65 label=
None, weight=1.):
66 """Setup distance restraint.
67 @param root_hier The hierarchy to select from
68 @param tuple_selection1 (resnum, resnum, molecule name, copy
70 @param tuple_selection2 (resnum, resnum, molecule name, copy
72 @param distancemin The minimum dist
73 @param distancemax The maximum dist
74 @param resolution For selecting particles
75 @param kappa The harmonic parameter
76 @param label A unique label to be used in outputs and
77 particle/restraint names
78 @param weight Weight of restraint
79 @note Pass the same resnum twice to each tuple_selection. Optionally
80 add a copy number (PMI2 only)
85 model = root_hier.get_model()
87 if len(tuple_selection1) > 3:
88 copy_num1 = tuple_selection1[3]
90 if len(tuple_selection2) > 3:
91 copy_num2 = tuple_selection2[3]
94 resolution=resolution,
95 molecule=tuple_selection1[2],
96 residue_index=tuple_selection1[0],
98 particles1 = sel1.get_selected_particles()
100 resolution=resolution,
101 molecule=tuple_selection2[2],
102 residue_index=tuple_selection2[0],
103 copy_index=copy_num2)
104 particles2 = sel2.get_selected_particles()
106 super(DistanceRestraint, self).
__init__(model, label=label,
110 print(
"Created distance restraint between "
111 "%s and %s" % (particles1[0].get_name(),
112 particles2[0].get_name()))
114 if len(particles1) > 1
or len(particles2) > 1:
115 raise ValueError(
"more than one particle selected")
117 self.rs.add_restraint(
121 self.rs.add_restraint(
129 PMI2 python restraint. Restrains particles within a
130 Cylinder aligned along the z-axis and
132 Optionally, one can restrain the cylindrical angle
136 def __init__(self, m, objects, resolution, radius, mintheta=None,
137 maxtheta=
None, repulsive=
False, label=
'None'):
139 @param objects PMI2 objects
140 @param resolution the resolution you want the restraint to be applied
141 @param radius the radius of the cylinder
142 @param mintheta minimum cylindrical angle in degrees
143 @param maxtheta maximum cylindrical angle in degrees
145 IMP.Restraint.__init__(self, m,
"CylinderRestraint %1%")
148 self.softness_angle = 0.5
152 self.mintheta = mintheta
153 self.maxtheta = maxtheta
154 self.repulsive = repulsive
158 self.particles = [h.get_particle()
for h
in hierarchies]
161 def get_probability(self, p):
163 r = self.math.sqrt(xyz.get_x()**2+xyz.get_y()**2)
164 argvalue = (r-self.radius) / self.softness
167 prob = (1.0 - self.plateau) / (1.0 + self.math.exp(-argvalue))
170 def get_angle_probability(self, p):
172 angle = self.math.atan2(xyz.get_y(), xyz.get_x())*180.0/self.math.pi
173 anglediff = (angle - self.maxtheta + 180 + 360) % 360 - 180
174 argvalue1 = anglediff / self.softness_angle
175 anglediff = (angle - self.mintheta + 180 + 360) % 360 - 180
176 argvalue2 = -anglediff / self.softness_angle
177 prob = ((1.0-self.plateau)
178 / (1.0 + self.math.exp(-max(argvalue1, argvalue2))))
181 def unprotected_evaluate(self, da):
183 for p
in self.particles:
184 s += -self.math.log(1.0-self.get_probability(p))
185 if self.mintheta
is not None and self.maxtheta
is not None:
186 s += -self.math.log(1.0-self.get_angle_probability(p))
190 return self.particles
192 def add_to_model(self):
195 def get_output(self):
197 score = self.weight * self.unprotected_evaluate(
None)
198 output[
"_TotalScore"] = str(score)
199 output[
"CylinderRestraint_" + self.label] = str(score)
205 a python restraint with bistable potential
206 Authors: G. Bouvier, R. Pellarin. Pasteur Institute.
211 def __init__(self, m, p1, p2, dist1, dist2, sigma1, sigma2, weight1,
214 input twp oarticles, the two equilibrium distances, their amplitudes,
215 and their weights (populations)
217 IMP.Restraint.__init__(self, m,
"BiStableDistanceRestraint %1%")
224 self.weight1 = weight1
225 self.weight2 = weight2
227 if self.weight1+self.weight2 != 1:
228 raise ValueError(
"The sum of the weights must be one")
232 self.particle_list = [p1, p2]
234 def gaussian(self, x, mu, sig, w):
235 return (w*self.np.exp(-self.np.power(x - mu, 2.)
236 / (2 * self.np.power(sig, 2.))))
238 def unprotected_evaluate(self, da):
240 prob = self.gaussian(dist, self.dist1, self.sigma1, self.weight1) + \
241 self.gaussian(dist, self.dist2, self.sigma2, self.weight2)
242 return -self.math.log(prob)
245 return self.particle_list
250 """Restraint for anchoring a particle to a specific coordinate."""
252 def __init__(self, root_hier, tuple_selection,
254 radius=10.0, kappa=10.0, resolution=1.0, weight=1.0,
256 """Setup distance restraint.
257 @param root_hier The hierarchy to select from
258 @param tuple_selection (resnum, resnum, molecule name,
260 @param anchor_point Point to which to restrain particle
261 (IMP.algebra.Vector3D object)
262 @param radius Size of the tolerance length
263 @param kappa The harmonic parameter
264 @param resolution For selecting a particle
265 @param weight Weight of restraint
266 @param label A unique label to be used in outputs and
267 particle/restraint names
268 @note Pass the same resnum twice to each tuple_selection. Optionally
269 add a copy number (PMI2 only)
271 model = root_hier.get_model()
273 if len(tuple_selection) > 3:
274 copy_num1 = tuple_selection[3]
277 resolution=resolution,
278 molecule=tuple_selection[2],
279 residue_index=tuple_selection[0],
280 copy_index=copy_num1)
281 ps = sel1.get_selected_particles()
283 raise ValueError(
"More than one particle selected")
285 super(DistanceToPointRestraint, self).
__init__(model, label=label,
290 if anchor_point
is None:
292 elif isinstance(anchor_point, IMP.algebra.Vector3D):
295 raise TypeError(
"anchor_point must be an algebra.Vector3D object")
302 self.rs.add_restraint(r3)
304 print(
"\n%s: Created distance_to_point_restraint between "
305 "%s and %s" % (self.name, ps[0].get_name(), c3))
309 def __init__(self, hier, objects_above=None, objects_inside=None,
310 objects_below=
None, center=0.0, thickness=30.0,
311 softness=3.0, plateau=0.0000000001, resolution=1,
312 weight=1.0, label=
None):
313 """ Setup Membrane restraint
315 Simple sigmoid score calculated for particles above,
317 @param objects_inside list or tuples of objects in membrane
318 (e.g. ['p1', (10, 30,'p2')])
319 @param objects_above list or tuples of objects above membrane
320 @param objects_below list or tuples of objects below membrane
321 @param thickness Thickness of the membrane along the z-axis
322 @param softness Softness of the limiter in the sigmoid function
323 @param plateau Parameter to set the probability (=1- plateau))
324 at the plateau phase of the sigmoid
325 @param weight Weight of restraint
326 @param label A unique label to be used in outputs and
327 particle/restraint names.
328 input a list of particles, the slope and theta of the sigmoid potential
329 theta is the cutoff distance for a protein-protein contact
333 model = self.hier.get_model()
335 super(MembraneRestraint, self).
__init__(
336 model, name=
"MembraneRestraint", label=label, weight=weight)
339 self.thickness = thickness
340 self.softness = softness
341 self.plateau = plateau
343 self.resolution = resolution
348 z_center.set_nuisance(self.center)
352 z_center.get_particle_index(),
360 for obj
in objects_above:
361 if isinstance(obj, tuple):
362 self.particles_above = self._select_from_tuple(obj)
364 elif isinstance(obj, str):
365 self.particles_above = self._select_from_string(obj)
366 mr.add_particles_above(self.particles_above)
370 for obj
in objects_inside:
371 if isinstance(obj, tuple):
372 self.particles_inside = self._select_from_tuple(obj)
374 elif isinstance(obj, str):
375 self.particles_inside = self._select_from_string(obj)
376 mr.add_particles_inside(self.particles_inside)
380 for obj
in objects_below:
381 if isinstance(obj, tuple):
382 self.particles_below = self._select_from_tuple(obj)
384 elif isinstance(obj, str):
385 self.particles_below = self._select_from_string(obj)
386 mr.add_particles_below(self.particles_below)
388 self.rs.add_restraint(mr)
390 def get_particles_above(self):
391 return self.particles_above
393 def get_particles_inside(self):
394 return self.particles_inside
396 def get_particles_below(self):
397 return self.particles_below
399 def _select_from_tuple(self, obj):
401 self.hier, molecule=obj[2],
402 residue_indexes=range(obj[0], obj[1]+1, 1),
403 resolution=self.resolution).get_selected_particles()
407 def _select_from_string(self, obj):
409 self.hier, molecule=obj,
410 resolution=self.resolution).get_selected_particles()
413 def create_membrane_density(self, file_out='membrane_localization.mrc'):
416 Just for visualization purposes.
417 Writes density of membrane localization
420 offset = 5.0 * self.thickness
427 -self.center - offset),
429 self.center + offset))
431 dheader.set_resolution(resolution)
434 for vox
in range(dmap.get_header().get_number_of_voxels()):
435 c = dmap.get_location_by_voxel(vox)
436 if self._is_membrane(c[2]) == 1:
437 dmap.set_value(c[0], c[1], c[2], 1.0)
439 dmap.set_value(c[0], c[1], c[2], 0.0)
441 IMP.em.write_map(dmap, file_out)
443 def _is_membrane(self, z):
444 if ((z-self.center) < self.thickness/2.0
and
445 (z-self.center) >= -self.thickness/2.0):
Applies a SingletonScore to each Singleton in a list.
static Nuisance setup_particle(Model *m, ParticleIndex pi)
def __init__
Setup distance restraint.
A simple distance restraint.
Lower bound harmonic function (non-zero when feature < mean)
Various classes to hold sets of particles.
Upper bound harmonic function (non-zero when feature > mean)
Distance restraint between two particles.
double get_distance(XYZR a, XYZR b)
Compute the sphere distance between a and b.
Classes to handle different kinds of restraints.
def __init__
input twp oarticles, the two equilibrium distances, their amplitudes, and their weights (populations)...
Class for sampling a density map from particles.
def __init__
Setup external barrier restraint.
Store a list of ParticleIndexes.
Restraint for anchoring a particle to a specific coordinate.
DensityHeader create_density_header(const algebra::BoundingBoxD< 3 > &bb, float spacing)
Create a header from a bounding box in 3D.
Apply a function to the distance to a fixed point.
A decorator for a particle with x,y,z coordinates.
Restraint to keep all structures inside sphere.
def __init__
Setup distance restraint.
Basic functionality that is expected to be used by a wide variety of IMP users.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
The general base class for IMP exceptions.
Class to handle individual particles of a Model object.
Functionality for loading, creating, manipulating and scoring atomic structures.
a python restraint with bistable potential Authors: G.
Select hierarchy particles identified by the biological name.
virtual ModelObjectsTemp do_get_inputs() const =0
A restraint is a term in an IMP ScoringFunction.