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."""
27 """Setup external barrier restraint.
28 @param representation DEPRECATED
29 @param radius Size of external barrier
30 @param hierarchies Can be one of the following inputs: IMP Hierarchy,
31 PMI System/State/Molecule/TempResidue, or a list/set of them
32 @param resolution Select which resolutions to act upon
33 @param weight Weight of restraint
34 @param center Center of the external barrier restraint
35 (IMP.algebra.Vector3D object)
36 @param label A unique label to be used in outputs and
37 particle/restraint names.
40 model = representation.prot.get_model()
43 resolution=resolution,
44 hierarchies=hierarchies)
48 model = hiers[0].get_model()
49 particles = [h.get_particle()
for h
in hiers]
51 raise Exception(
"%s: must pass representation or hierarchies" % (
54 super(ExternalBarrier, self).
__init__(model, label=label,
60 elif type(center)
is IMP.algebra.Vector3D:
64 "%s: @param center must be an IMP.algebra.Vector3D object" % (
73 self.rs.add_restraint(r3)
78 """A simple distance restraint"""
82 tuple_selection1=
None,
83 tuple_selection2=
None,
91 """Setup distance restraint.
92 @param representation DEPRECATED
93 @param tuple_selection1 (resnum, resnum, molecule name, copy
95 @param tuple_selection2 (resnum, resnum, molecule name, copy
97 @param distancemin The minimum dist
98 @param distancemax The maximum dist
99 @param resolution For selecting particles
100 @param kappa The harmonic parameter
101 @param root_hier The hierarchy to select from (use this instead of
103 @param label A unique label to be used in outputs and
104 particle/restraint names
105 @param weight Weight of restraint
106 @note Pass the same resnum twice to each tuple_selection. Optionally
107 add a copy number (PMI2 only)
109 if tuple_selection1
is None or tuple_selection2
is None:
110 raise Exception(
"You must pass tuple_selection1/2")
114 if representation
and not root_hier:
115 model = representation.prot.get_model()
117 resolution=resolution,
118 name=tuple_selection1[2],
119 residue=tuple_selection1[0])
121 resolution=resolution,
122 name=tuple_selection2[2],
123 residue=tuple_selection2[0])
124 elif root_hier
and not representation:
125 model = root_hier.get_model()
127 if len(tuple_selection1) > 3:
128 copy_num1 = tuple_selection1[3]
130 if len(tuple_selection2) > 3:
131 copy_num2 = tuple_selection2[3]
134 resolution=resolution,
135 molecule=tuple_selection1[2],
136 residue_index=tuple_selection1[0],
137 copy_index=copy_num1)
138 particles1 = sel1.get_selected_particles()
140 resolution=resolution,
141 molecule=tuple_selection2[2],
142 residue_index=tuple_selection2[0],
143 copy_index=copy_num2)
144 particles2 = sel2.get_selected_particles()
146 raise Exception(
"Pass representation or root_hier, not both")
148 super(DistanceRestraint, self).
__init__(model, label=label,
152 print(
"Created distance restraint between "
153 "%s and %s" % (particles1[0].get_name(),
154 particles2[0].get_name()))
156 if len(particles1) > 1
or len(particles2) > 1:
157 raise ValueError(
"more than one particle selected")
159 self.rs.add_restraint(
163 self.rs.add_restraint(
171 PMI2 python restraint. Restrains particles within a
172 Cylinder aligned along the z-axis and
174 Optionally, one can restrain the cylindrical angle
177 def __init__(self, m, objects, resolution, radius,mintheta=None,
178 maxtheta=
None,repulsive=
False,label=
'None'):
180 @param objects PMI2 objects
181 @param resolution the resolution you want the restraint to be applied
182 @param radius the radius of the cylinder
183 @param mintheta minimum cylindrical angle in degrees
184 @param maxtheta maximum cylindrical angle in degrees
186 IMP.Restraint.__init__(self, m,
"CylinderRestraint %1%")
189 self.softness_angle = 0.5
193 self.mintheta=mintheta
194 self.maxtheta=maxtheta
195 self.repulsive=repulsive
199 self.particles = [h.get_particle()
for h
in hierarchies]
202 def get_probability(self,p):
204 r=self.math.sqrt(xyz.get_x()**2+xyz.get_y()**2)
205 argvalue=(r-self.radius) / self.softness
206 if self.repulsive: argvalue=-argvalue
207 prob = (1.0 - self.plateau) / (1.0 + self.math.exp(-argvalue))
210 def get_angle_probability(self,p):
212 angle=self.math.atan2(xyz.get_y(),xyz.get_x() )*180.0/self.math.pi
213 anglediff = (angle - self.maxtheta + 180 + 360) % 360 - 180
214 argvalue1=anglediff / self.softness_angle
215 anglediff = (angle - self.mintheta + 180 + 360) % 360 - 180
216 argvalue2=-anglediff / self.softness_angle
217 prob = (1.0-self.plateau) / (1.0 + self.math.exp(-max(argvalue1,argvalue2)))
220 def unprotected_evaluate(self, da):
222 for p
in self.particles:
223 s+=-self.math.log(1.0-self.get_probability(p))
224 if self.mintheta
is not None and self.maxtheta
is not None:
225 s+=-self.math.log(1.0-self.get_angle_probability(p))
229 return self.particles
231 def add_to_model(self):
234 def get_output(self):
236 score = self.weight * self.unprotected_evaluate(
None)
237 output[
"_TotalScore"] = str(score)
238 output[
"CylinderRestraint_" + self.label] = str(score)
245 a python restraint with bistable potential
246 Authors: G. Bouvier, R. Pellarin. Pasteur Institute.
251 def __init__(self,m,p1,p2,dist1,dist2,sigma1,sigma2,weight1,weight2):
253 input twp particles, the two equilibrium distances, their amplitudes, and their weights (populations)
255 IMP.Restraint.__init__(self, m,
"BiStableDistanceRestraint %1%")
265 if self.weight1+self.weight2 != 1:
266 raise ValueError(
"The sum of the weights must be one")
270 self.particle_list=[p1,p2]
272 def gaussian(self,x, mu, sig, w):
273 return w*self.np.exp(-self.np.power(x - mu, 2.) / (2 * self.np.power(sig, 2.)))
275 def unprotected_evaluate(self,da):
277 prob=self.gaussian(dist,self.dist1,self.sigma1,self.weight1)+\
278 self.gaussian(dist,self.dist2,self.sigma2,self.weight2)
279 return -self.math.log(prob)
282 return self.particle_list
287 """Restraint for anchoring a particle to a specific coordinate."""
291 tuple_selection=
None,
299 """Setup distance restraint.
300 @param representation DEPRECATED
301 @param tuple_selection (resnum, resnum, molecule name,
303 @param anchor_point Point to which to restrain particle
304 (IMP.algebra.Vector3D object)
305 @param radius Size of the tolerance length
306 @param kappa The harmonic parameter
307 @param resolution For selecting a particle
308 @param weight Weight of restraint
309 @param root_hier The hierarchy to select from (use this instead of
311 @param label A unique label to be used in outputs and
312 particle/restraint names
313 @note Pass the same resnum twice to each tuple_selection. Optionally
314 add a copy number (PMI2 only)
316 if tuple_selection
is None:
317 raise ValueError(
"You must pass a tuple_selection")
319 if representation
and not root_hier:
320 model = representation.prot.get_model()
322 resolution=resolution,
323 name=tuple_selection[2],
324 residue=tuple_selection[0])
325 elif root_hier
and not representation:
326 model = root_hier.get_model()
328 if len(tuple_selection) > 3:
329 copy_num1 = tuple_selection[3]
332 resolution=resolution,
333 molecule=tuple_selection[2],
334 residue_index=tuple_selection[0],
335 copy_index=copy_num1)
336 ps = sel1.get_selected_particles()
338 raise ValueError(
"Pass representation or root_hier, not both")
340 raise ValueError(
"More than one particle selected")
342 super(DistanceToPointRestraint, self).
__init__(model, label=label,
347 if anchor_point
is None:
349 elif isinstance(anchor_point, IMP.algebra.Vector3D):
352 raise TypeError(
"anchor_point must be an algebra.Vector3D object")
359 self.rs.add_restraint(r3)
361 print(
"\n%s: Created distance_to_point_restraint between "
362 "%s and %s" % (self.name, ps[0].get_name(), c3))
373 plateau=0.0000000001,
377 """ Setup Membrane restraint
379 Simple sigmoid score calculated for particles above,
381 @param objects_inside list or tuples of objects in membrane (e.g. ['p1', (10, 30,'p2')])
382 @param objects_above list or tuples of objects above membrane
383 @param objects_below list or tuples of objects below membrane
384 @param thickness Thickness of the membrane along the z-axis
385 @param softness Softness of the limiter in the sigmoid function
386 @param plateau Parameter to set the probability (=1- plateau)) at the plateau
388 @param weight Weight of restraint
389 @param label A unique label to be used in outputs and
390 particle/restraint names.
391 input a list of particles, the slope and theta of the sigmoid potential
392 theta is the cutoff distance for a protein-protein contact
396 model = self.hier.get_model()
398 rname =
"MembraneRestraint"
399 super(MembraneRestraint, self).
__init__(
400 model, name=
"MembraneRestraint", label=label, weight=weight)
403 self.thickness = thickness
404 self.softness = softness
405 self.plateau = plateau
407 self.resolution = resolution
412 z_center.set_nuisance(self.center)
416 z_center.get_particle_index(),
424 for obj
in objects_above:
425 if isinstance(obj, tuple):
426 self.particles_above = self._select_from_tuple(obj)
428 elif isinstance(obj, str):
429 self.particles_above = self._select_from_string(obj)
430 mr.add_particles_above(self.particles_above)
434 for obj
in objects_inside:
435 if isinstance(obj, tuple):
436 self.particles_inside = self._select_from_tuple(obj)
438 elif isinstance(obj, str):
439 self.particles_inside = self._select_from_string(obj)
440 mr.add_particles_inside(self.particles_inside)
445 for obj
in objects_below:
446 if isinstance(obj, tuple):
447 self.particles_below = self._select_from_tuple(obj)
449 elif isinstance(obj, str):
450 self.particles_below = self._select_from_string(obj)
451 mr.add_particles_below(self.particles_below)
454 self.rs.add_restraint(mr)
456 def get_particles_above(self):
457 return self.particles_above
459 def get_particles_inside(self):
460 return self.particles_inside
462 def get_particles_below(self):
463 return self.particles_below
465 def _select_from_tuple(self, obj):
468 residue_indexes = range(obj[0], obj[1]+1, 1),
469 resolution = self.resolution).get_selected_particles()
473 def _select_from_string(self, obj):
476 resolution = self.resolution).get_selected_particles()
479 def create_membrane_density(self, file_out='membrane_localization.mrc'):
482 Just for visualization purposes.
483 Writes density of membrane localization
486 offset = 5.0*self.thickness
495 dheader.set_resolution(resolution)
498 for vox
in range(dmap.get_header().get_number_of_voxels()):
499 c = dmap.get_location_by_voxel(vox)
500 if self._is_membrane(c[2])==1:
501 dmap.set_value(c[0], c[1], c[2], 1.0)
503 dmap.set_value(c[0], c[1], c[2], 0.0)
505 IMP.em.write_map(dmap, file_out)
507 def _is_membrane(self, z):
508 if (z-self.center) < self.thickness/2.0
and (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 particles, 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
Base class for PMI restraints, which wrap IMP.Restraint(s).
A restraint is a term in an IMP ScoringFunction.