1 """@namespace IMP.pmi.restraints.em2d
2 Restraints for handling electron microscopy images.
5 from __future__
import print_function
15 """Fit particles against a set of class averages by principal components.
16 Compares how well the principal components of the segmented class
17 average fit to the principal components of the particles.
23 image_resolution=
None,
24 projection_number=
None,
25 micrographs_number=
None,
30 @param representation DEPRECATED, pass 'hier' instead
31 @param images 2D class average filenames in PGM text format
32 @param pixel_size Pixel size in angstroms
33 @param image_resolution Estimated resolution of the images
35 @param projection_number Number of projections of the model
36 to generate and fit to images. The lower the number, the
37 faster the evaluation, but the lower the accuracy
38 @param micrographs_number Number of micrograph particles that
39 were used to generate the class averages, if known
40 @param resolution Which level of
41 [model representation](@ref pmi_resolution) to use in the fit
42 @param n_components Number of the largest components to be
43 considered for the EM image
44 @param hier The root hierarchy for applying the restraint
52 if pixel_size
is None:
54 if image_resolution
is None:
55 raise Exception(
"must pass image resolution")
60 d = representation.get_file_dataset(image)
62 self.datasets.append(d)
64 l = ihm.location.InputFileLocation(image,
65 details=
"Electron microscopy class average")
66 d = ihm.dataset.EM2DClassDataset(l)
67 self.datasets.append(d)
70 for p, state
in representation._protocol_output:
71 for i
in range(len(self.datasets)):
72 p.add_em2d_restraint(state, self, i, resolution, pixel_size,
73 image_resolution, projection_number,
77 if representation
is None and hier
is not None:
78 self.m = hier.get_model()
80 elif hier
is None and representation
is not None:
81 self.m = representation.prot.get_model()
84 resolution=resolution)
86 raise Exception(
"EM2D: must pass hier or representation")
94 if (n_components >= 2) :
96 particles, images, pixel_size, image_resolution, projection_number,
True, n_components)
99 particles, images, pixel_size, image_resolution, projection_number,
True)
100 self._em2d_restraint = em2d
101 self._num_images = len(images)
102 self.rs.add_restraint(em2d)
104 def set_label(self, label):
107 def add_to_model(self):
110 def get_restraint(self):
113 def set_weight(self,weight):
115 self.rs.set_weight(self.weight)
117 def get_output(self):
120 score = self.weight*self.rs.unprotected_evaluate(
None)
121 output[
"_TotalScore"] = str(score)
122 output[
"ElectronMicroscopy2D_" + self.label] = str(score)
125 for i
in range(self._num_images):
126 prefix =
'ElectronMicroscopy2D_%s_Image%d' % (self.label, i+1)
127 ccc = self._em2d_restraint.get_cross_correlation_coefficient(i)
128 output[prefix +
'_CCC'] = str(ccc)
129 tran = self._em2d_restraint.get_transformation(i)
130 r = tran.get_rotation().get_quaternion()
131 t = tran.get_translation()
133 output[prefix +
'_Rotation%d' % j] = str(r[j])
135 output[prefix +
'_Translation%d' % j] = str(t[j])
139 """FFT based image alignment, developed by Javier Velazquez-Muriel"""
145 image_resolution=
None,
146 projection_number=
None,
150 @param representation DEPRECATED, pass 'hier' instead
151 @param images SPIDER FORMAT images (format conversion should be done through EM2EM)
152 @param pixel_size sampling rate of the available EM images (angstroms)
153 @param image_resolution resolution at which you want to generate the projections of the model
154 In principle you want "perfect" projections, so use the highest resolution
155 @param projection_number Number of projections of the model (coarse registration) to
156 estimate the registration parameters
157 @param resolution Which level of
158 [model representation](@ref pmi_resolution) to use in the fit
159 @param n_components Number of the largest components to be
160 considered for the EM image
161 @param hier The root hierarchy for applying the restraint
168 raise Exception(
"EM2D_FFT: must pass images")
169 if pixel_size
is None:
170 raise Exception(
"EM2D_FFT: must pass pixel size")
171 if image_resolution
is None:
172 raise Exception(
"EM2D_FFT: must pass image resolution")
173 if projection_number
is None:
174 raise Exception(
"EM2D_FFT: must pass projection_number")
177 if representation
is None and hier
is not None:
178 self.m = hier.get_model()
180 elif hier
is None and representation
is not None:
181 self.m = representation.prot.get_model()
184 resolution=resolution)
186 raise Exception(
"EM2D: must pass hier or representation")
195 rows = imgs[0].get_header().get_number_of_rows()
196 cols = imgs[0].get_header().get_number_of_columns()
201 params.coarse_registration_method = IMP.em2d.ALIGN2D_PREPROCESSING
202 params.optimization_steps = 50
203 params.simplex_initial_length = 0.1
204 params.simplex_minimum_size = 0.02
207 params.save_match_images =
False
214 em2d_restraint.setup(score_function, params)
215 em2d_restraint.set_images(imgs)
216 em2d_restraint.set_fast_mode(5)
217 em2d_restraint.set_name(
"em2d_restraint")
219 print (
"len(particles) = ", len(particles))
221 em2d_restraint.set_particles(container)
223 self.rs.add_restraint(em2d_restraint)
225 def set_label(self, label):
228 def add_to_model(self):
231 def get_restraint(self):
234 def set_weight(self,weight):
236 self.rs.set_weight(self.weight)
238 def get_output(self):
241 score = self.weight*self.rs.unprotected_evaluate(
None)
242 output[
"_TotalScore"] = str(score)
243 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.