IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
edit_molecular_hierarchy.py
1## \example atom/edit_molecular_hierarchy.py
2# In this example, we read a protein from a PDB file and then add a
3# layer of atom::Fragments below the chain.
4
5import IMP.core
6import IMP.atom
7import sys
8
9IMP.setup_from_argv(sys.argv, "edit molecular hierarchy")
10
11m = IMP.Model()
12ep = IMP.atom.read_pdb(IMP.atom.get_example_path('example_protein.pdb'), m)
13
14hchain = IMP.atom.get_by_type(ep, IMP.atom.CHAIN_TYPE)[0]
15
16children = hchain.get_children()
17
18# create two fragments with 10 residues each and transfer the residues
19# to be their children
20
21f0 = IMP.atom.Fragment.setup_particle(m, m.add_particle("F0"),
22 [IMP.atom.Residue(x).get_index()
23 for x in children[:10]])
24for c in children[:10]:
25 hchain.remove_child(c)
26 f0.add_child(c)
27
28f1 = IMP.atom.Fragment.setup_particle(m, m.add_particle("F1"),
29 [IMP.atom.Residue(x).get_index()
30 for x in children[10:20]])
31for c in children[10:20]:
32 hchain.remove_child(c)
33 f1.add_child(c)
34
35# remove the rest to make the graph simple
36for c in children[20:]:
37 hchain.remove_child(c)
38
39# add the fragments under the chain
40hchain.add_child(f0)
41hchain.add_child(f1)
42
43# create a graph from the hierarchy
45
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
static Fragment setup_particle(Model *m, ParticleIndex pi)
Definition Fragment.h:67
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.
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.
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.
std::string show_graphviz(Graph g)