1 """@namespace IMP.pmi.restraints.em2d
2 Restraints for handling electron microscopy images.
5 from __future__
import print_function
14 """Fit particles against a set of class averages by principal components.
15 Compares how well the principal components of the segmented class
16 average fit to the principal components of the particles.
22 image_resolution=
None,
23 projection_number=
None,
28 @param representation DEPRECATED, pass 'hier' instead
29 @param images 2D class average filenames in PGM text format
30 @param pixel_size Pixel size in angstroms
31 @param image_resolution Estimated resolution of the images
33 @param projection_number Number of projections of the model
34 to generate and fit to images. The lower the number, the
35 faster the evaluation, but the lower the accuracy
36 @param resolution Which level of
37 [model representation](@ref pmi_resolution) to use in the fit
38 @param n_components Number of the largest components to be
39 considered for the EM image
40 @param hier The root hierarchy for applying the restraint
48 if pixel_size
is None:
50 if image_resolution
is None:
51 raise Exception(
"must pass image resolution")
56 d = representation.get_file_dataset(image)
58 self.datasets.append(d)
61 details=
"Electron microscopy class average")
63 self.datasets.append(d)
66 for p, state
in representation._protocol_output:
67 for i
in range(len(self.datasets)):
68 p.add_em2d_restraint(state, self, i, resolution, pixel_size,
69 image_resolution, projection_number)
72 if representation
is None and hier
is not None:
73 self.m = hier.get_model()
75 elif hier
is None and representation
is not None:
76 self.m = representation.prot.get_model()
79 resolution=resolution)
81 raise Exception(
"EM2D: must pass hier or representation")
89 if (n_components >= 2) :
91 particles, images, pixel_size, image_resolution, projection_number,
True, n_components)
94 particles, images, pixel_size, image_resolution, projection_number,
True)
95 self._em2d_restraint = em2d
96 self._num_images = len(images)
97 self.rs.add_restraint(em2d)
99 def set_label(self, label):
102 def add_to_model(self):
105 def get_restraint(self):
108 def set_weight(self,weight):
110 self.rs.set_weight(self.weight)
112 def get_output(self):
115 score = self.weight*self.rs.unprotected_evaluate(
None)
116 output[
"_TotalScore"] = str(score)
117 output[
"ElectronMicroscopy2D_" + self.label] = str(score)
120 for i
in range(self._num_images):
121 prefix =
'ElectronMicroscopy2D_%s_Image%d' % (self.label, i+1)
122 ccc = self._em2d_restraint.get_cross_correlation_coefficient(i)
123 output[prefix +
'_CCC'] = str(ccc)
124 tran = self._em2d_restraint.get_transformation(i)
125 r = tran.get_rotation().get_quaternion()
126 t = tran.get_translation()
128 output[prefix +
'_Rotation%d' % j] = str(r[j])
130 output[prefix +
'_Translation%d' % j] = str(t[j])
134 """FFT based image alignment, developed by Javier Velazquez-Muriel"""
140 image_resolution=
None,
141 projection_number=
None,
145 @param representation DEPRECATED, pass 'hier' instead
146 @param images SPIDER FORMAT images (format conversion should be done through EM2EM)
147 @param pixel_size sampling rate of the available EM images (angstroms)
148 @param image_resolution resolution at which you want to generate the projections of the model
149 In principle you want "perfect" projections, so use the highest resolution
150 @param projection_number Number of projections of the model (coarse registration) to
151 estimate the registration parameters
152 @param resolution Which level of
153 [model representation](@ref pmi_resolution) to use in the fit
154 @param n_components Number of the largest components to be
155 considered for the EM image
156 @param hier The root hierarchy for applying the restraint
163 raise Exception(
"EM2D_FFT: must pass images")
164 if pixel_size
is None:
165 raise Exception(
"EM2D_FFT: must pass pixel size")
166 if image_resolution
is None:
167 raise Exception(
"EM2D_FFT: must pass image resolution")
168 if projection_number
is None:
169 raise Exception(
"EM2D_FFT: must pass projection_number")
172 if representation
is None and hier
is not None:
173 self.m = hier.get_model()
175 elif hier
is None and representation
is not None:
176 self.m = representation.prot.get_model()
179 resolution=resolution)
181 raise Exception(
"EM2D: must pass hier or representation")
190 rows = imgs[0].get_header().get_number_of_rows()
191 cols = imgs[0].get_header().get_number_of_columns()
196 params.coarse_registration_method = IMP.em2d.ALIGN2D_PREPROCESSING
197 params.optimization_steps = 50
198 params.simplex_initial_length = 0.1
199 params.simplex_minimum_size = 0.02
202 params.save_match_images =
False
209 em2d_restraint.setup(score_function, params)
210 em2d_restraint.set_images(imgs)
211 em2d_restraint.set_fast_mode(5)
212 em2d_restraint.set_name(
"em2d_restraint")
214 print (
"len(particles) = ", len(particles))
216 em2d_restraint.set_particles(container)
218 self.rs.add_restraint(em2d_restraint)
220 def set_label(self, label):
223 def add_to_model(self):
226 def get_restraint(self):
229 def set_weight(self,weight):
231 self.rs.set_weight(self.weight)
233 def get_output(self):
236 score = self.weight*self.rs.unprotected_evaluate(
None)
237 output[
"_TotalScore"] = str(score)
238 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.