1 """@namespace IMP.pmi.restraints.em
2 Restraints for handling electron microscopy maps.
5 from __future__
import print_function
14 class GaussianEMRestraint(object):
16 def __init__(self, densities,
19 cutoff_dist_model_model=0.0,
20 cutoff_dist_model_data=0.0,
21 overlap_threshold=0.0,
22 target_mass_scale=1.0,
23 target_radii_scale=3.0,
24 model_radii_scale=1.0,
26 spherical_gaussians=
False,
27 pointwise_restraint=
False,
29 close_pair_container=
None,
31 scale_target_to_mass=
False,
42 self.sigmaissampled =
False
43 self.sigmamaxtrans = 0.3
48 self.densities = densities
51 self.m = self.densities[0].get_model()
52 if scale_target_to_mass:
54 print(
'will scale target mass by', target_mass_scale)
61 radius_scale=target_radii_scale,
62 mass_scale=target_mass_scale)
64 self.target_ps = target_ps
66 print(
'Gaussian EM restraint: must provide target density file or properly set up target densities')
71 for h
in self.densities:
73 if model_radii_scale != 1.0:
74 for p
in self.model_ps:
83 self.sigmaglobal = tools.SetupNuisance(self.m, self.sigmainit,
84 self.sigmamin, self.sigmamax,
85 self.sigmaissampled).get_particle()
88 print(
'target num particles', len(self.target_ps), \
90 for p
in self.target_ps]))
91 print(
'model num particles', len(self.model_ps), \
93 for p
in self.model_ps]))
95 update_model=
not spherical_gaussians
97 if not pointwise_restraint:
98 self.gaussianEM_restraint = \
102 self.sigmaglobal.get_particle().
get_index(),
103 cutoff_dist_model_model,
104 cutoff_dist_model_data,
106 update_model, backbone_slope)
108 print(
'USING POINTWISE RESTRAINT - requires isd_emxl')
110 print(
'update model?',update_model)
111 self.gaussianEM_restraint = \
112 IMP.isd_emxl.PointwiseGaussianEMRestraint(self.m,
115 self.sigmaglobal.get_particle().
get_index(),
116 cutoff_dist_model_model,
117 cutoff_dist_model_data,
121 close_pair_container)
123 print(
'done EM setup')
125 self.rs.add_restraint(self.gaussianEM_restraint)
126 self.set_weight(weight)
128 def center_target_density_on_model(self):
131 for p
in self.target_ps:
134 target_com += pos * mass
136 target_com /= target_mass
137 print(
'target com', target_com)
140 for p
in self.model_ps:
143 model_com += pos * mass
145 model_com /= model_mass
146 print(
'model com', model_com)
148 v = target_com - model_com
149 print(
'translating with', -v)
151 for p
in self.target_ps:
155 def center_model_on_target_density(self, representation):
158 for p
in self.target_ps:
161 target_com += pos * mass
163 target_com /= target_mass
164 print(
'target com', target_com)
167 for p
in self.model_ps:
170 model_com += pos * mass
172 model_com /= model_mass
173 print(
'model com', model_com)
175 v = target_com - model_com
176 print(
'translating with', v)
192 for rb
in list(rigid_bodies):
195 for p
in list(XYZRs):
199 def set_weight(self,weight):
201 self.rs.set_weight(weight)
203 def set_label(self, label):
206 def add_to_model(self):
209 def get_particles_to_sample(self):
211 if self.sigmaissampled:
212 ps[
"Nuisances_GaussianEMRestraint_sigma_" +
213 self.label] = ([self.sigmaglobal], self.sigmamaxtrans)
216 def get_hierarchy(self):
219 def get_density_as_hierarchy(self):
221 f.set_name(
"GaussianEMRestraint_density_"+self.label)
222 for p
in self.target_ps:
226 def get_restraint_set(self):
229 def get_output(self):
232 score = self.weight * self.rs.unprotected_evaluate(
None)
233 output[
"_TotalScore"] = str(score)
234 output[
"GaussianEMRestraint_" +
235 self.label] = str(score)
236 output[
"GaussianEMRestraint_sigma_" +
237 self.label] = str(self.sigmaglobal.get_scale())
241 return self.weight * self.rs.unprotected_evaluate(
None)
246 class ElectronMicroscopy2D(object):
255 self.m = representation.prot.get_model()
262 resolution=resolution)
265 self.rs.add_restraint(em2d)
267 def set_label(self, label):
270 def add_to_model(self):
273 def get_restraint(self):
276 def set_weight(self,weight):
278 self.rs.set_weigth(self.weight)
280 def get_output(self):
283 score = self.weight*self.rs.unprotected_evaluate(
None)
284 output[
"_TotalScore"] = str(score)
285 output[
"ElectronMicroscopy2D_" + self.label] = str(score)
A decorator to associate a particle with a part of a protein/DNA/RNA.
Various classes to hold sets of particles.
static XYZR setup_particle(Model *m, ParticleIndex pi)
double get_mass(ResidueType c)
Get the mass from the residue type.
static bool get_is_setup(const IMP::ParticleAdaptor &p)
static bool get_is_setup(const IMP::ParticleAdaptor &p)
Object used to hold a set of restraints.
ParticleIndexPairs get_indexes(const ParticlePairsTemp &ps)
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
void transform(XYZ a, const algebra::Transformation3D &tr)
Apply a transformation to the particle.
Creates a restraint between two Gaussian Mixture Models, "model" and "density".
A decorator for a particle with x,y,z coordinates.
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...
Class to handle individual model particles.
A decorator for a rigid body.
Functionality for loading, creating, manipulating and scoring atomic structures.
Hierarchies get_leaves(const Selection &h)
static bool get_is_setup(const IMP::ParticleAdaptor &p)
Inferential scoring building on methods developed as part of the Inferential Structure Determination ...
A decorator for a particle with x,y,z coordinates and a radius.