IMP  2.0.1
The Integrative Modeling Platform
_optimization.py
1 """Interface between XML Representation and IMP Model."""
2 
3 import IMP
4 import IMP.atom
5 import random
6 import math
7 
8 
9 class Optimization(object):
10 
11  def __init__(self):
12  self._children = list()
13 
14  def run(self, restraint, log):
15  for child in self._children:
16  child.run(restraint, log)
17 
18 
19 class _OptimizationNode(object):
20  counter = 0
21  def __init__(self, attributes, text):
22  id = attributes.get('id')
23  if id:
24  self.id = id
25  else:
26  self.id = 'object_%d' % _OptimizationNode.counter
27  _OptimizationNode.counter += 1
28  self._children = list()
29 
30 
31 class _OptimizationConjugateGradients(_OptimizationNode):
32  def __init__(self, attributes, text):
33  _OptimizationNode.__init__(self, attributes, text)
34  self.threshold = float(attributes.get('threshold', 0))
35  self.steps = int(attributes.get('steps', 1))
36 
37  def run(self, restraint, log):
38  restraint.clear()
39  restraint.set_include(include=True)
40  for child in self._children:
41  child.run(restraint, log)
42  restraint.add_to_model()
44  o.set_model(restraint._model)
45  if log:
46  o.add_optimizer_state(log)
47  o.optimize(self.steps)
48 
49 
50 
51 class _OptimizationRestraint(_OptimizationNode):
52  def __init__(self, attributes, text):
53  _OptimizationNode.__init__(self, attributes, text)
54  self.name = attributes['name']
55  self.weight = float(attributes.get('weight', 1.0))
56 
57  def run(self, restraint, log):
58  restraint.set_include(name=self.name, include=True,
59  weight=self.weight)