IMP logo
IMP Reference Guide  2.17.0
The Integrative Modeling Platform
atom/edit_molecular_hierarchy.py

In this example, we read a protein from a PDB file and then add a layer of atom::Fragments below the chain.

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 
5 import IMP.core
6 import IMP.atom
7 import sys
8 
9 IMP.setup_from_argv(sys.argv, "edit molecular hierarchy")
10 
11 m = IMP.Model()
12 ep = IMP.atom.read_pdb(IMP.atom.get_example_path('example_protein.pdb'), m)
13 
14 hchain = IMP.atom.get_by_type(ep, IMP.atom.CHAIN_TYPE)[0]
15 
16 children = hchain.get_children()
17 
18 # create two fragments with 10 residues each and transfer the residues
19 # to be their children
20 
21 f0 = IMP.atom.Fragment.setup_particle(m, m.add_particle("F0"),
23  for x in children[:10]])
24 for c in children[:10]:
25  hchain.remove_child(c)
26  f0.add_child(c)
27 
28 f1 = IMP.atom.Fragment.setup_particle(m, m.add_particle("F1"),
30  for x in children[10:20]])
31 for 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
36 for c in children[20:]:
37  hchain.remove_child(c)
38 
39 # add the fragments under the chain
40 hchain.add_child(f0)
41 hchain.add_child(f1)
42 
43 # create a graph from the hierarchy
45