IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
profile_fit.py
1## \example saxs/profile_fit.py
2# In this example, we read a protein from a PDB file and experimental profile
3# file. Next we compute the theoretical profile from the PDB file and fit it
4# to the experimental one. Unlike in profile.py example, here we fit the
5# profile with adjustment of the excluded volume and hydration layer density
6# of the molecule.
7#
8# This application is available as a web service at salilab.org/foxs. It is
9# also available as C++ code in IMP at modules/foxs/bin/foxs.cpp.
10#
11# The experimental data for lysozyme is taken from crysol program
12# (www.embl-hamburg.de/ExternalInfo/Research/Sax/crysol.html)
13#
14
15import IMP
16import IMP.atom
17import IMP.core
18import IMP.saxs
19import sys
20
21IMP.setup_from_argv(sys.argv, "profile fit")
22
23m = IMP.Model()
24
25# read PDB
28
29# read experimental profile
30exp_profile = IMP.saxs.Profile(IMP.saxs.get_example_path('lyzexp.dat'))
31
32print('min_q = ' + str(exp_profile.get_min_q()))
33print('max_q = ' + str(exp_profile.get_max_q()))
34print('delta_q = ' + str(exp_profile.get_delta_q()))
35
36# select particles from the model
37particles = IMP.atom.get_by_type(mp, IMP.atom.ATOM_TYPE)
38
39# add radius for water layer computation
41for i in range(0, len(particles)):
42 radius = ft.get_radius(particles[i])
43 IMP.core.XYZR.setup_particle(particles[i], radius)
44# compute surface accessibility
46surface_area = s.get_solvent_accessibility(IMP.core.XYZRs(particles))
47
48# calculate SAXS profile
49delta_q = 0.5 / 500
50model_profile = IMP.saxs.Profile(0.0, 0.5, delta_q)
51model_profile.calculate_profile_partial(particles, surface_area)
52# model_profile.write_SAXS_file('6lyz.dat')
53
54# calculate chi-square score (should be ~0.25 for this example)
55saxs_score = IMP.saxs.ProfileFitterChi(exp_profile)
56chi = saxs_score.compute_score(model_profile)
57print('Chi without parameter fitting = ' + str(chi))
58
59chi = (saxs_score.fit_profile(model_profile)).get_chi_square()
60print('Chi after adjustment of excluded volume and water layer parameters = '
61 + str(chi))
62saxs_score.fit_profile(model_profile, 0.95, 1.05, -2.0, 4.0, False,
63 '6lyz_fitted.dat')
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Hierarchies get_by_type(Hierarchy mhd, GetByType t)
Gather all the molecular particles of a certain level in the hierarchy.
Select non water and non hydrogen atoms.
Definition pdb.h:320
static XYZR setup_particle(Model *m, ParticleIndex pi)
Definition XYZR.h:48
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.
Basic functionality that is expected to be used by a wide variety of IMP users.
Support for small angle X-ray scattering (SAXS) data.
FormFactorTable * get_default_form_factor_table()
std::string get_example_path(std::string file_name)
Return the full path to one of this module's example files.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.