IMP  2.0.1
The Integrative Modeling Platform
chimera_models.py
1 #!/usr/bin/env python
2 
3 __doc__ = "Generate complete models from Chimera transformations file."
4 
5 import sys
6 import IMP
7 import IMP.atom
8 from optparse import OptionParser
9 
10 def parse_args():
11  usage = """%prog [options] <subunit> <symmetry degree>
12  <transformations file> <number of models> <output models>
13 
14 This script, given the structure of a single subunit and the Chimera
15 transformations file, applies the transformations to generate a number of
16 complete models.
17 
18  <subunit> subunit PDB, the same given to MultiFit.
19  <symmetry degree> Cn degree.
20  <transformations file> MultiFit output in chimera output format.
21  <number of models> number of models to print.
22  <output models> Solutions are written as output.i.pdb."""
23  parser = OptionParser(usage)
24  opts, args = parser.parse_args()
25  if len(args) != 5:
26  parser.error("incorrect number of arguments")
27  return args
28 
29 def get_transformations(sol):
30  [ind,dock_rot_s,dock_trans_s,fit_rot_s,fit_trans_s,cc_s]=sol.split("|")
31  s=dock_rot_s.split(" ")
32  s1=dock_trans_s.split(" ")
35  float(s[0]),float(s[1]),float(s[2]),
36  float(s[3]),float(s[4]),float(s[5]),
37  float(s[6]),float(s[7]),float(s[8])),
38  IMP.algebra.Vector3D(float(s1[0]),float(s1[1]),float(s1[2])))
39  s=fit_rot_s.split(" ")
40  s1=fit_trans_s.split(" ")
43  float(s[0]),float(s[1]),float(s[2]),
44  float(s[3]),float(s[4]),float(s[5]),
45  float(s[6]),float(s[7]),float(s[8])),
46  IMP.algebra.Vector3D(float(s1[0]),float(s1[1]),float(s1[2])))
47  return dock_t,fit_t
48 
49 def run(subunit_fn,symm_deg,sol_fn,num,output_fn):
50  mdl=IMP.Model()
51  mhs=[]
52  for i in range(symm_deg):
53  mh=IMP.atom.read_pdb(subunit_fn,mdl)
54  mhs.append(mh)
55  IMP.atom.setup_as_rigid_body(mh)
56  lines=open(sol_fn).readlines()
57  for j,sol in enumerate(lines[:num]):
58  dock_t,fit_t=get_transformations(sol)
59  curr_t=dock_t
60  for i in range(symm_deg):
62  curr_t=dock_t*curr_t
63  for i in range(symm_deg):
65  IMP.atom.write_pdb(mhs,output_fn+".%03d.pdb" % j)
66 
67 def main():
68  args = parse_args()
69  run(args[0],int(args[1]),args[2],int(args[3]),args[4])
70 
71 if __name__ == "__main__":
72  main()