1 """@namespace IMP.pmi1.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 def __init__(self, m, objects, resolution, angular_tolerance,label='None'):
172 IMP.Restraint.__init__(self, m,
"TorqueRestraint %1%")
173 self.softness_angle = 0.5
180 self.particles = [h.get_particle()
for h
in hierarchies]
183 self.at=angular_tolerance
185 def get_angle_probability(self,xyz,angle_center):
186 maxtheta=angle_center+self.at
187 mintheta=angle_center-self.at
188 angle=self.math.atan2(xyz.get_y(),xyz.get_x() )*180.0/self.math.pi
189 anglediff = (angle - maxtheta + 180 + 360) % 360 - 180
190 argvalue1=anglediff / self.softness_angle
191 anglediff = (angle - mintheta + 180 + 360) % 360 - 180
192 argvalue2=-anglediff / self.softness_angle
193 prob = (1.0-self.plateau) / (1.0 + self.math.exp(-max(argvalue1,argvalue2)))
196 def unprotected_evaluate(self, da):
199 angle_center=self.math.atan2(center[1],center[0])*180.0/self.math.pi
201 s+=-self.math.log(1.0-self.get_angle_probability(xyz,angle_center))
204 def do_get_inputs(self):
205 return self.particles
212 score = self.weight * self.unprotected_evaluate(
None)
213 output[
"_TotalScore"] = str(score)
214 output[
"TorqueRestraint_" + self.label] = str(score)
222 PMI2 python restraint. Restrains particles within a
223 Cylinder aligned along the z-axis and
225 Optionally, one can restrain the cylindrical angle
228 def __init__(self, m, objects, resolution, radius,mintheta=None,
229 maxtheta=
None,repulsive=
False,label=
'None'):
231 @param objects PMI2 objects
232 @param resolution the resolution you want the restraint to be applied
233 @param radius the radius of the cylinder
234 @param mintheta minimum cylindrical angle in degrees
235 @param maxtheta maximum cylindrical angle in degrees
237 IMP.Restraint.__init__(self, m,
"CylinderRestraint %1%")
240 self.softness_angle = 0.5
244 self.mintheta=mintheta
245 self.maxtheta=maxtheta
246 self.repulsive=repulsive
250 self.particles = [h.get_particle()
for h
in hierarchies]
253 def get_probability(self,p):
255 r=self.math.sqrt(xyz.get_x()**2+xyz.get_y()**2)
256 argvalue=(r-self.radius) / self.softness
257 if self.repulsive: argvalue=-argvalue
258 prob = (1.0 - self.plateau) / (1.0 + self.math.exp(-argvalue))
261 def get_angle_probability(self,p):
263 angle=self.math.atan2(xyz.get_y(),xyz.get_x() )*180.0/self.math.pi
264 anglediff = (angle - self.maxtheta + 180 + 360) % 360 - 180
265 argvalue1=anglediff / self.softness_angle
266 anglediff = (angle - self.mintheta + 180 + 360) % 360 - 180
267 argvalue2=-anglediff / self.softness_angle
268 prob = (1.0-self.plateau) / (1.0 + self.math.exp(-max(argvalue1,argvalue2)))
273 for p
in self.particles:
274 s+=-self.math.log(1.0-self.get_probability(p))
275 if self.mintheta
is not None and self.maxtheta
is not None:
276 s+=-self.math.log(1.0-self.get_angle_probability(p))
280 return self.particles
282 def add_to_model(self):
285 def get_output(self):
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.)))
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 model = 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 model = 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__(model, 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.
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)
def __init__
Setup external barrier restraint.
virtual double unprotected_evaluate(DerivativeAccumulator *da) const
Return the unweighted score for the restraint.
Classes to handle different kinds of restraints.
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.
def get_output
Get outputs to write to stat files.
Store a list of ParticleIndexes.
def __init__
Setup distance restraint.
Apply a function to the distance to a fixed point.
A decorator for a particle with x,y,z coordinates.
Base class for PMI restraints, which wrap IMP.Restraint(s).
Restraint for anchoring a particle to a specific coordinate.
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...
Restraint to keep all structures inside sphere.
The general base class for IMP exceptions.
a python restraint with bistable potential Authors: G.
A simple distance restraint.
Functionality for loading, creating, manipulating and scoring atomic structures.
Select hierarchy particles identified by the biological name.
virtual ModelObjectsTemp do_get_inputs() const =0
def add_to_model
Add the restraint to the model.
A restraint is a term in an IMP ScoringFunction.
def __init__
input twp particles, the two equilibrium distances, their amplitudes, and their weights (populations)...