1 """@namespace IMP.pmi.restraints.saxs
2 Restraints for handling small angle x-ray (SAXS) data.
5 from __future__
import print_function
13 class SAXSISDRestraint(object):
20 def __init__(self, representation, profile, resolution=0, weight=1,
21 ff_type=IMP.saxs.HEAVY_ATOMS):
23 self.m = representation.prot.get_model()
27 self.taumaxtrans = 0.05
32 resolution=resolution)
35 self.gamma = IMP.pmi.tools.SetupNuisance(
36 self.m, 1., 0.,
None,
False).get_particle()
39 self.sigma = IMP.pmi.tools.SetupNuisance(self.m, 10.0, 0.,
None,
False
43 self.tau = IMP.pmi.tools.SetupNuisance(self.m, 1., 0.,
None,
False,
47 self.c1 = IMP.pmi.tools.SetupNuisance(self.m, 1.0, 0.95, 1.05,
49 self.c2 = IMP.pmi.tools.SetupNuisance(self.m, 0.0, -2., 4.,
53 self.w = IMP.pmi.tools.SetupWeight(self.m).get_particle()
57 self.cov = [[1
if i == j
else 0
for j
in range(self.prof.size())]
58 for i
in range(self.prof.size())]
60 print(
"create saxs restraint")
61 self.saxs = IMP.isd2.SAXSRestraint(self.prof, self.sigma, self.tau,
62 self.gamma, self.w, self.c1, self.c2)
63 self.saxs.add_scatterer(self.atoms, self.cov, ff_type)
65 self.rs.add_restraint(self.saxs)
66 self.rs.set_weight(weight)
74 self.rs2.add_restraint(j1)
76 self.rs2.add_restraint(j2)
78 self.rs2.add_restraint(j3)
80 def optimize_sigma(self):
81 """set sigma to the value that maximizes its conditional likelihood"""
84 sigma2hat = self.saxs.get_sigmasq_scale_parameter() \
85 / (self.saxs.get_sigmasq_shape_parameter() + 1)
88 def optimize_gamma(self):
89 """set gamma to the value that maximizes its conditional likelihood"""
92 gammahat = exp(self.saxs.get_loggamma_variance_parameter()
93 * self.saxs.get_loggamma_jOg_parameter())
96 def logspace(self, a, b, num=100):
97 """mimick numpy's logspace function"""
99 val = a + float(b - a) / float(num - 1) * i
102 def optimize_tau(self, ltaumin=-2, ltaumax=3, npoints=100):
108 fl = open(
'tauvals.txt',
'w')
109 for tauval
in self.logspace(ltaumin, ltaumax, npoints):
112 values.append((self.m.evaluate(
False), tauval))
115 fl.write(
'%G %G\n' % (values[-1][1], values[-1][0]))
117 ltcenter = log(values[0][1]) / log(10)
118 spacing = (ltaumax - ltaumin) / float(npoints)
120 for tauval
in self.logspace(
121 ltcenter - 2 * spacing, ltcenter + 2 * spacing,
124 values.append((self.m.evaluate(
False), tauval))
125 fl.write(
'%G %G\n' % (values[-1][1], values[-1][0]))
129 def draw_sigma(self):
130 """draw 1/sigma2 from gamma distribution"""
132 self.saxs.draw_sigma()
134 def draw_gamma(self):
135 """draw gamma from lognormal distribution"""
137 self.saxs.draw_gamma()
139 def update_covariance_matrix(self):
144 self.cov = IMP.isd2.compute_relative_covariance(self.atoms, c1, c2,
149 self.saxs.set_cov(0, self.cov)
151 def write_covariance_matrix(self, fname):
152 fl = open(fname,
'w')
153 for line
in self.cov:
158 def get_gamma_value(self):
159 return self.gamma.get_scale()
161 def set_label(self, label):
164 def add_to_model(self):
168 def set_taumaxtrans(self, taumaxtrans):
169 self.taumaxtrans = taumaxtrans
171 def get_particles_to_sample(self):
177 def get_output(self):
180 score = self.rs.unprotected_evaluate(
None)
181 score2 = self.rs2.unprotected_evaluate(
None)
182 output[
"_TotalScore"] = str(score + score2)
184 output[
"SAXSISDRestraint_Likelihood_" + self.label] = str(score)
185 output[
"SAXSISDRestraint_Prior_" + self.label] = str(score2)
186 output[
"SAXSISDRestraint_Sigma_" +
187 self.label] = str(self.sigma.get_scale())
188 output[
"SAXSISDRestraint_Tau_" +
189 self.label] = str(self.tau.get_scale())
190 output[
"SAXSISDRestraint_Gamma_" +
191 self.label] = str(self.gamma.get_scale())
Add weights for a set of states to a particle.
Various classes to hold sets of particles.
void write_pdb(const Selection &mhd, TextOutput out, unsigned int model=1)
Add scale parameter to particle.
Object used to hold a set of restraints.
Add nuisance parameter to particle.
Basic functionality that is expected to be used by a wide variety of IMP users.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
Functionality for loading, creating, manipulating and scoring atomic structures.
Support for small angle X-ray scattering (SAXS) data.
Inferential scoring building on methods developed as part of the Inferential Structure Determination ...