1 """@namespace IMP.pmi.restraints.em
2 Restraints for handling electron microscopy maps.
5 from __future__
import print_function
15 class GaussianEMRestraint(object):
17 def __init__(self, densities,
20 cutoff_dist_model_model=0.0,
21 cutoff_dist_model_data=0.0,
22 overlap_threshold=0.0,
23 target_mass_scale=1.0,
24 target_radii_scale=3.0,
25 model_radii_scale=1.0,
27 spherical_gaussians=
False,
28 pointwise_restraint=
False,
30 close_pair_container=
None,
32 scale_target_to_mass=
False,
43 self.sigmaissampled =
False
44 self.sigmamaxtrans = 0.3
49 self.densities = densities
52 self.m = self.densities[0].get_model()
53 if scale_target_to_mass:
55 print(
'will scale target mass by', target_mass_scale)
62 radius_scale=target_radii_scale,
63 mass_scale=target_mass_scale)
65 self.target_ps = target_ps
67 print(
'Gaussian EM restraint: must provide target density file or properly set up target densities')
72 for h
in self.densities:
74 if model_radii_scale != 1.0:
75 for p
in self.model_ps:
84 self.sigmaglobal = tools.SetupNuisance(self.m, self.sigmainit,
85 self.sigmamin, self.sigmamax,
86 self.sigmaissampled).get_particle()
89 print(
'target num particles', len(self.target_ps), \
91 for p
in self.target_ps]))
92 print(
'model num particles', len(self.model_ps), \
94 for p
in self.model_ps]))
96 update_model=
not spherical_gaussians
98 if not pointwise_restraint:
99 self.gaussianEM_restraint = \
101 IMP.get_indexes(self.model_ps),
102 IMP.get_indexes(self.target_ps),
103 self.sigmaglobal.get_particle().
get_index(),
104 cutoff_dist_model_model,
105 cutoff_dist_model_data,
107 update_model, backbone_slope)
109 print(
'USING POINTWISE RESTRAINT - requires isd_emxl')
111 print(
'update model?',update_model)
112 self.gaussianEM_restraint = \
113 IMP.isd_emxl.PointwiseGaussianEMRestraint(self.m,
114 IMP.get_indexes(self.model_ps),
115 IMP.get_indexes(self.target_ps),
116 self.sigmaglobal.get_particle().
get_index(),
117 cutoff_dist_model_model,
118 cutoff_dist_model_data,
122 close_pair_container)
124 print(
'done EM setup')
126 self.rs.add_restraint(self.gaussianEM_restraint)
127 self.set_weight(weight)
129 def center_target_density_on_model(self):
132 for p
in self.target_ps:
135 target_com += pos * mass
137 target_com /= target_mass
138 print(
'target com', target_com)
141 for p
in self.model_ps:
144 model_com += pos * mass
146 model_com /= model_mass
147 print(
'model com', model_com)
149 v = target_com - model_com
150 print(
'translating with', -v)
152 for p
in self.target_ps:
156 def center_model_on_target_density(self, representation):
159 for p
in self.target_ps:
162 target_com += pos * mass
164 target_com /= target_mass
165 print(
'target com', target_com)
168 for p
in self.model_ps:
171 model_com += pos * mass
173 model_com /= model_mass
174 print(
'model com', model_com)
176 v = target_com - model_com
177 print(
'translating with', v)
193 for rb
in list(rigid_bodies):
196 for p
in list(XYZRs):
200 def set_weight(self,weight):
202 self.rs.set_weight(weight)
204 def set_label(self, label):
207 def add_to_model(self):
208 self.m.add_restraint(self.rs)
210 def get_particles_to_sample(self):
212 if self.sigmaissampled:
213 ps[
"Nuisances_GaussianEMRestraint_sigma_" +
214 self.label] = ([self.sigmaglobal], self.sigmamaxtrans)
217 def get_hierarchy(self):
220 def get_density_as_hierarchy(self):
222 f.set_name(
"GaussianEMRestraint_density_"+self.label)
223 for p
in self.target_ps:
227 def get_restraint_set(self):
230 def get_output(self):
233 score = self.weight * self.rs.unprotected_evaluate(
None)
234 output[
"_TotalScore"] = str(score)
235 output[
"GaussianEMRestraint_" +
236 self.label] = str(score)
237 output[
"GaussianEMRestraint_sigma_" +
238 self.label] = str(self.sigmaglobal.get_scale())
242 return self.weight * self.rs.unprotected_evaluate(
None)
247 class ElectronMicroscopy2D(object):
256 self.m = representation.prot.get_model()
263 resolution=resolution)
266 self.rs.add_restraint(em2d)
268 def set_label(self, label):
271 def add_to_model(self):
272 self.m.add_restraint(self.rs)
274 def get_restraint(self):
277 def set_weight(self,weight):
279 self.rs.set_weigth(self.weight)
281 def get_output(self):
284 score = self.weight*self.rs.unprotected_evaluate(
None)
285 output[
"_TotalScore"] = str(score)
286 output[
"ElectronMicroscopy2D_" + self.label] = str(score)
A decorator to associate a particle with a part of a protein/DNA/RNA.
Ints get_index(const kernel::ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
Various classes to hold sets of particles.
double get_mass(ResidueType c)
Get the mass from the residue type.
Object used to hold a set of restraints.
Low level functionality (logging, error handling, profiling, command line flags etc) that is used by ...
static bool get_is_setup(const IMP::kernel::ParticleAdaptor &p)
static bool get_is_setup(const IMP::kernel::ParticleAdaptor &p)
static XYZR setup_particle(kernel::Model *m, ParticleIndex pi)
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.
Class to handle individual model particles.
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...
static bool get_is_setup(const IMP::kernel::ParticleAdaptor &p)
A decorator for a rigid body.
Functionality for loading, creating, manipulating and scoring atomic structures.
Hierarchies get_leaves(const Selection &h)
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.