IMP logo
IMP Reference Guide  2.5.0
The Integrative Modeling Platform
basic.py
1 """@namespace IMP.pmi.restraints.basic
2 Some miscellaneous simple restraints.
3 """
4 
5 from __future__ import print_function
6 import IMP
7 import IMP.core
8 import IMP.algebra
9 import IMP.atom
10 import IMP.container
11 import IMP.pmi.tools
12 
13 class ExternalBarrier(object):
14 
15  def __init__(
16  self,
17  representation,
18  radius,
19  hierarchies=None,
20  resolution=None):
21  self.m = representation.prot.get_model()
22  self.rs = IMP.RestraintSet(self.m, 'barrier')
23 
24  self.radius = radius
25  self.label = "None"
26 
27  c3 = IMP.algebra.Vector3D(0, 0, 0)
28  ub3 = IMP.core.HarmonicUpperBound(radius, 10.0)
31  # IMP.atom.get_by_type
32  particles = IMP.pmi.tools.select(
33  representation,
34  resolution=resolution,
35  hierarchies=hierarchies)
36  lsc.add(particles)
38  self.rs.add_restraint(r3)
39 
40  def set_label(self, label):
41  self.label = label
42 
43  def add_to_model(self):
45 
46  def get_restraint(self):
47  return self.rs
48 
49  def get_output(self):
50  self.m.update()
51  output = {}
52  score = self.rs.unprotected_evaluate(None)
53  output["_TotalScore"] = str(score)
54  output["ExternalBarrier_" + self.label] = str(score)
55  return output
56 
57 
58 class DistanceRestraint(object):
59 
60  def __init__(
61  self,
62  representation,
63  tuple_selection1,
64  tuple_selection2,
65  distancemin,
66  distancemax,
67  resolution=1.0,
68  kappa=1.0):
69  self.m = representation.prot.get_model()
70  self.rs = IMP.RestraintSet(self.m, 'distance')
71  self.weight=1.0
72  self.label="None"
73  #ts = IMP.core.Harmonic(distance,kappa)
74 
75  ts1 = IMP.core.HarmonicUpperBound(distancemax, kappa)
76  ts2 = IMP.core.HarmonicLowerBound(distancemin, kappa)
77 
78  # IMP.atom.get_by_type
79  particles1 = IMP.pmi.tools.select(
80  representation,
81  resolution=resolution,
82  name=tuple_selection1[2],
83  residue=tuple_selection1[0])
84  particles2 = IMP.pmi.tools.select(
85  representation,
86  resolution=resolution,
87  name=tuple_selection2[2],
88  residue=tuple_selection2[0])
89 
90  for p in particles1:
91  print(p.get_name())
92 
93  for p in particles2:
94  print(p.get_name())
95 
96  if len(particles1) > 1 or len(particles2) > 1:
97  raise ValueError("more than one particle selected")
98 
99  self.rs.add_restraint(
100  IMP.core.DistanceRestraint(self.m, ts1,
101  particles1[0],
102  particles2[0]))
103  self.rs.add_restraint(
104  IMP.core.DistanceRestraint(self.m, ts2,
105  particles1[0],
106  particles2[0]))
107 
108  def set_weight(self,weight):
109  self.weight = weight
110  self.rs.set_weight(weight)
111 
112  def set_label(self, label):
113  self.label = label
114 
115  def add_to_model(self):
116  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
117 
118  def get_restraint(self):
119  return self.rs
120 
121  def get_output(self):
122  self.m.update()
123  output = {}
124  score = self.weight * self.rs.unprotected_evaluate(None)
125  output["_TotalScore"] = str(score)
126  output["DistanceRestraint_" + self.label] = str(score)
127  return output
128 
129  def evaluate(self):
130  return self.weight * self.rs.unprotected_evaluate(None)
131 
132 
133 
134 
136  '''
137  a python restraint with bistable potential
138  Authors: G. Bouvier, R. Pellarin. Pasteur Institute.
139  '''
140  import numpy as np
141  import math
142 
143  def __init__(self,m,p1,p2,dist1,dist2,sigma1,sigma2,weight1,weight2):
144  '''
145  input twp particles, the two equilibrium distances, their amplitudes, and their weights (populations)
146  '''
147  IMP.Restraint.__init__(self, m, "BiStableDistanceRestraint %1%")
148  self.dist1=dist1
149  self.dist2=dist2
150 
151  self.sigma1=sigma1
152  self.sigma2=sigma2
153 
154  self.weight1=weight1
155  self.weight2=weight2
156 
157  if self.weight1+self.weight2 != 1:
158  raise ValueError("The sum of the weights must be one")
159 
160  self.d1=IMP.core.XYZ(p1)
161  self.d2=IMP.core.XYZ(p2)
162  self.particle_list=[p1,p2]
163 
164  def gaussian(self,x, mu, sig, w):
165  return w*self.np.exp(-self.np.power(x - mu, 2.) / (2 * self.np.power(sig, 2.)))
166 
167  def unprotected_evaluate(self,da):
168  dist=IMP.core.get_distance(self.d1,self.d2)
169  prob=self.gaussian(dist,self.dist1,self.sigma1,self.weight1)+\
170  self.gaussian(dist,self.dist2,self.sigma2,self.weight2)
171  return -self.math.log(prob)
172 
173  def do_get_inputs(self):
174  return self.particle_list
Applies a SingletonScore to each Singleton in a list.
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)
Miscellaneous utilities.
Definition: tools.py:1
Distance restraint between two particles.
double get_distance(XYZR a, XYZR b)
Compute the sphere distance between a and b.
Definition: XYZR.h:87
Object used to hold a set of restraints.
Definition: RestraintSet.h:36
def __init__
input twp particles, the two equilibrium distances, their amplitudes, and their weights (populations)...
Definition: basic.py:143
Store a list of ParticleIndexes.
def add_restraint_to_model
Add a PMI restraint to the model.
Definition: tools.py:22
Apply a function to the distance to a fixed point.
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
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...
VectorD< 3 > Vector3D
Definition: VectorD.h:395
def select
this function uses representation=SimplifiedModel it returns the corresponding selected particles rep...
Definition: tools.py:662
Functionality for loading, creating, manipulating and scoring atomic structures.
a python restraint with bistable potential Authors: G.
Definition: basic.py:135
virtual ModelObjectsTemp do_get_inputs() const =0
A restraint is a term in an IMP ScoringFunction.
Definition: Restraint.h:52