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 if micrographs_number:
78 em2d.set_micrographs_number(micrographs_number)
79 self._em2d_restraint = em2d
80 self._num_images = len(images)
81 self.rs.add_restraint(em2d)
83 def set_label(self, label):
86 def add_to_model(self):
89 def get_restraint(self):
92 def set_weight(self, weight):
94 self.rs.set_weight(self.weight)
98 score = self.weight*self.rs.unprotected_evaluate(
None)
99 output[
"_TotalScore"] = str(score)
100 output[
"ElectronMicroscopy2D_" + self.label] = str(score)
103 for i
in range(self._num_images):
104 prefix =
'ElectronMicroscopy2D_%s_Image%d' % (self.label, i+1)
105 ccc = self._em2d_restraint.get_cross_correlation_coefficient(i)
106 output[prefix +
'_CCC'] = str(ccc)
107 tran = self._em2d_restraint.get_transformation(i)
108 r = tran.get_rotation().get_quaternion()
109 t = tran.get_translation()
111 output[prefix +
'_Rotation%d' % j] = str(r[j])
113 output[prefix +
'_Translation%d' % j] = str(t[j])
118 """FFT based image alignment, developed by Javier Velazquez-Muriel"""
119 def __init__(self, hier, images=None, pixel_size=None,
120 image_resolution=
None, projection_number=
None,
123 @param hier The root hierarchy for applying the restraint
124 @param images SPIDER FORMAT images (format conversion should be done
126 @param pixel_size sampling rate of the available EM images (angstroms)
127 @param image_resolution resolution at which you want to generate the
128 projections of the model. In principle you want "perfect"
129 projections, so use the highest resolution
130 @param projection_number Number of projections of the model (coarse
131 registration) to estimate the registration parameters
132 @param resolution Which level of
133 [model representation](@ref pmi_resolution) to use in the fit
134 @param n_components Number of the largest components to be
135 considered for the EM image
142 raise Exception(
"EM2D_FFT: must pass images")
143 if pixel_size
is None:
144 raise Exception(
"EM2D_FFT: must pass pixel size")
145 if image_resolution
is None:
146 raise Exception(
"EM2D_FFT: must pass image resolution")
147 if projection_number
is None:
148 raise Exception(
"EM2D_FFT: must pass projection_number")
151 self.m = hier.get_model()
153 hier, resolution=resolution).get_selected_particles()
164 pixel_size, image_resolution, projection_number)
168 params.coarse_registration_method = IMP.em2d.ALIGN2D_PREPROCESSING
169 params.optimization_steps = 50
170 params.simplex_initial_length = 0.1
171 params.simplex_minimum_size = 0.02
175 params.save_match_images =
False
182 em2d_restraint.setup(score_function, params)
183 em2d_restraint.set_images(imgs)
184 em2d_restraint.set_fast_mode(5)
185 em2d_restraint.set_name(
"em2d_restraint")
187 print(
"len(particles) = ", len(particles))
189 em2d_restraint.set_particles(container)
191 self.rs.add_restraint(em2d_restraint)
193 def set_label(self, label):
196 def add_to_model(self):
199 def get_restraint(self):
202 def set_weight(self, weight):
204 self.rs.set_weight(self.weight)
206 def get_output(self):
208 score = self.weight*self.rs.unprotected_evaluate(
None)
209 output[
"_TotalScore"] = str(score)
210 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.