IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
selection.py
1## \example pmi/selection.py
2"""This script demonstrates a few different ways you can perform selection
3 in PMI.
4 In PMI we first set up molecules at various resolutions.
5 Then you call System.build() and this creates all requested representations.
6"""
7
8import IMP
9import IMP.atom
10import IMP.rmf
11import IMP.pmi
13import IMP.pmi.dof
14import IMP.pmi.macros
17import sys
18
19IMP.setup_from_argv(sys.argv, "Selection in PMI")
20
21# ############### BEFORE BUILDING ###################
22# Preliminaries: read sequences, create a system and a state
24mdl = IMP.Model()
26st = s.create_state()
27
28# Create a molecule. This sets up "TempResidues" for all elements in
29# the sequence.
30mol = st.create_molecule("Rpb4", seqs["1WCM:D"], chain_id="D")
31
32# No structure has been built yet - you have to call
33# 'Molecule.add_representation'
34# The first argument to that function is a set of "TempResidues"
35# Here are some ways of getting them:
36
37# Slice a molecule (uses python-style 0-ordering)
38myres1 = mol[0:10]
39
40# Use PDB numbering with residue_range (inclusive on both ends)
41myres2 = mol.residue_range('1', '10')
42
43# If you add a PDB, this returns the set of TempResidues that were in
44# the PDB file
45atomic = mol.add_structure(IMP.pmi.get_example_path('data/1WCM_fitted.pdb'),
46 chain_id="D")
47
48# You can also call these helper functions at any time
49atomic = mol.get_atomic_residues()
50non_atomic = mol.get_non_atomic_residues()
51
52# All of the above objects are OrderedSets, so you can actually perform
53# set operations
54myres3 = mol[0:50] - atomic # non-atomic residues from 0 to 50
55myres4 = mol[0:50] & atomic # atomic residues between 0 and 50
56
57# Finally, pass your favorite handle to add_representation
58mol.add_representation(
59 myres3,
60 # creates beads with size 1 (non-atomic can only have one beadsize)
61 resolutions=[1])
62mol.add_representation(myres4,
63 resolutions=[1, 10]) # creates beads with size 1 and 10
64
65# When you have decided all representations, call build()
66# This returns an IMP hierarchy
67hier = s.build()
68
69# View your creation with this function
71
72
73# ############### AFTER BUILDING ###################
74# After building, only what you requested with add_representation()
75# can be selected
76
77# PMI selection
78# Most PMI functions will let you pass Molecules or TempResidues and it
79# will automatically gather things.
81 resolution=1)
82
83# Similarly for rigid body creation, we recommend passing PMI objects
84# and it will gather all resolutions
86dof.create_rigid_body(mol, nonrigid_parts=non_atomic,
87 resolution='all')
88
89# Advanced: IMP selection
90# Note if you request a resolution this will find the NEAREST available
91# resolution.
92# e.g. if only resolution 1 is built, those particles will be returned below:
93sel = IMP.atom.Selection(hier, resolution=10, molecule="Rpb4",
94 residue_indexes=range(1, 10))
95particles = sel.get_selected_particles()
96
97# Retrieving the molecule object
98# The molecules are stored within the state, so you can do :
99all_mol_copies = st.molecules["Rpb4"] # a list of all copies
100mol = all_mol_copies[0]
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Select hierarchy particles identified by the biological name.
Definition Selection.h:76
Simplify creation of constraints and movers for an IMP Hierarchy.
Create a restraint between consecutive TempResidue objects or an entire PMI Molecule object.
A dictionary-like wrapper for reading and storing sequence data.
Represent the root node of the global IMP.atom.Hierarchy.
Functionality for loading, creating, manipulating and scoring atomic structures.
void show_with_representations(Hierarchy h, std::ostream &out=std::cout)
Traverse through the tree and show atom info, including representations.
Create movers and set up constraints for PMI objects.
Protocols for sampling structures and analyzing them.
Definition macros.py:1
Restraints for keeping correct stereochemistry.
Classes to handle different kinds of restraints.
Set of Python classes to create a multi-state, multi-resolution IMP hierarchy.
Python classes to represent, score, sample and analyze models.
std::string get_example_path(std::string file_name)
Return the full path to one of this module's example files.
Support for the RMF file format for storing hierarchical molecular data and markup.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.