1 """@namespace IMP.pmi1.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 pmi1_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):
119 score = self.weight*self.rs.unprotected_evaluate(
None)
120 output[
"_TotalScore"] = str(score)
121 output[
"ElectronMicroscopy2D_" + self.label] = str(score)
124 for i
in range(self._num_images):
125 prefix =
'ElectronMicroscopy2D_%s_Image%d' % (self.label, i+1)
126 ccc = self._em2d_restraint.get_cross_correlation_coefficient(i)
127 output[prefix +
'_CCC'] = str(ccc)
128 tran = self._em2d_restraint.get_transformation(i)
129 r = tran.get_rotation().get_quaternion()
130 t = tran.get_translation()
132 output[prefix +
'_Rotation%d' % j] = str(r[j])
134 output[prefix +
'_Translation%d' % j] = str(t[j])
138 """FFT based image alignment, developed by Javier Velazquez-Muriel"""
144 image_resolution=
None,
145 projection_number=
None,
149 @param representation DEPRECATED, pass 'hier' instead
150 @param images SPIDER FORMAT images (format conversion should be done through EM2EM)
151 @param pixel_size sampling rate of the available EM images (angstroms)
152 @param image_resolution resolution at which you want to generate the projections of the model
153 In principle you want "perfect" projections, so use the highest resolution
154 @param projection_number Number of projections of the model (coarse registration) to
155 estimate the registration parameters
156 @param resolution Which level of
157 [model representation](@ref pmi1_resolution) to use in the fit
158 @param n_components Number of the largest components to be
159 considered for the EM image
160 @param hier The root hierarchy for applying the restraint
167 raise Exception(
"EM2D_FFT: must pass images")
168 if pixel_size
is None:
169 raise Exception(
"EM2D_FFT: must pass pixel size")
170 if image_resolution
is None:
171 raise Exception(
"EM2D_FFT: must pass image resolution")
172 if projection_number
is None:
173 raise Exception(
"EM2D_FFT: must pass projection_number")
176 if representation
is None and hier
is not None:
177 self.m = hier.get_model()
179 elif hier
is None and representation
is not None:
180 self.m = representation.prot.get_model()
183 resolution=resolution)
185 raise Exception(
"EM2D: must pass hier or representation")
194 rows = imgs[0].get_header().get_number_of_rows()
195 cols = imgs[0].get_header().get_number_of_columns()
200 params.coarse_registration_method = IMP.em2d.ALIGN2D_PREPROCESSING
201 params.optimization_steps = 50
202 params.simplex_initial_length = 0.1
203 params.simplex_minimum_size = 0.02
206 params.save_match_images =
False
213 em2d_restraint.setup(score_function, params)
214 em2d_restraint.set_images(imgs)
215 em2d_restraint.set_fast_mode(5)
216 em2d_restraint.set_name(
"em2d_restraint")
218 print (
"len(particles) = ", len(particles))
220 em2d_restraint.set_particles(container)
222 self.rs.add_restraint(em2d_restraint)
224 def set_label(self, label):
227 def add_to_model(self):
230 def get_restraint(self):
233 def set_weight(self,weight):
235 self.rs.set_weight(self.weight)
237 def get_output(self):
239 score = self.weight*self.rs.unprotected_evaluate(
None)
240 output[
"_TotalScore"] = str(score)
241 output[
"ElectronMicroscopy2D_FFT_" + self.label] = str(score)
Fit particles against a set of class averages by principal components.
Restraints using electron microscopy 2D images (class averages).
FFT based image alignment, developed by Javier Velazquez-Muriel.
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.