IMP logo
IMP Reference Guide  2.22.0
The Integrative Modeling Platform
kernel/basic_optimization.py

This illustrates a basic main loop for optimization and searching for the best scoring conformation.

1 ## \example kernel/basic_optimization.py
2 # This illustrates a basic main loop for optimization and searching for the
3 # best scoring conformation.
4 #
5 
6 import IMP.container
7 import IMP.statistics
8 import sys
9 
10 IMP.setup_from_argv(sys.argv, "Basic optimization")
11 
12 # Make 100 particles randomly distributed in a cubic box
13 m = IMP.Model()
16  IMP.algebra.Vector3D(10,10,10))
17 for i in range(100):
18  p = m.add_particle("p")
19  lsc.add(p)
22  d.set_coordinates_are_optimized(True)
23 
27 # we don't want to see lots of log messages about restraint evaluation
28 m.set_log_level(IMP.WARNING)
29 
30 # the container (lsc) stores a list of particle indices
31 pis = lsc.get_contents()
32 
34 s.set_scoring_function(sf)
35 s.set_number_of_attempts(10)
36 # but we do want something to watch
37 s.set_log_level(IMP.TERSE)
38 s.set_number_of_monte_carlo_steps(10)
39 # find some configurations which move the particles far apart
40 configs = s.create_sample()
41 for i in range(0, configs.get_number_of_configurations()):
42  configs.load_configuration(i)
43  # print out the sphere containing the point set
44  # - Why? - Why not?
46  print(sphere)
47 
48 # cluster the solutions based on their coordinates
50 
51 # of course, this doesn't return anything of interest since the points are
52 # randomly distributed, but, again, why not?
53 clustering = IMP.statistics.create_lloyds_kmeans(e, 3, 1000)
54 for i in range(0, clustering.get_number_of_clusters()):
55  # load the configuration for a central point
56  configs.load_configuration(clustering.get_cluster_representative(i))
58  print(sphere)