IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
mGBP2_dimer_fp.py
1## \example bff/structure/mGBP2_dimer_fp.py
2"""
3Guanylate binding proteins: Combining restraints
4========================================
5This example illustrate modeling of the GDP-AlFx dimer
6of human guanylate binding protein 1 (hGBP1) by rigid
7bodies (RBs) in PMI. Note, this example serves illustration
8and not scientific purposes.
9"""
10# sphinx_gallery_thumbnail_path = 'img/example_structure_mgbp2_dimer_fp.png'
11
12import pathlib
13
14import IMP
15import IMP.core
16import IMP.atom
17
18import IMP.rmf
19
20import IMP.pmi
22import IMP.pmi.tools
24import IMP.pmi.dof
25import IMP.pmi.macros
26
27import IMP.bayesianem
28import IMP.bayesianem.restraint
34import sys
35try:
36 import scipy
37except ImportError:
38 print("To run this example, please first install the 'scipy'")
39 print("Python module.")
40 sys.exit(0)
41
42import IMP.bff
43import IMP.bff.tools
45
46IMP.setup_from_argv(sys.argv,
47 "Guanylate binding proteins: Combining restraints")
48if IMP.get_check_level() >= IMP.USAGE_AND_INTERNAL:
49 print("This example is too slow to test in debug mode - run without")
50 print("internal tests enabled")
51 sys.exit(0)
52if sys.maxsize <= 2**32:
53 print("This example uses too much memory to run well on a 32-bit system")
54 sys.exit(0)
55
56output_objects = list()
57root_dir = pathlib.Path(IMP.bff.get_example_path('structure')) / "GBP/"
58output_dir = root_dir / 'modeling/'
59
60# %%
61# System setup
62# -------------
63# The TopologyReader reads the text file, and the BuildSystem macro constructs it.
64# The RB decomposition of T4L is defined in the topology tile.
65mdl = IMP.Model()
66topol_fn = str(root_dir / 'mGBP2_FP_dimer.top.dat')
68 topol_fn,
69 pdb_dir=root_dir,
70 fasta_dir=root_dir
71)
72bs = IMP.pmi.macros.BuildSystem(mdl, resolutions=[1])
73
74# %%
75# note you can call this multiple times to create a multi-state system
76bs.add_state(reader)
77hier, dof = bs.execute_macro()
78state = hier.get_children()[0]
79mol = state.get_children()[0]
80rb = mol.get_children()[2]
81
82# %%
83# General restraints
84# ------------------
85# Connectivity keeps things connected along the backbone (ignores if inside same rigid body)
86crs = []
87moldict = bs.get_molecules()[0]
88mols = []
89for molname in moldict:
90 for mol in moldict[molname]:
93 cr.add_to_model()
94 output_objects.append(cr)
95 crs.append(cr)
96 mols.append(mol)
97
98# %%
99# Excluded volume - automatically more efficient due to rigid bodies
100ev_weight = 1.0
102evr.add_to_model()
103evr.set_weight(ev_weight)
104output_objects.append(evr)
105
106# # Restrain in sphere
107# barrier_restraint = IMP.pmi.restraints.basic.ExternalBarrier(hier, 200)
108# barrier_restraint.add_to_model()
109# output_objects.append(barrier_restraint)
110
111###############################
112# SAXS
113###############################
114# The SAXS restraint scores structures against the experimental
115# scattering curve. Computing the scattering curve is computaionally
116# costly. Thus, here for sampling the BayesianEM restraint is used
117# and where structures are scored against the
118use_saxs_density = False
119
120# %%
121#
122if use_saxs_density:
123 # FP not discriminated
124 saxs_file = str(root_dir / "saxs" / "hGBP1_dimer+GDPAlFx_dimer.dat")
125 molecules = list(bs.get_molecules()[0].values())
127 molecules, saxs_file, weight=1.0, ff_type=IMP.saxs.RESIDUES)
128 saxs_restraint.add_to_model()
129 output_objects.append(saxs_restraint)
130else:
131 # SAXS was without FP: only select protein
132 sel = IMP.atom.Selection(
133 hierarchy=hier, molecule="mGBP2_eGFP",
134 residue_indexes=range(261, 839),
135 representation_type=IMP.atom.DENSITIES
136 )
137 sel |= IMP.atom.Selection(
138 hierarchy=hier,
139 molecule="mGBP2_mCh",
140 residue_indexes=range(250, 827),
141 representation_type=IMP.atom.DENSITIES
142 )
143 target_gmm_file = str(root_dir / "saxs" / "SASDEG8.gmm.txt")
144 densities = sel.get_selected_particles()
146 densities,
147 target_fn=target_gmm_file,
148 scale_target_to_mass=True,
149 slope=0.01,
150 target_radii_scale=3.0,
151 target_is_rigid_body=True
152 )
153 gem.set_label("GaussianSAXS")
154 IMP.pmi.tools.add_restraint_to_model(mdl, gem.rs, True)
155 output_objects.append(gem)
156
157# ###############################
158# # XL-MS
159# ###############################
160# # Crosslinks - dataset
161# # These have a different format and label, but other settings are the same
162# xldbkwc = IMP.pmi.io.crosslink.CrossLinkDataBaseKeywordsConverter()
163# xldbkwc.set_protein1_key("Protein 1")
164# xldbkwc.set_protein2_key("Protein 2")
165# xldbkwc.set_residue1_key("Residue 1")
166# xldbkwc.set_residue2_key("Residue 2")
167# xldb = IMP.pmi.io.crosslink.CrossLinkDataBase(xldbkwc)
168# xldb.create_set_from_file(str(root_dir / 'xlinks.txt'))
169# xl = IMP.pmi.restraints.crosslinking.CrossLinkingMassSpectrometryRestraint(
170# root_hier=hier,
171# database=xldb,
172# length=21.0,
173# slope=0.01,
174# label="XL",
175# resolution=1.0,
176# linker=ihm.cross_linkers.bs3,
177# weight=1.
178# )
179# xl._include_in_rmf = True
180# xl.add_to_model()
181# output_objects.append(xl)
182#
183# %%
184# FRET restraint
185# --------------
186# The experimental information is contained in an ``fps.json`` file.
187# Fps.json files can contain multiple experimental distance dataset.
188# Different combinations of distances can be used for scoring. The set
189# of distances that is used for scoring needs to be specified. There are
190# two modes of operation of the PMI AV network restraint. The restraint
191# can operate on the mean position of AVs. If the restraint operates on
192# mean positions, the AV is treated as rigid body member and the distances
193# between the mean dye positions computed for the initial RB arrangement
194# are used for scoring (with the use of a transfer function). Otherwise,
195# the AVs are recalculated on each restraint evaluation.
196fps_json_fn = str(root_dir / "mGBP2_FP.fps.json")
197score_set = "577_577" # molecule in close c2, go from c2 -> open c1
198fret_restraint = IMP.bff.restraints.AVNetworkRestraintWrapper(
199 hier, fps_json_fn,
200 mean_position_restraint=True,
201 occupy_volume=False,
202 score_set=score_set
203)
205fret_restraint.add_to_model()
206output_objects.append(fret_restraint)
207
208# # %%
209# # Adds the AV to the atom Hierarchy to display the dye mean position:
210# used_avs = fret_restraint.av_network_restraint.get_used_avs()
211# IMP.bff.tools.display_mean_av_positions(used_avs)
212
213# %%
214# Sampling
215# --------
216# rbs, beads = IMP.pmi.tools.get_rbs_and_beads(hier)
217# # First shuffle the system
218# for state in bs.system.get_states():
219# IMP.pmi.tools.shuffle_configuration(state.get_hierarchy())
220# # Quickly move all flexible beads into place
221# dof.optimize_flexible_beads(100)
222
223# Monte carlo sampling. For better results increase the number of frames
224num_frames = 100000
226 num_frames = 10
227
229 mdl,
230 simulated_annealing=False,
231 root_hier=hier, # pass the root hierarchy
232 monte_carlo_sample_objects=dof.get_movers(), # pass MC movers
233 output_objects=output_objects,
234 monte_carlo_steps=10,
235 global_output_directory='./out/',
236 rmf_output_objects=None,
237 monte_carlo_temperature=1.0,
238 number_of_best_scoring_models=0, # set >0 to store best PDB files (but this is slow to do online)
239 number_of_frames=num_frames # increase number of frames to get better results!
240)
241rex.execute_macro()
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
Fit Gaussian-decorated particles to an EM map (also represented with a set of Gaussians).
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
Basic SAXS restraint.
Definition saxs.py:22
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.
IMP::bayesianem.restraint
Restraints for handling electron microscopy maps.
Utility functions.
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 handling cross-linking data.
Restraints for handling small angle x-ray (SAXS) data.
Definition saxs.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...
add_restraint_to_model(model, restraint, add_to_rmf=False)
Add a PMI restraint to the model.
Definition pmi/tools.py:89
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.
CheckLevel get_check_level()
Get the current audit mode.
Definition exception.h:80