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)
62 self.datasets.append(d)
65 for p
in representation._protocol_output:
66 for i
in range(len(self.datasets)):
67 p.add_em2d_restraint(self, i, resolution, pixel_size,
68 image_resolution, projection_number)
71 if representation
is None and hier
is not None:
72 self.m = hier.get_model()
74 elif hier
is None and representation
is not None:
75 self.m = representation.prot.get_model()
78 resolution=resolution)
80 raise Exception(
"EM2D: must pass hier or representation")
88 if (n_components >= 2) :
90 particles, images, pixel_size, image_resolution, projection_number,
True, n_components)
93 particles, images, pixel_size, image_resolution, projection_number,
True)
94 self.rs.add_restraint(em2d)
96 def set_label(self, label):
99 def add_to_model(self):
102 def get_restraint(self):
105 def set_weight(self,weight):
107 self.rs.set_weight(self.weight)
109 def get_output(self):
112 score = self.weight*self.rs.unprotected_evaluate(
None)
113 output[
"_TotalScore"] = str(score)
114 output[
"ElectronMicroscopy2D_" + self.label] = str(score)
118 """FFT based image alignment, developed by Javier Velazquez-Muriel"""
124 image_resolution=
None,
125 projection_number=
None,
129 @param representation DEPRECATED, pass 'hier' instead
130 @param images SPIDER FORMAT images (format conversion should be done through EM2EM)
131 @param pixel_size sampling rate of the available EM images (angstroms)
132 @param image_resolution resolution at which you want to generate the projections of the model
133 In principle you want "perfect" projections, so use the highest resolution
134 @param projection_number Number of projections of the model (coarse registration) to
135 estimate the registration parameters
136 @param resolution Which level of
137 [model representation](@ref pmi_resolution) to use in the fit
138 @param n_components Number of the largest components to be
139 considered for the EM image
140 @param hier The root hierarchy for applying the restraint
147 raise Exception(
"EM2D_FFT: must pass images")
148 if pixel_size
is None:
149 raise Exception(
"EM2D_FFT: must pass pixel size")
150 if image_resolution
is None:
151 raise Exception(
"EM2D_FFT: must pass image resolution")
152 if projection_number
is None:
153 raise Exception(
"EM2D_FFT: must pass projection_number")
156 if representation
is None and hier
is not None:
157 self.m = hier.get_model()
159 elif hier
is None and representation
is not None:
160 self.m = representation.prot.get_model()
163 resolution=resolution)
165 raise Exception(
"EM2D: must pass hier or representation")
174 rows = imgs[0].get_header().get_number_of_rows()
175 cols = imgs[0].get_header().get_number_of_columns()
180 params.coarse_registration_method = IMP.em2d.ALIGN2D_PREPROCESSING
181 params.optimization_steps = 50
182 params.simplex_initial_length = 0.1
183 params.simplex_minimum_size = 0.02
186 params.save_match_images =
False
193 em2d_restraint.setup(score_function, params)
194 em2d_restraint.set_images(imgs)
195 em2d_restraint.set_fast_mode(5)
196 em2d_restraint.set_name(
"em2d_restraint")
198 print (
"len(particles) = ", len(particles))
200 em2d_restraint.set_particles(container)
202 self.rs.add_restraint(em2d_restraint)
204 def set_label(self, label):
207 def add_to_model(self):
210 def get_restraint(self):
213 def set_weight(self,weight):
215 self.rs.set_weight(self.weight)
217 def get_output(self):
220 score = self.weight*self.rs.unprotected_evaluate(
None)
221 output[
"_TotalScore"] = str(score)
222 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.