IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
plot_AVNetworkRestraint.py
1"""
2Accessible Volume Restraint
3===========================
4Accessible volume (AV) restraints can be used for integrative modeling and for
5scoring structures. There are two versions of AV restraints ``IMP.bff.AVNetworkRestraint``
6and ``IMP.bff.restraints.AVNetworkRestraintWrapper``. The AV restraint wrapped for PMI,
7``AVNetworkRestraintWrapper`` provides a mean dye positions, an approximation that
8is faster when working with rigid bodies.
9
10In this example a T4 lysozme structure is loaded and scored using ``IMP.bff.AVNetworkRestraint``
11by experimental data in a fps.json file.
12"""
13
14# %%
15# First import all necessary libraries.
16import pathlib
17import json
18
19import numpy as np
20import pylab as plt
21
22import IMP
23import IMP.rmf
24import IMP.atom
25import IMP.bff
26
27
28# %%
29# Create a model and populate a ``IMP.Hierarchy``.
30m = IMP.Model()
31pdb_fn = pathlib.Path(IMP.bff.get_example_path('structure')) / "T4L/3GUN.pdb"
32hier = IMP.atom.read_pdb(str(pdb_fn), m)
33
34
35# %%
36# The AV network restraint takes a fps.json file as an input.
37# fps.json files can contain multiple sets of distances for scoring
38# structures.
39fps_json_path = IMP.bff.get_example_path("structure/T4L/fret.fps.json")
40with open(fps_json_path) as fp:
41 fps_json = json.load(fp)
42
43score_set_c1 = "chi2_C2_33p"
44fret_restraint = IMP.bff.AVNetworkRestraint(hier, str(fps_json_path), score_set=score_set_c1)
45
46# %%
47# The score is computed
48v = fret_restraint.unprotected_evaluate(None)
49print("Score: {:.1f}".format(v))
50
51# %%
52# The computed model distances and the experimental distances contained ``IMP.bff.AVNetworkRestraint``
53# objects can be accesses as follows, e.g., to identify outliers.
54experimental_distances = fret_restraint.get_used_distances()
55
56model = list()
57experiment = list()
58for key in experimental_distances:
59 e_dist = experimental_distances[key]
60 d = json.loads(e_dist.get_json())
61 model_distance = fret_restraint.get_model_distance(
62 d["position1_name"],
63 d["position2_name"],
64 d["Forster_radius"],
65 d["distance_type"]
66 )
67 e_dist.score_model(model_distance)
68 model.append(model_distance)
69 experiment.append(d['distance'])
70
71# %%
72# Plot the experiment against the model distance
73x = np.linspace(25, 60)
74plt.plot(model, experiment, "o")
75plt.plot(x, x, "-")
76plt.xlabel("Model distance [Ang.]")
77plt.ylabel("Experimental distance [Ang.]")
78print("See plot.png for experiment against model distance")
79plt.savefig('plot.png')
80#plt.show()
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
A restraint that uses an annotated volumetric network to score particle distances.
Functionality for loading, creating, manipulating and scoring atomic structures.
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.
Bayesian Fluorescence Framework.
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.