IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
t4l_pmi.py
1## \example bff/structure/T4L.py
2"""
3T4 lysozyme: Using PMI
4======================
5T4 lysozme
6
7This example illustrate modeling of by rigid bodies (RBs) in PMI.
8Note, this example serves illustration and not scientific purposes.
9"""
10# sphinx_gallery_thumbnail_path = 'img/example_structure_t4l.png'
11
12import sys
13import pathlib
14
15import IMP
16import IMP.core
17import IMP.atom
18import IMP.bff
19try:
20 import scipy
21except ImportError:
22 print("To run this example, please first install the 'scipy'")
23 print("Python module.")
24 sys.exit(0)
25import IMP.bff.tools
27
28import IMP.rmf
29import IMP.pmi
30import IMP.pmi.tools
32import IMP.pmi.dof
33import IMP.pmi.macros
37
38IMP.setup_from_argv(sys.argv, "Simulation of an atomic T4L system")
40 print("This example is too slow to test in debug mode - run without")
41 print("internal tests enabled, or without the --run-quick-test flag")
42 sys.exit(0)
43
44
45output_objects = list()
46root_dir = pathlib.Path(IMP.bff.get_example_path('structure')) / "T4L/"
47output_dir = root_dir / 'modeling/'
48
49# %%
50# System setup
51# -------------
52# The TopologyReader reads the text file, and the BuildSystem macro constructs it.
53# The RB decomposition of T4L is defined in the topology tile.
54mdl = IMP.Model()
55topol_fn = str(root_dir / 'topology.dat')
57 topol_fn,
58 pdb_dir=root_dir,
59 fasta_dir=root_dir
60)
61bs = IMP.pmi.macros.BuildSystem(mdl, resolutions=[1])
62
63# %%
64# note you can call this multiple times to create a multi-state system
65bs.add_state(reader)
66hier, dof = bs.execute_macro()
67state = hier.get_children()[0]
68mol = state.get_children()[0]
69rb = mol.get_children()[2]
70
71# %%
72# General restraints
73# --------------------
74# Connectivity keeps things connected along the backbone (ignores if inside same rigid body)
75crs = []
76moldict = bs.get_molecules()[0]
77mols = []
78for molname in moldict:
79 for mol in moldict[molname]:
82 cr.add_to_model()
83 output_objects.append(cr)
84 crs.append(cr)
85 mols.append(mol)
86
87# %%
88# Restrain in sphere
89barrier_restraint = IMP.pmi.restraints.basic.ExternalBarrier(hier, 30)
90barrier_restraint.add_to_model()
91output_objects.append(barrier_restraint)
92
93# %%
94# FRET restraint
95# --------------
96# The experimental information is contained in an ``fps.json`` file.
97# Fps.json files can contain multiple experimental distance dataset.
98# Different combinations of distances can be used for scoring. The set
99# of distances that is used for scoring needs to be specified. There are
100# two modes of operation of the PMI AV network restraint. The restraint
101# can operate on the mean position of AVs. If the restraint operates on
102# mean positions, the AV is treated as rigid body member and the distances
103# between the mean dye positions computed for the initial RB arrangement
104# are used for scoring (with the use of a transfer function). Elsewise,
105# the AVs are recalculated on each restraint evaluation.
106fps_json_fn = str(root_dir / "fret.fps.json")
107score_set = "chi2_C3" # molecule in close c2, go from c2 -> open c1
108fret_restraint = IMP.bff.restraints.AVNetworkRestraintWrapper(
109 hier, fps_json_fn,
110 mean_position_restraint=True,
111 occupy_volume=True,
112 score_set=score_set
113)
114fret_restraint.add_to_model()
115output_objects.append(fret_restraint)
116
117# %%
118# Excluded volume - automatically more efficient due to rigid bodies
119# Note: add after AV restraint if the dyes should occupy some volume
120ev_weight = 1.0
122evr.add_to_model()
123evr.set_weight(ev_weight)
124output_objects.append(evr)
125
126
127# %%
128# Adds the AV to the atom Hierarchy to display the dye mean position:
129used_avs = fret_restraint.av_network_restraint.get_used_avs()
131
132# %%
133# Sampling
134# --------
135# First shuffle the system
136for state in bs.system.get_states():
137 IMP.pmi.tools.shuffle_configuration(state.get_hierarchy(), max_translation=10)
138# Quickly move all flexible beads into place
139dof.optimize_flexible_beads(10)
140
141# %%
142# Monte carlo sampling. For better results increase the number of frames
143num_frames = 1000
145 mdl,
146 simulated_annealing=False,
147 root_hier=hier, # pass the root hierarchy
148 monte_carlo_sample_objects=dof.get_movers(), # pass MC movers
149 output_objects=output_objects,
150 monte_carlo_steps=100,
151 global_output_directory='./out/',
152 rmf_output_objects=None,
153 monte_carlo_temperature=1.0,
154 number_of_best_scoring_models=0, # set >0 to store best PDB files (but this is slow to do online)
155 number_of_frames=num_frames # increase number of frames to get better results!
156)
157rex.execute_macro()
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
A macro to build a IMP.pmi.topology.System based on a TopologyReader object.
Definition macros.py:840
A macro to help setup and run replica exchange.
Definition macros.py:164
Keeps all structures inside a sphere.
Definition basic.py:15
Create a restraint between consecutive TempResidue objects or an entire PMI Molecule object.
A class to create an excluded volume restraint for a set of particles at a given resolution.
Automatically setup System and Degrees of Freedom with a formatted text file.
Functionality for loading, creating, manipulating and scoring atomic structures.
Utility functions.
display_mean_av_positions(used_avs, dye_radius=3.5)
Decorate the accessible volume particles with a mass and radii, so that they appear in the rmf file.
Bayesian Fluorescence Framework.
std::string get_example_path(std::string file_name)
Return the full path to one of this module's example files.
Basic functionality that is expected to be used by a wide variety of IMP users.
Create movers and set up constraints for PMI objects.
Protocols for sampling structures and analyzing them.
Definition macros.py:1
Some miscellaneous simple restraints.
Definition basic.py:1
Restraints for keeping correct stereochemistry.
Classes to handle different kinds of restraints.
Miscellaneous utilities.
Definition pmi/tools.py:1
display_bonds(mol)
Decorate the sequence-consecutive particles from a PMI2 molecule with a bond, so that they appear con...
shuffle_configuration(objects, max_translation=300.0, max_rotation=2.0 *math.pi, avoidcollision_rb=True, avoidcollision_fb=False, cutoff=10.0, niterations=100, bounding_box=None, excluded_rigid_bodies=[], hierarchies_excluded_from_collision=[], hierarchies_included_in_collision=[], verbose=False, return_debug=False)
Shuffle particles.
Set of Python classes to create a multi-state, multi-resolution IMP hierarchy.
Python classes to represent, score, sample and analyze models.
Support for the RMF file format for storing hierarchical molecular data and markup.
bool get_is_quick_test()
Definition flags.h:183
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.