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")
54 if representation
is None and hier
is not None:
55 self.m = hier.get_model()
57 elif hier
is None and representation
is not None:
58 self.m = representation.prot.get_model()
61 resolution=resolution)
63 raise Exception(
"EM2D: must pass hier or representation")
71 if (n_components >= 2) :
73 particles, images, pixel_size, image_resolution, projection_number,
True, n_components)
76 particles, images, pixel_size, image_resolution, projection_number,
True)
77 self.rs.add_restraint(em2d)
79 def set_label(self, label):
82 def add_to_model(self):
85 def get_restraint(self):
88 def set_weight(self,weight):
90 self.rs.set_weight(self.weight)
95 score = self.weight*self.rs.unprotected_evaluate(
None)
96 output[
"_TotalScore"] = str(score)
97 output[
"ElectronMicroscopy2D_" + self.label] = str(score)
101 """FFT based image alignment, developed by Javier Velazquez-Muriel"""
107 image_resolution=
None,
108 projection_number=
None,
112 @param representation DEPRECATED, pass 'hier' instead
113 @param images SPIDER FORMAT images (format conversion should be done through EM2EM)
114 @param pixel_size sampling rate of the available EM images (angstroms)
115 @param image_resolution resolution at which you want to generate the projections of the model
116 In principle you want "perfect" projections, so use the highest resolution
117 @param projection_number Number of projections of the model (coarse registration) to
118 estimate the registration parameters
119 @param resolution Which level of
120 [model representation](@ref pmi_resolution) to use in the fit
121 @param n_components Number of the largest components to be
122 considered for the EM image
123 @param hier The root hierarchy for applying the restraint
130 raise Exception(
"EM2D_FFT: must pass images")
131 if pixel_size
is None:
132 raise Exception(
"EM2D_FFT: must pass pixel size")
133 if image_resolution
is None:
134 raise Exception(
"EM2D_FFT: must pass image resolution")
135 if projection_number
is None:
136 raise Exception(
"EM2D_FFT: must pass projection_number")
139 if representation
is None and hier
is not None:
140 self.m = hier.get_model()
142 elif hier
is None and representation
is not None:
143 self.m = representation.prot.get_model()
146 resolution=resolution)
148 raise Exception(
"EM2D: must pass hier or representation")
157 rows = imgs[0].get_header().get_number_of_rows()
158 cols = imgs[0].get_header().get_number_of_columns()
163 params.coarse_registration_method = IMP.em2d.ALIGN2D_PREPROCESSING
164 params.optimization_steps = 50
165 params.simplex_initial_length = 0.1
166 params.simplex_minimum_size = 0.02
169 params.save_match_images =
False
176 em2d_restraint.setup(score_function, params)
177 em2d_restraint.set_images(imgs)
178 em2d_restraint.set_fast_mode(5)
179 em2d_restraint.set_name(
"em2d_restraint")
181 print (
"len(particles) = ", len(particles))
183 em2d_restraint.set_particles(container)
185 self.rs.add_restraint(em2d_restraint)
187 def set_label(self, label):
190 def add_to_model(self):
193 def get_restraint(self):
196 def set_weight(self,weight):
198 self.rs.set_weight(self.weight)
200 def get_output(self):
203 score = self.weight*self.rs.unprotected_evaluate(
None)
204 output[
"_TotalScore"] = str(score)
205 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.