IMP  2.4.0
The Integrative Modeling Platform
rmf/multiresolution.py

In this example a pdb is converted into a multiresolution model, somewhat painfully.

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