IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
plot_AVDecorator.py
1"""
2Accessible volume decorator
3===========================
4IMP particles can be decorated with accessible volume (AV)
5decorators to compute the sterically allowed volume of a
6label around its attachment site, i.e., the decorated IMP
7particle.
8
9The AV decorator uses the Dijkstra's algorithm to compute
10all path from the attachment site to a set of grid points
11around the attachment site. The AV decorator uses the
12``IMP.bff.PathMap`` class for computing the AV. The occupied
13volume of leaves in a molecular hierarchy serve as obstacles
14in the path search.
15"""
16import pathlib
17import numpy as np
18import pylab as plt
19
20import IMP
21import IMP.core
22import IMP.atom
23import IMP.em
24import IMP.bff
25
26# %%
27# Setup Model
28# -----------
29m = IMP.Model()
30pdb_fn = pathlib.Path(IMP.bff.get_example_path('structure')) / "T4L/3GUN.pdb"
31hier = IMP.atom.read_pdb(str(pdb_fn), m)
32
33# %%
34# Decorate particle
35# -----------------
36# Any particle can be decorated by AVs. The location of the AV particle is changed by AV
37# calculation to the mean position of the AV. Thus, better create a new particle that will
38# be decorated with an AV.
39av_p = IMP.Particle(m)
40# %%
41# An AV has a source, i.e., the labeling site and a set of parameters that determine the
42# shape of the AV. We select
43residue_index = 132
44atom_name = "CB"
45sel = IMP.atom.Selection(hier)
46sel.set_atom_type(IMP.atom.AtomType(atom_name))
47sel.set_residue_index(residue_index)
48source = sel.get_selected_particles()[0]
49av_parameter = {
50 "linker_length": 20.0,
51 "radii": (3.5, 0.0, 0.0),
52 "linker_width": 0.5,
53 "allowed_sphere_radius": 2.0,
54 "contact_volume_thickness": 0.0,
55 "contact_volume_trapped_fraction": -1,
56 "simulation_grid_resolution": 0.5
57}
58IMP.bff.AV.do_setup_particle(m, av_p, source, **av_parameter)
59av1 = IMP.bff.AV(m, av_p)
60
61# %%
62# The coordinates of an AV are the mean AV the density map. Thus, the position of the
63# AV changes when the AV is resampled.
64av_xyz = IMP.core.XYZ(av1)
65# av_mp == (0,0,0)
66av1.resample() # Updates the AV
67# av_xyz == (-1.46132, -25.366, -6.04022)
68
69# %%
70# Access AV features
71# ------------------
72# AV decorated particles use PathMaps to sample the accessible volume.
73# Thus, features of the AV are accessed through PathMap. The features can
74# be written to density maps (see: PathMapTile). PathMaps derive from
75# IMP EM density maps and sampled obstacles can be written to density files
76# using standard IMP methods.
77av_map = av1.get_map()
78bounds = 0.01, 20
79# write to map
80#IMP.em.write_map(av_map, "OBSTACLES.mrc")
81
82# %%
83# Features of a IMP.bff.PathMap are identified by the following constants
84pm_features = [
85 IMP.bff.PM_TILE_PENALTY, # Penalty of visiting a tile
86 IMP.bff.PM_TILE_COST, # Cost of a path to the tile
87 IMP.bff.PM_TILE_DENSITY, # Density of tile
88 IMP.bff.PM_TILE_COST_DENSITY, # Cost * Density of tile
89 IMP.bff.PM_TILE_PATH_LENGTH, # Path length to tile (cost * grid spacing)
90 IMP.bff.PM_TILE_PATH_LENGTH_DENSITY, # Path length to tile * density
91 IMP.bff.PM_TILE_FEATURE, # Additional feature of tile (accessed by name)
92 IMP.bff.PM_TILE_ACCESSIBLE_DENSITY, # Density of tiles with path length in bounds
93 IMP.bff.PM_TILE_ACCESSIBLE_FEATURE # Feature of tile with path length in bounds
94]
95
96# %%
97# These features can be written to density maps
98
99
100# IMP.bff.write_path_map(
101# av_map, "BFF_TILE_PENALTY.mrc",
102# IMP.bff.PM_TILE_PENALTY,
103# (0, 1)
104# )
105
106# PM_TILE_PATH_LENGTH_WEIGHT : filter by path length and write tile weight
107# IMP.bff.write_path_map(
108# av_map, "PM_TILE_PATH_LENGTH.mrc",
109# IMP.bff.PM_TILE_PATH_LENGTH,
110# bounds
111# )
112
113# IMP.bff.write_path_map(
114# av_map, "PM_TILE_PATH_LENGTH_DENSITY_132.mrc",
115# IMP.bff.PM_TILE_PATH_LENGTH_DENSITY,
116# bounds
117# )
118
119# IMP.bff.write_path_map(
120# av_map, "PM_TILE_ACCESSIBLE_DENSITY.mrc",
121# IMP.bff.PM_TILE_ACCESSIBLE_DENSITY,
122# bounds
123# )
124
125# %%
126# Measure AV/AV-distance
127# ----------------------
128#
129residue_index = 55
130sel = IMP.atom.Selection(hier)
131sel.set_atom_type(IMP.atom.AtomType("CB"))
132sel.set_residue_index(residue_index)
133p = sel.get_selected_particles()[0]
134av_p2 = IMP.Particle(m)
135IMP.bff.AV.do_setup_particle(m, av_p2, p, **av_parameter)
136av2 = IMP.bff.AV(av_p2)
137v = IMP.bff.av_distance(av1, av2)
138print(v)
139
140# %%
141# Distance types
142# --------------
143distance_types = [
144 IMP.bff.DYE_PAIR_DISTANCE_E, # Mean FRET averaged distance R_E
145 IMP.bff.DYE_PAIR_DISTANCE_MEAN, # Mean distance <R_DA>
146 IMP.bff.DYE_PAIR_DISTANCE_MP, # Distance between AV mean positions
147 IMP.bff.DYE_PAIR_EFFICIENCY, # Mean FRET efficiency
148 IMP.bff.DYE_PAIR_DISTANCE_DISTRIBUTION, # (reserved for Distance distributions)
149 IMP.bff.DYE_PAIR_XYZ_DISTANCE # Distance between XYZ of dye particles
150]
151
152forster_radius = 52.0 # Optional (default 52.0)
153n_samples = 20000 # Optional (default 10000)
154fret_efficiency = IMP.bff.av_distance(
155 av1, av2,
156 forster_radius=forster_radius,
157 distance_type=IMP.bff.DYE_PAIR_EFFICIENCY,
158 n_samples=n_samples
159)
160distance_fret = IMP.bff.av_distance(
161 av1, av2,
162 forster_radius,
163 IMP.bff.DYE_PAIR_DISTANCE_E,
164 n_samples
165)
166mean_inter_dye_distance = IMP.bff.av_distance(av1, av2, distance_type=IMP.bff.DYE_PAIR_DISTANCE_MEAN)
167print("Mean FRET efficiency : {:.2f}".format(fret_efficiency))
168print("Distance FRET : {:.1f}".format(distance_fret))
169print("Mean inter-dye distance: {:.1f}".format(mean_inter_dye_distance))
170print("Distance mean position : {:.1f}".format(IMP.bff.av_distance(av1, av2, IMP.bff.DYE_PAIR_DISTANCE_MP)))
171
172# %%
173# Distance distribution between two AVs
174rda_start, rda_stop, n_bins = 0, 100, 128
175n_samples = 10000
176rda = np.linspace(rda_start, rda_stop, n_bins)
177p_rda = IMP.bff.av_distance_distribution(av1, av2, rda, n_samples=n_samples)
178plt.plot(rda, p_rda)
179print("See plot.png for the distance distribution between two AVs")
180plt.savefig('plot.png')
181#plt.show()
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Class to handle individual particles of a Model object.
Definition Particle.h:45
Select hierarchy particles identified by the biological name.
Definition Selection.h:76
A decorator for a particle with accessible volume (AV).
Definition AV.h:94
static void do_setup_particle(Model *m, ParticleIndex pi, ParticleIndex pi_source, double linker_length=20.0, const algebra::Vector3D radii=algebra::Vector3D(3.5, 0, 0), double linker_width=0.5, double allowed_sphere_radius=1.5, double contact_volume_thickness=0.0, double contact_volume_trapped_fraction=-1, double simulation_grid_resolution=1.5)
Sets up the attributes for a particle in a model for AV (Anisotropic Volume) calculations.
Definition AV.h:181
A decorator for a particle with x,y,z coordinates.
Definition XYZ.h:30
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::vector< double > av_distance_distribution(const AV &av1, const AV &av2, std::vector< double > axis, int n_samples=10000)
Compute the distance to another accessible volume.
std::string get_example_path(std::string file_name)
Return the full path to one of this module's example files.
double av_distance(const AV &a, const AV &b, double forster_radius=52.0, int distance_type=DYE_PAIR_DISTANCE_MEAN, int n_samples=10000)
Computes the distance to another accessible volume.
Basic functionality that is expected to be used by a wide variety of IMP users.
Basic utilities for handling cryo-electron microscopy 3D density maps.