IMP  2.2.1
The Integrative Modeling Platform
rmf/multiresolution.py
1 ## \example rmf/multiresolution.py
2 # In this example a pdb is converted into a multiresolution model,
3 # somewhat painfully.
4 
5 import IMP.atom
6 import IMP.base
7 import sys
8 import RMF
9 import IMP.rmf
10 
11 IMP.base.setup_from_argv(sys.argv, "Create a multiresolution rmf file")
12 
13 pdbname = IMP.rmf.get_example_path("big.pdb")
14 
15 m = IMP.kernel.Model()
16 h = IMP.atom.read_pdb(pdbname, m)
18 
19 chains = IMP.atom.get_by_type(h, IMP.atom.CHAIN_TYPE)
20 
21 if IMP.base.get_bool_flag("run_quick_test"):
22  chains = [chains[0]]
23 
24 
25 def recursive_approximation(res):
26  print "approximating", res
27  lr = len(res)
28  if lr <= 1:
29  return res
30  if lr > 4:
31  me = recursive_approximation(res[0:lr / 4])\
32  + recursive_approximation(res[lr / 4: lr / 2])\
33  + recursive_approximation(res[lr / 2: 3 * lr / 4])\
34  + recursive_approximation(res[3 * lr / 4: lr])
35  else:
36  me = res
37  p = IMP.kernel.Particle(m)
40  nm = str(IMP.atom.Residue(res[0]).get_index()) + "-"\
41  + str(IMP.atom.Residue(res[-1]).get_index())
42  p.set_name(nm)
43  for mm in me:
44  hc.add_child(mm)
45  return [hc]
46 
47 for c in chains:
48  res = IMP.atom.get_by_type(h, IMP.atom.RESIDUE_TYPE)
49  for r in res:
50  c.remove_child(r)
51  lvs = IMP.atom.get_leaves(r)
53  lr = len(res)
54  me = recursive_approximation(res[0:lr / 4])\
55  + recursive_approximation(res[lr / 4: lr / 2])\
56  + recursive_approximation(res[lr / 2: 3 * lr / 4])\
57  + recursive_approximation(res[3 * lr / 4: lr])
58  for mm in me:
59  c.add_child(mm)
60 
61 print "writing"
62 fn = IMP.base.create_temporary_file_name("multires", ".rmf")
63 rmf = RMF.create_rmf_file(fn)
64 print "adding"
65 IMP.rmf.add_hierarchies(rmf, chains)
66 
67 print "see file", fn
Ints get_index(const kernel::ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
void setup_as_approximation(Hierarchy h)
bool get_bool_flag(std::string name)
std::string create_temporary_file_name(std::string prefix="imp_temp", std::string suffix="")
See IMP.base for more information.
Definition: base/Array.h:20
static Hierarchy setup_particle(kernel::Model *m, kernel::ParticleIndex pi, kernel::ParticleIndexesAdaptor children=kernel::ParticleIndexesAdaptor())
Hierarchies get_by_type(Hierarchy mhd, GetByType t)
void add_hierarchies(RMF::NodeHandle fh, const atom::Hierarchies &hs)
Class to handle individual model particles.
A decorator for a residue.
Definition: Residue.h:133
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
See IMP.atom for more information.
void read_pdb(base::TextInput input, int model, Hierarchy h)
Hierarchies get_leaves(const Selection &h)
See IMP.rmf for more information.
Definition: associations.h:20
void add_bonds(Hierarchy d, const ForceFieldParameters *ffp=get_all_atom_CHARMM_parameters())
std::string get_example_path(std::string file_name)
Return the path to installed example data for this module.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:72