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.
5 from __future__
import print_function
15 def __init__(self, m, ps, k):
16 IMP.kernel.Restraint.__init__(self, m,
"MyRestraint %1%")
20 def unprotected_evaluate(self, da):
22 for i
in range(1, len(self.ps)):
25 if p0.get_value(k) > p1.get_value(k):
26 diff = (p0.get_value(k) - p1.get_value(k))
28 p0.add_to_derivative(k, -1, da)
29 p1.add_to_derivative(k, 1, da)
31 if IMP.get_log_level() >= IMP.base.TERSE:
32 print(p0.get_name(),
"and", p1.get_name(),
" are ok")
35 def do_get_inputs(self):
42 for i
in range(0, 10):
46 r = MyRestraint(m, ps, k)
48 print(r.evaluate(
True))