IMP  2.0.0
The Integrative Modeling Platform
multiresolution.py
1 ## \example rmf/multiresolution.py
2 ## In this example a pdb is converted into a multiresolution model, somewhat painfully.
3 
4 import IMP.atom
5 import IMP.base
6 import sys
7 import RMF
8 import IMP.rmf
9 
10 IMP.base.setup_from_argv(sys.argv, "Create a multiresolution rmf file")
11 
12 pdbname= IMP.rmf.get_example_path("big.pdb")
13 
14 m= IMP.Model()
15 h= IMP.atom.read_pdb(pdbname, m)
17 
18 chains= IMP.atom.get_by_type(h, IMP.atom.CHAIN_TYPE)
19 
20 if IMP.base.get_bool_flag("run_quick_test"):
21  chains=[chains[0]]
22 
23 def recursive_approximation(res):
24  print "approximating", res
25  lr=len(res)
26  if lr<=1:
27  return res
28  if lr > 4:
29  me= recursive_approximation(res[0:lr/4])\
30  +recursive_approximation(res[lr/4: lr/2])\
31  +recursive_approximation(res[lr/2: 3*lr/4])\
32  +recursive_approximation(res[3*lr/4: lr])
33  else:
34  me= res
35  p= IMP.Particle(m)
38  nm= str(IMP.atom.Residue(res[0]).get_index())+"-"\
39  + str(IMP.atom.Residue(res[-1]).get_index())
40  p.set_name(nm)
41  for mm in me:
42  hc.add_child(mm)
43  return [hc]
44 
45 for c in chains:
46  res= IMP.atom.get_by_type(h, IMP.atom.RESIDUE_TYPE)
47  for r in res:
48  c.remove_child(r)
49  lvs= IMP.atom.get_leaves(r)
51  lr=len(res)
52  me= recursive_approximation(res[0:lr/4])\
53  +recursive_approximation(res[lr/4: lr/2])\
54  +recursive_approximation(res[lr/2: 3*lr/4])\
55  +recursive_approximation(res[3*lr/4: lr])
56  for mm in me:
57  c.add_child(mm)
58 
59 print "writing"
60 fn= IMP.base.create_temporary_file_name("multires", ".rmf")
61 rmf= RMF.create_rmf_file(fn)
62 print "adding"
63 IMP.rmf.add_hierarchies(rmf, chains)
64 
65 print "see file", fn