IMP  2.0.0
The Integrative Modeling Platform
_main.py
1 from _xml_parser import XMLRepresentation
2 from _xml_parser import XMLRestraint
3 from _xml_parser import XMLOptimization
4 from _xml_parser import XMLDisplay
5 
6 class Main(object):
7  def __init__(self):
8  self.representation = None
9  self.restraint = None
10  self.optimization = None
11  self.display = None
12  self.log = None
13  self._logname = None
14  def add_representation(self, fname):
15  if self.representation:
16  raise Exception, "Representation cannot be added twice!"
17  self.representation = XMLRepresentation(fname).run()
18  return self.representation
19  def add_restraint(self, fname):
20  if self.restraint:
21  raise Exception, "Restraint cannot be added twice!"
22  if not self.representation:
23  raise Exception, "Please add Representation before Restraint!"
24  self.restraint = XMLRestraint(fname).run()
25  self.restraint.add_to_representation(self.representation)
26  return self.restraint
27  def add_optimization(self, fname):
28  if self.optimization:
29  raise Exception, "Optimization cannot be added twice!"
30  self.optimization = XMLOptimization(fname).run()
31  return self.optimization
32  def add_display(self, fname, logname=None):
33  if self.display:
34  raise Exception, "Display cannot be added twice!"
35  self.display = XMLDisplay(fname).run()
36  self._logname = logname
37  self._create_log()
38  return self.display
39  def _create_log(self):
40  if not self.log:
41  if self.display and self.representation:
42  if not self.restraint:
43  self.representation.get_model()
44  if self._logname:
45  logname = self._logname
46  else:
47  logname = 'log%03d.py'
48  self.log = self.display.create_log(self.representation, logname)
49  self.log.set_was_used(True)
50  def optimize(self):
51  if self.restraint:
52  if not self.representation:
53  raise Exception, "Representation missing!"
54  self._create_log()
55  if self.optimization:
56  if self._logname:
57  self.optimization.run(self.restraint, self.log)
58  else:
59  self.optimization.run(self.restraint, None)
60  elif self.optimization:
61  raise Exception, "Restraint missing!"
62  def get_model(self):
63  if self.representation:
64  return self.representation._model
65  else:
66  raise Exception, "Representation missing!"