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")
59 l = ihm.location.InputFileLocation(image,
60 details=
"Electron microscopy class average")
61 d = ihm.dataset.EM2DClassDataset(l)
62 self.datasets.append(d)
65 for p, state
in representation._protocol_output:
66 for i
in range(len(self.datasets)):
67 p.add_em2d_restraint(state, self, i, resolution, pixel_size,
68 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()
77 particles = IMP.pmi.tools.select(
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):
114 score = self.weight*self.rs.unprotected_evaluate(
None)
115 output[
"_TotalScore"] = str(score)
116 output[
"ElectronMicroscopy2D_" + self.label] = str(score)
119 for i
in range(self._num_images):
120 prefix =
'ElectronMicroscopy2D_%s_Image%d' % (self.label, i+1)
121 ccc = self._em2d_restraint.get_cross_correlation_coefficient(i)
122 output[prefix +
'_CCC'] = str(ccc)
123 tran = self._em2d_restraint.get_transformation(i)
124 r = tran.get_rotation().get_quaternion()
125 t = tran.get_translation()
127 output[prefix +
'_Rotation%d' % j] = str(r[j])
129 output[prefix +
'_Translation%d' % j] = str(t[j])
133 """FFT based image alignment, developed by Javier Velazquez-Muriel"""
139 image_resolution=
None,
140 projection_number=
None,
144 @param representation DEPRECATED, pass 'hier' instead
145 @param images SPIDER FORMAT images (format conversion should be done through EM2EM)
146 @param pixel_size sampling rate of the available EM images (angstroms)
147 @param image_resolution resolution at which you want to generate the projections of the model
148 In principle you want "perfect" projections, so use the highest resolution
149 @param projection_number Number of projections of the model (coarse registration) to
150 estimate the registration parameters
151 @param resolution Which level of
152 [model representation](@ref pmi_resolution) to use in the fit
153 @param n_components Number of the largest components to be
154 considered for the EM image
155 @param hier The root hierarchy for applying the restraint
162 raise Exception(
"EM2D_FFT: must pass images")
163 if pixel_size
is None:
164 raise Exception(
"EM2D_FFT: must pass pixel size")
165 if image_resolution
is None:
166 raise Exception(
"EM2D_FFT: must pass image resolution")
167 if projection_number
is None:
168 raise Exception(
"EM2D_FFT: must pass projection_number")
171 if representation
is None and hier
is not None:
172 self.m = hier.get_model()
174 elif hier
is None and representation
is not None:
175 self.m = representation.prot.get_model()
176 particles = IMP.pmi.tools.select(
178 resolution=resolution)
180 raise Exception(
"EM2D: must pass hier or representation")
189 rows = imgs[0].get_header().get_number_of_rows()
190 cols = imgs[0].get_header().get_number_of_columns()
195 params.coarse_registration_method = IMP.em2d.ALIGN2D_PREPROCESSING
196 params.optimization_steps = 50
197 params.simplex_initial_length = 0.1
198 params.simplex_minimum_size = 0.02
201 params.save_match_images =
False
208 em2d_restraint.setup(score_function, params)
209 em2d_restraint.set_images(imgs)
210 em2d_restraint.set_fast_mode(5)
211 em2d_restraint.set_name(
"em2d_restraint")
213 print (
"len(particles) = ", len(particles))
215 em2d_restraint.set_particles(container)
217 self.rs.add_restraint(em2d_restraint)
219 def set_label(self, label):
222 def add_to_model(self):
225 def get_restraint(self):
228 def set_weight(self,weight):
230 self.rs.set_weight(self.weight)
232 def get_output(self):
234 score = self.weight*self.rs.unprotected_evaluate(
None)
235 output[
"_TotalScore"] = str(score)
236 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.