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 m = representation.prot.get_model()
43 resolution=resolution,
44 hierarchies=hierarchies)
48 m = 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__(m, label=label, weight=weight)
59 elif type(center)
is IMP.algebra.Vector3D:
63 "%s: @param center must be an IMP.algebra.Vector3D object" % (
72 self.rs.add_restraint(r3)
77 """A simple distance restraint"""
81 tuple_selection1=
None,
82 tuple_selection2=
None,
90 """Setup distance restraint.
91 @param representation DEPRECATED
92 @param tuple_selection1 (resnum, resnum, molecule name, copy
94 @param tuple_selection2 (resnum, resnum, molecule name, copy
96 @param distancemin The minimum dist
97 @param distancemax The maximum dist
98 @param resolution For selecting particles
99 @param kappa The harmonic parameter
100 @param root_hier The hierarchy to select from (use this instead of
102 @param label A unique label to be used in outputs and
103 particle/restraint names
104 @param weight Weight of restraint
105 \note Pass the same resnum twice to each tuple_selection. Optionally
106 add a copy number (PMI2 only)
108 if tuple_selection1
is None or tuple_selection2
is None:
109 raise Exception(
"You must pass tuple_selection1/2")
113 if representation
and not root_hier:
114 m = representation.prot.get_model()
116 resolution=resolution,
117 name=tuple_selection1[2],
118 residue=tuple_selection1[0])
120 resolution=resolution,
121 name=tuple_selection2[2],
122 residue=tuple_selection2[0])
123 elif root_hier
and not representation:
124 m = root_hier.get_model()
126 if len(tuple_selection1) > 3:
127 copy_num1 = tuple_selection1[3]
129 if len(tuple_selection2) > 3:
130 copy_num2 = tuple_selection2[3]
133 resolution=resolution,
134 molecule=tuple_selection1[2],
135 residue_index=tuple_selection1[0],
136 copy_index=copy_num1)
137 particles1 = sel1.get_selected_particles()
139 resolution=resolution,
140 molecule=tuple_selection2[2],
141 residue_index=tuple_selection2[0],
142 copy_index=copy_num2)
143 particles2 = sel2.get_selected_particles()
145 raise Exception(
"Pass representation or root_hier, not both")
147 super(DistanceRestraint, self).
__init__(m, label=label, weight=weight)
150 print(
"Created distance restraint between "
151 "%s and %s" % (particles1[0].get_name(),
152 particles2[0].get_name()))
154 if len(particles1) > 1
or len(particles2) > 1:
155 raise ValueError(
"more than one particle selected")
157 self.rs.add_restraint(
161 self.rs.add_restraint(
169 def __init__(self, m, objects, resolution, angular_tolerance,label='None'):
170 IMP.Restraint.__init__(self, m,
"TorqueRestraint %1%")
171 self.softness_angle = 0.5
178 self.particles = [h.get_particle()
for h
in hierarchies]
181 self.at=angular_tolerance
183 def get_angle_probability(self,xyz,angle_center):
184 maxtheta=angle_center+self.at
185 mintheta=angle_center-self.at
186 angle=self.math.atan2(xyz.get_y(),xyz.get_x() )*180.0/self.math.pi
187 anglediff = (angle - maxtheta + 180 + 360) % 360 - 180
188 argvalue1=anglediff / self.softness_angle
189 anglediff = (angle - mintheta + 180 + 360) % 360 - 180
190 argvalue2=-anglediff / self.softness_angle
191 prob = (1.0-self.plateau) / (1.0 + self.math.exp(-max(argvalue1,argvalue2)))
194 def unprotected_evaluate(self, da):
197 angle_center=self.math.atan2(center[1],center[0])*180.0/self.math.pi
199 s+=-self.math.log(1.0-self.get_angle_probability(xyz,angle_center))
202 def do_get_inputs(self):
203 return self.particles
211 score = self.weight * self.unprotected_evaluate(
None)
212 output[
"_TotalScore"] = str(score)
213 output[
"TorqueRestraint_" + self.label] = str(score)
221 PMI2 python restraint. Restrains particles within a
222 Cylinder aligned along the z-axis and
224 Optionally, one can restrain the cylindrical angle
227 def __init__(self, m, objects, resolution, radius,mintheta=None,
228 maxtheta=
None,repulsive=
False,label=
'None'):
230 @param objects PMI2 objects
231 @param resolution the resolution you want the restraint to be applied
232 @param radius the radius of the cylinder
233 @param mintheta minimum cylindrical angle in degrees
234 @param maxtheta maximum cylindrical angle in degrees
236 IMP.Restraint.__init__(self, m,
"CylinderRestraint %1%")
239 self.softness_angle = 0.5
243 self.mintheta=mintheta
244 self.maxtheta=maxtheta
245 self.repulsive=repulsive
249 self.particles = [h.get_particle()
for h
in hierarchies]
252 def get_probability(self,p):
254 r=self.math.sqrt(xyz.get_x()**2+xyz.get_y()**2)
255 argvalue=(r-self.radius) / self.softness
256 if self.repulsive: argvalue=-argvalue
257 prob = (1.0 - self.plateau) / (1.0 + self.math.exp(-argvalue))
260 def get_angle_probability(self,p):
262 angle=self.math.atan2(xyz.get_y(),xyz.get_x() )*180.0/self.math.pi
263 anglediff = (angle - self.maxtheta + 180 + 360) % 360 - 180
264 argvalue1=anglediff / self.softness_angle
265 anglediff = (angle - self.mintheta + 180 + 360) % 360 - 180
266 argvalue2=-anglediff / self.softness_angle
267 prob = (1.0-self.plateau) / (1.0 + self.math.exp(-max(argvalue1,argvalue2)))
270 def unprotected_evaluate(self, da):
272 for p
in self.particles:
273 s+=-self.math.log(1.0-self.get_probability(p))
274 if self.mintheta
is not None and self.maxtheta
is not None:
275 s+=-self.math.log(1.0-self.get_angle_probability(p))
279 return self.particles
281 def add_to_model(self):
284 def get_output(self):
287 score = self.weight * self.unprotected_evaluate(
None)
288 output[
"_TotalScore"] = str(score)
289 output[
"CylinderRestraint_" + self.label] = str(score)
296 a python restraint with bistable potential
297 Authors: G. Bouvier, R. Pellarin. Pasteur Institute.
302 def __init__(self,m,p1,p2,dist1,dist2,sigma1,sigma2,weight1,weight2):
304 input twp particles, the two equilibrium distances, their amplitudes, and their weights (populations)
306 IMP.Restraint.__init__(self, m,
"BiStableDistanceRestraint %1%")
316 if self.weight1+self.weight2 != 1:
317 raise ValueError(
"The sum of the weights must be one")
321 self.particle_list=[p1,p2]
323 def gaussian(self,x, mu, sig, w):
324 return w*self.np.exp(-self.np.power(x - mu, 2.) / (2 * self.np.power(sig, 2.)))
326 def unprotected_evaluate(self,da):
328 prob=self.gaussian(dist,self.dist1,self.sigma1,self.weight1)+\
329 self.gaussian(dist,self.dist2,self.sigma2,self.weight2)
330 return -self.math.log(prob)
333 return self.particle_list
338 """Restraint for anchoring a particle to a specific coordinate."""
342 tuple_selection=
None,
350 """Setup distance restraint.
351 @param representation DEPRECATED
352 @param tuple_selection (resnum, resnum, molecule name,
354 @param anchor_point Point to which to restrain particle
355 (IMP.algebra.Vector3D object)
356 @param radius Size of the tolerance length
357 @param kappa The harmonic parameter
358 @param resolution For selecting a particle
359 @param weight Weight of restraint
360 @param root_hier The hierarchy to select from (use this instead of
362 @param label A unique label to be used in outputs and
363 particle/restraint names
364 \note Pass the same resnum twice to each tuple_selection. Optionally
365 add a copy number (PMI2 only)
367 if tuple_selection
is None:
368 raise Exception(
"You must pass a tuple_selection")
370 if representation
and not root_hier:
371 m = representation.prot.get_model()
373 resolution=resolution,
374 name=tuple_selection[2],
375 residue=tuple_selection[0])
376 elif root_hier
and not representation:
377 m = root_hier.get_model()
379 if len(tuple_selection) > 3:
380 copy_num1 = tuple_selection[3]
383 resolution=resolution,
384 molecule=tuple_selection[2],
385 residue_index=tuple_selection[0],
386 copy_index=copy_num1)
387 ps = sel1.get_selected_particles()
389 raise Exception(
"%s: Pass representation or root_hier, not both" %
392 raise ValueError(
"%s: more than one particle selected" %
395 super(DistanceToPointRestraint, self).
__init__(m, label=label,
400 if anchor_point
is None:
402 elif type(anchor_point)
is IMP.algebra.Vector3D:
406 "%s: @param anchor_point must be an algebra.Vector3D object" %
414 self.rs.add_restraint(r3)
416 print(
"\n%s: Created distance_to_point_restraint between "
417 "%s and %s" % (self.name, ps[0].get_name(), c3))
Applies a SingletonScore to each Singleton in a list.
def __init__
Setup distance restraint.
A simple distance restraint.
Lower bound harmonic function (non-zero when feature < mean)
def add_to_model
Add the restraint to the model.
Various classes to hold sets of particles.
Upper bound harmonic function (non-zero when feature > mean)
algebra::Vector3D get_centroid(const XYZs &ps)
Get the centroid.
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)...
def __init__
Setup external barrier restraint.
Store a list of ParticleIndexes.
Restraint for anchoring a particle to a specific coordinate.
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.
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.
def get_output
Get outputs to write to stat files.
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.