While we do not recomment doing serious work using optimizer states written it python, it is often useful when prototyping or testing code. Copy this example and modify as needed.
6 from __future__
import print_function
14 def __init__(self, rs):
15 IMP.OptimizerState.__init__(self, rs[0].get_model(),
16 "MyOptimizerState%1%")
21 print(r.get_name(), r.get_last_score())
27 r0 = IMP.kernel._ConstRestraint(m, [], 1)
28 r0.set_name(
"restraint 0")
30 r1 = IMP.kernel._ConstRestraint(m, [], 2)
31 r1.set_name(
"restraint 1")
34 sf = rs.create_scoring_function()
36 os = MyOptimizerState([r0, r1])
37 os.set_name(
"python optimizer state")
39 co = IMP.kernel._ConstOptimizer(m)
40 co.set_scoring_function(sf)
41 co.add_optimizer_state(os)
42 print(co.optimize(100))
45 co.remove_optimizer_state(os)