IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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
5import IMP.atom
6import sys
7import RMF
8import IMP.rmf
9
10IMP.setup_from_argv(sys.argv, "Create a multiresolution rmf file")
11
12pdbname = IMP.rmf.get_example_path("big.pdb")
13
14m = IMP.Model()
15h = IMP.atom.read_pdb(pdbname, m)
17
18chains = IMP.atom.get_by_type(h, IMP.atom.CHAIN_TYPE)
19
20if IMP.get_bool_flag("run_quick_test"):
21 chains = [chains[0]]
22
23
24def recursive_approximation(res):
25 print("approximating", res)
26 lr = len(res)
27 if lr <= 1:
28 return res
29 if lr > 4:
30 me = recursive_approximation(res[0:lr // 4])\
31 + recursive_approximation(res[lr // 4: lr // 2])\
32 + recursive_approximation(res[lr // 2: 3 * lr // 4])\
33 + recursive_approximation(res[3 * lr // 4: lr])
34 else:
35 me = res
36 p = IMP.Particle(m)
39 nm = str(IMP.atom.Residue(res[0]).get_index()) + "-"\
40 + str(IMP.atom.Residue(res[-1]).get_index())
41 p.set_name(nm)
42 for mm in me:
43 hc.add_child(mm)
44 return [hc]
45
46
47for 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
61print("writing")
62fn = "multires.rmf"
63rmf = RMF.create_rmf_file(fn)
64print("adding")
65IMP.rmf.add_hierarchies(rmf, chains)
66
67print("see file", fn)
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Class to handle individual particles of a Model object.
Definition Particle.h:45
static Hierarchy setup_particle(Model *m, ParticleIndex pi, ParticleIndexesAdaptor children=ParticleIndexesAdaptor())
Create a Hierarchy of level t by adding the needed attributes.
Hierarchies get_by_type(Hierarchy mhd, GetByType t)
Gather all the molecular particles of a certain level in the hierarchy.
A decorator for a residue.
Definition Residue.h:137
Functionality for loading, creating, manipulating and scoring atomic structures.
void add_bonds(Hierarchy d, const ForceFieldParameters *ffp=get_all_atom_CHARMM_parameters())
Add bonds using definitions from given force field parameters.
void setup_as_approximation(Particle *h, const ParticlesTemp &other)
Hierarchy read_pdb(TextInput input, Model *model, PDBSelector *selector=get_default_pdb_selector(), bool select_first_model=true)
Read all the molecules in the first model of the PDB file.
Hierarchies get_leaves(const Selection &h)
Support for the RMF file format for storing hierarchical molecular data and markup.
std::string get_example_path(std::string file_name)
Return the full path to one of this module's example files.
void add_hierarchies(RMF::FileHandle fh, const atom::Hierarchies &hs)
bool get_bool_flag(std::string name)
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.