IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
molecular_hierarchy.py
1## \example atom/molecular_hierarchy.py
2# In this example, we read a protein from a PDB file and set the center and
3# radius of each residue to enclose the atoms in that residue.
4#
5# Then a second copy of the protein is loaded and they are both added to the
6# same hierarchy to define a hypothetical assembly.
7#
8
9import IMP
10import IMP.core
11import IMP.atom
12import sys
13
14IMP.setup_from_argv(sys.argv, "molecular hierarchy")
15
16m = IMP.Model()
17mp0 = IMP.atom.read_pdb(IMP.atom.get_example_path('example_protein.pdb'), m)
18# get the 16th residue of the first chain
19hchain = IMP.atom.get_by_type(mp0, IMP.atom.CHAIN_TYPE)[0]
20# decorate the chain particle with an IMP.atom.Chain decorator.
21# unfortunately, our Python wrapper does not handle conversions properly
22# as a result you have to manually get the particle for that chain
23chain = IMP.atom.Chain(hchain.get_particle())
24r16 = IMP.atom.get_residue(chain, 16)
25r16.show()
26
27# get all the atoms
28atoms = IMP.atom.get_by_type(mp0, IMP.atom.ATOM_TYPE)
29# I didn't really have anything interesting to do with them...
30
31# create a new version of the protein that is coarsened (one particle per
32# residue)
34
35# we don't need mp0 any more
37
38# load another copy
39mp1 = IMP.atom.read_pdb(IMP.atom.get_example_path('example_protein.pdb'), m)
40
41# create a graph from the hierarchy
43# process the file with dot like
44# dot -Tpdf hierarchy.dot > hierarchy.pdf
45mp1t.show_graphviz(open("hierarchy.dot", "w"))
46# try to display it graphically, assuming altgraph is installed
47try:
48 mp1t.show_with_altgraph()
49except:
50 pass
51
52# make this one rigid
54
55# create a hierarchy which contains the two proteins
56p = IMP.Particle(m)
58rmp.add_child(smp0)
59rmp.add_child(mp1)
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
Store info for a chain of a protein.
Definition Chain.h:61
static Hierarchy setup_particle(Model *m, ParticleIndex pi, ParticleIndexesAdaptor children=ParticleIndexesAdaptor())
Create a Hierarchy of level t by adding the needed attributes.
void destroy(Hierarchy d)
Delete the Hierarchy.
Hierarchies get_by_type(Hierarchy mhd, GetByType t)
Gather all the molecular particles of a certain level in the hierarchy.
Functionality for loading, creating, manipulating and scoring atomic structures.
IMP::core::RigidBody create_rigid_body(const Hierarchies &h, std::string name=std::string("created rigid body"))
Rigidify a molecule or collection of molecules.
Residue get_residue(Atom d, bool nothrow=false)
Return the Residue containing this atom.
HierarchyTree get_hierarchy_tree(Hierarchy h)
Get a graph for the passed Hierarchy.
std::string get_example_path(std::string file_name)
Return the full path to one of this module's example files.
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.
Hierarchy create_simplified_along_backbone(Hierarchy input, int num_res, bool keep_detailed=false, Model *m=nullptr)
Basic functionality that is expected to be used by a wide variety of IMP users.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.