IMP logo
IMP Reference Guide  2.10.0
The Integrative Modeling Platform
gsl/simplex.py

The IMP::gsl::Simplex optimizer is a local optimizer that does not require derivatives.

1 ## \example gsl/simplex.py
2 # The IMP::gsl::Simplex optimizer is a local optimizer that does not
3 # require derivatives.
4 
5 import IMP
6 import IMP.test
7 import IMP.core
8 import IMP.gsl
9 import IMP.algebra
10 import sys
11 
12 IMP.setup_from_argv(sys.argv, "simplex")
13 
14 m = IMP.Model()
15 
16 # create two particles to optimize
21 d0.set_coordinates_are_optimized(True)
22 d1.set_coordinates_are_optimized(True)
23 
24 # restrain their distance to be 1
25 dist = IMP.core.DistanceRestraint(m, IMP.core.Harmonic(1, 1), d0, d1)
26 
27 opt = IMP.gsl.Simplex(m)
28 opt.set_scoring_function([dist])
29 opt.set_minimum_size(.000001)
30 opt.set_initial_length(1)
31 
32 # probably more steps than are needed
33 e = opt.optimize(1000000)
34 print(IMP.core.get_distance(d0, d1))