1 """@namespace IMP.pmi.restraints.basic
2 Some miscellaneous simple restraints.
5 from __future__
import print_function
13 class ExternalBarrier(object):
22 """Setup external barrier to keep all your structures inside sphere
23 @param representation DEPRECATED
24 @param center - Center of the external barrier restraint (IMP.algebra.Vector3D object)
25 @param radius Size of external barrier
26 @param hierarchies Can be one of the following inputs:
27 IMP Hierarchy, PMI System/State/Molecule/TempResidue, or a list/set of them
28 @param resolution Select which resolutions to act upon
35 self.m = representation.prot.get_model()
38 resolution=resolution,
39 hierarchies=hierarchies)
42 self.m = hiers[0].get_model()
43 particles = [h.get_particle()
for h
in hiers]
45 raise Exception(
"ExternalBarrier: must pass representation or hierarchies")
51 elif type(center)
is IMP.algebra.Vector3D:
54 raise Exception(
"ExternalBarrier: @param center must be an algebra::Vector3D object")
62 self.rs.add_restraint(r3)
63 self.set_weight(self.weight)
65 def set_label(self, label):
68 def add_to_model(self):
71 def get_restraint(self):
77 score = self.evaluate()
78 output[
"_TotalScore"] = str(score)
79 output[
"ExternalBarrier_" + self.label] = str(score)
82 def set_weight(self, weight):
84 self.rs.set_weight(weight)
87 return self.weight * self.rs.unprotected_evaluate(
None)
91 """A simple distance restraint"""
94 tuple_selection1=
None,
95 tuple_selection2=
None,
101 """Setup distance restraint.
102 @param representation DEPRECATED
103 @param tuple_selection1 (resnum,resnum,molecule name, copy number (=0))
104 @param tuple_selection2 (resnum,resnum,molecule name, copy number (=0))
105 @param distancemin The minimum dist
106 @param distancemax The maximum dist
107 @param resolution For selecting particles
108 @param kappa The harmonic parameter
109 @param root_hier The hierarchy to select from (use this instead of representation)
110 \note Pass the same resnum twice to each tuple_selection. Optionally add a copy number (PMI2 only)
114 if tuple_selection1
is None or tuple_selection2
is None:
115 raise Exception(
"You must pass tuple_selection1/2")
119 if representation
and not root_hier:
120 self.m = representation.prot.get_model()
122 resolution=resolution,
123 name=tuple_selection1[2],
124 residue=tuple_selection1[0])
126 resolution=resolution,
127 name=tuple_selection2[2],
128 residue=tuple_selection2[0])
129 elif root_hier
and not representation:
130 self.m = root_hier.get_model()
132 if len(tuple_selection1)>3:
133 copy_num1 = tuple_selection1[3]
135 if len(tuple_selection2)>3:
136 copy_num2 = tuple_selection2[3]
139 resolution=resolution,
140 molecule=tuple_selection1[2],
141 residue_index=tuple_selection1[0],
142 copy_index=copy_num1)
143 particles1 = sel1.get_selected_particles()
145 resolution=resolution,
146 molecule=tuple_selection2[2],
147 residue_index=tuple_selection2[0],
148 copy_index=copy_num2)
149 particles2 = sel2.get_selected_particles()
151 raise Exception(
"Pass representation or root_hier, not both")
155 print(
"Created distance restraint between "
156 "%s and %s" % (particles1[0].get_name(),particles2[0].get_name()))
158 if len(particles1) > 1
or len(particles2) > 1:
159 raise ValueError(
"more than one particle selected")
161 self.rs.add_restraint(
165 self.rs.add_restraint(
170 def set_weight(self,weight):
172 self.rs.set_weight(weight)
174 def set_label(self, label):
177 def add_to_model(self):
180 def get_restraint(self):
183 def get_restraint_for_rmf(self):
186 def get_output(self):
189 score = self.weight * self.rs.unprotected_evaluate(
None)
190 output[
"_TotalScore"] = str(score)
191 output[
"DistanceRestraint_" + self.label] = str(score)
195 return self.weight * self.rs.unprotected_evaluate(
None)
202 a python restraint with bistable potential
203 Authors: G. Bouvier, R. Pellarin. Pasteur Institute.
208 def __init__(self,m,p1,p2,dist1,dist2,sigma1,sigma2,weight1,weight2):
210 input twp particles, the two equilibrium distances, their amplitudes, and their weights (populations)
212 IMP.Restraint.__init__(self, m,
"BiStableDistanceRestraint %1%")
222 if self.weight1+self.weight2 != 1:
223 raise ValueError(
"The sum of the weights must be one")
227 self.particle_list=[p1,p2]
229 def gaussian(self,x, mu, sig, w):
230 return w*self.np.exp(-self.np.power(x - mu, 2.) / (2 * self.np.power(sig, 2.)))
232 def unprotected_evaluate(self,da):
234 prob=self.gaussian(dist,self.dist1,self.sigma1,self.weight1)+\
235 self.gaussian(dist,self.dist2,self.sigma2,self.weight2)
236 return -self.math.log(prob)
239 return self.particle_list
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)
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.
Object used to hold a set of restraints.
def __init__
input twp particles, the two equilibrium distances, their amplitudes, and their weights (populations)...
Store a list of ParticleIndexes.
Apply a function to the distance to a fixed point.
A decorator for a particle with x,y,z coordinates.
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.
virtual ModelObjectsTemp do_get_inputs() const =0
A restraint is a term in an IMP ScoringFunction.