While we do not recommend doing serious work using restraints written in Python, it is often useful when prototyping or testing code. Copy this example and modify as needed.
7 from __future__
import print_function
20 def __init__(self, m, ps, k):
21 IMP.Restraint.__init__(self, m,
"MyRestraint %1%")
25 def unprotected_evaluate(self, da):
27 for i
in range(1, len(self.ps)):
30 if p0.get_value(k) > p1.get_value(k):
31 diff = (p0.get_value(k) - p1.get_value(k))
33 p0.add_to_derivative(k, -1, da)
34 p1.add_to_derivative(k, 1, da)
37 print(p0.get_name(),
"and", p1.get_name(),
" are ok")
40 def do_get_inputs(self):
48 for i
in range(0, 10):
52 r = MyRestraint(m, ps, k)
54 print(r.evaluate(
True))