1 """@namespace IMP.pmi.restraints.em2d
2 Restraints for handling electron microscopy images.
5 from __future__
import print_function
16 """Fit particles against a set of class averages by principal components.
17 Compares how well the principal components of the segmented class
18 average fit to the principal components of the particles.
20 def __init__(self, hier, images, pixel_size, image_resolution,
21 projection_number, resolution, micrographs_number=
None,
24 @param hier The root hierarchy for applying the restraint
25 @param images 2D class average filenames in PGM text format
26 @param pixel_size Pixel size in angstroms
27 @param image_resolution Estimated resolution of the images
29 @param projection_number Number of projections of the model
30 to generate and fit to images. The lower the number, the
31 faster the evaluation, but the lower the accuracy
32 @param resolution Which level of
33 [model representation](@ref pmi_resolution) to use in the fit
34 @param micrographs_number Number of micrograph particles that
35 were used to generate the class averages, if known
36 @param n_components Number of the largest components to be
37 considered for the EM image
44 loc = ihm.location.InputFileLocation(
45 image, details=
"Electron microscopy class average")
46 d = ihm.dataset.EM2DClassDataset(loc)
47 self.datasets.append(d)
49 for p, state
in IMP.pmi.tools._all_protocol_outputs(hier):
50 for i
in range(len(self.datasets)):
51 p.add_em2d_restraint(state, self, i, resolution, pixel_size,
52 image_resolution, projection_number,
56 self.m = hier.get_model()
58 hier, resolution=resolution).get_selected_particles()
71 particles, images, pixel_size, image_resolution,
72 projection_number,
True, n_components)
75 particles, images, pixel_size, image_resolution,
76 projection_number,
True)
77 self._em2d_restraint = em2d
78 self._num_images = len(images)
79 self.rs.add_restraint(em2d)
81 def set_label(self, label):
84 def add_to_model(self):
87 def get_restraint(self):
90 def set_weight(self, weight):
92 self.rs.set_weight(self.weight)
96 score = self.weight*self.rs.unprotected_evaluate(
None)
97 output[
"_TotalScore"] = str(score)
98 output[
"ElectronMicroscopy2D_" + self.label] = str(score)
101 for i
in range(self._num_images):
102 prefix =
'ElectronMicroscopy2D_%s_Image%d' % (self.label, i+1)
103 ccc = self._em2d_restraint.get_cross_correlation_coefficient(i)
104 output[prefix +
'_CCC'] = str(ccc)
105 tran = self._em2d_restraint.get_transformation(i)
106 r = tran.get_rotation().get_quaternion()
107 t = tran.get_translation()
109 output[prefix +
'_Rotation%d' % j] = str(r[j])
111 output[prefix +
'_Translation%d' % j] = str(t[j])
116 """FFT based image alignment, developed by Javier Velazquez-Muriel"""
117 def __init__(self, hier, images=None, pixel_size=None,
118 image_resolution=
None, projection_number=
None,
121 @param hier The root hierarchy for applying the restraint
122 @param images SPIDER FORMAT images (format conversion should be done
124 @param pixel_size sampling rate of the available EM images (angstroms)
125 @param image_resolution resolution at which you want to generate the
126 projections of the model. In principle you want "perfect"
127 projections, so use the highest resolution
128 @param projection_number Number of projections of the model (coarse
129 registration) to estimate the registration parameters
130 @param resolution Which level of
131 [model representation](@ref pmi_resolution) to use in the fit
132 @param n_components Number of the largest components to be
133 considered for the EM image
140 raise Exception(
"EM2D_FFT: must pass images")
141 if pixel_size
is None:
142 raise Exception(
"EM2D_FFT: must pass pixel size")
143 if image_resolution
is None:
144 raise Exception(
"EM2D_FFT: must pass image resolution")
145 if projection_number
is None:
146 raise Exception(
"EM2D_FFT: must pass projection_number")
149 self.m = hier.get_model()
151 hier, resolution=resolution).get_selected_particles()
162 pixel_size, image_resolution, projection_number)
166 params.coarse_registration_method = IMP.em2d.ALIGN2D_PREPROCESSING
167 params.optimization_steps = 50
168 params.simplex_initial_length = 0.1
169 params.simplex_minimum_size = 0.02
173 params.save_match_images =
False
180 em2d_restraint.setup(score_function, params)
181 em2d_restraint.set_images(imgs)
182 em2d_restraint.set_fast_mode(5)
183 em2d_restraint.set_name(
"em2d_restraint")
185 print(
"len(particles) = ", len(particles))
187 em2d_restraint.set_particles(container)
189 self.rs.add_restraint(em2d_restraint)
191 def set_label(self, label):
194 def add_to_model(self):
197 def get_restraint(self):
200 def set_weight(self, weight):
202 self.rs.set_weight(self.weight)
204 def get_output(self):
206 score = self.weight*self.rs.unprotected_evaluate(
None)
207 output[
"_TotalScore"] = str(score)
208 output[
"ElectronMicroscopy2D_FFT_" + self.label] = str(score)
Restraints using electron microscopy 2D images (class averages).
Fit particles against a set of class averages by principal components.
Object used to hold a set of restraints.
Fast scoring of Particles against electron microscopy class averages.
Store a list of ParticleIndexes.
Images read_images(const Strings &names, const ImageReaderWriter *rw)
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...
Parameters used by Em2DRestraint and ProjectionFinder.
The general base class for IMP exceptions.
Functionality for loading, creating, manipulating and scoring atomic structures.
Select hierarchy particles identified by the biological name.
FFT based image alignment, developed by Javier Velazquez-Muriel.