IMP logo
IMP Reference Guide  2.20.2
The Integrative Modeling Platform
basic_optimization.py
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 from __future__ import print_function
7 import IMP.container
8 import IMP.statistics
9 import sys
10 
11 IMP.setup_from_argv(sys.argv, "Basic optimization")
12 
13 # Make 100 particles randomly distributed in a cubic box
14 m = IMP.Model()
17  IMP.algebra.Vector3D(10,10,10))
18 for i in range(100):
19  p = m.add_particle("p")
20  lsc.add(p)
23  d.set_coordinates_are_optimized(True)
24 
28 # we don't want to see lots of log messages about restraint evaluation
29 m.set_log_level(IMP.WARNING)
30 
31 # the container (lsc) stores a list of particle indices
32 pis = lsc.get_contents()
33 
35 s.set_scoring_function(sf)
36 s.set_number_of_attempts(10)
37 # but we do want something to watch
38 s.set_log_level(IMP.TERSE)
39 s.set_number_of_monte_carlo_steps(10)
40 # find some configurations which move the particles far apart
41 configs = s.create_sample()
42 for i in range(0, configs.get_number_of_configurations()):
43  configs.load_configuration(i)
44  # print out the sphere containing the point set
45  # - Why? - Why not?
47  print(sphere)
48 
49 # cluster the solutions based on their coordinates
51 
52 # of course, this doesn't return anything of interest since the points are
53 # randomly distributed, but, again, why not?
54 clustering = IMP.statistics.create_lloyds_kmeans(e, 3, 1000)
55 for i in range(0, clustering.get_number_of_clusters()):
56  # load the configuration for a central point
57  configs.load_configuration(clustering.get_cluster_representative(i))
59  print(sphere)
PartitionalClusteringWithCenter * create_lloyds_kmeans(Embedding *embedding, unsigned int k, unsigned int iterations)
Embed a configuration using the XYZ coordinates of a set of particles.
Definition: embeddings.h:28
Lower bound harmonic function (non-zero when feature < mean)
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
Various classes to hold sets of particles.
static XYZR setup_particle(Model *m, ParticleIndex pi)
Definition: XYZR.h:48
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
Create a scoring function on a list of restraints.
Return all close unordered pairs of particles taken from the SingletonContainer.
Vector3D get_random_vector_in(const Cylinder3D &c)
Generate a random vector in a cylinder with uniform density.
Code to compute statistical measures.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
Store a list of ParticleIndexes.
A simple sampler.
Definition: MCCGSampler.h:40
Score a pair of particles based on the distance between their centers.
algebra::Sphere3D get_enclosing_sphere(const XYZs &v)
Get a sphere enclosing the set of XYZRs.
VectorD< 3 > Vector3D
Definition: VectorD.h:425
Applies a PairScore to each Pair in a list.