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.
19 def __init__(self, hier, images, pixel_size, image_resolution,
20 projection_number, resolution, micrographs_number=
None,
23 @param hier The root hierarchy for applying the restraint
24 @param images 2D class average filenames in PGM text format
25 @param pixel_size Pixel size in angstroms
26 @param image_resolution Estimated resolution of the images
28 @param projection_number Number of projections of the model
29 to generate and fit to images. The lower the number, the
30 faster the evaluation, but the lower the accuracy
31 @param resolution Which level of
32 [model representation](@ref pmi_resolution) to use in the fit
33 @param micrographs_number Number of micrograph particles that
34 were used to generate the class averages, if known
35 @param n_components Number of the largest components to be
36 considered for the EM image
43 l = ihm.location.InputFileLocation(image,
44 details=
"Electron microscopy class average")
45 d = ihm.dataset.EM2DClassDataset(l)
46 self.datasets.append(d)
48 for p, state
in IMP.pmi.tools._all_protocol_outputs(hier):
49 for i
in range(len(self.datasets)):
50 p.add_em2d_restraint(state, self, i, resolution, pixel_size,
51 image_resolution, projection_number,
55 self.m = hier.get_model()
57 hier, resolution=resolution).get_selected_particles()
65 if (n_components >= 2) :
67 particles, images, pixel_size, image_resolution, projection_number,
True, n_components)
70 particles, images, pixel_size, image_resolution, projection_number,
True)
71 self._em2d_restraint = em2d
72 self._num_images = len(images)
73 self.rs.add_restraint(em2d)
75 def set_label(self, label):
78 def add_to_model(self):
81 def get_restraint(self):
84 def set_weight(self,weight):
86 self.rs.set_weight(self.weight)
90 score = self.weight*self.rs.unprotected_evaluate(
None)
91 output[
"_TotalScore"] = str(score)
92 output[
"ElectronMicroscopy2D_" + self.label] = str(score)
95 for i
in range(self._num_images):
96 prefix =
'ElectronMicroscopy2D_%s_Image%d' % (self.label, i+1)
97 ccc = self._em2d_restraint.get_cross_correlation_coefficient(i)
98 output[prefix +
'_CCC'] = str(ccc)
99 tran = self._em2d_restraint.get_transformation(i)
100 r = tran.get_rotation().get_quaternion()
101 t = tran.get_translation()
103 output[prefix +
'_Rotation%d' % j] = str(r[j])
105 output[prefix +
'_Translation%d' % j] = str(t[j])
109 """FFT based image alignment, developed by Javier Velazquez-Muriel"""
110 def __init__(self, hier, images=None, pixel_size=None,
111 image_resolution=
None, projection_number=
None,
114 @param hier The root hierarchy for applying the restraint
115 @param images SPIDER FORMAT images (format conversion should be done through EM2EM)
116 @param pixel_size sampling rate of the available EM images (angstroms)
117 @param image_resolution resolution at which you want to generate the projections of the model
118 In principle you want "perfect" projections, so use the highest resolution
119 @param projection_number Number of projections of the model (coarse registration) to
120 estimate the registration parameters
121 @param resolution Which level of
122 [model representation](@ref pmi_resolution) to use in the fit
123 @param n_components Number of the largest components to be
124 considered for the EM image
131 raise Exception(
"EM2D_FFT: must pass images")
132 if pixel_size
is None:
133 raise Exception(
"EM2D_FFT: must pass pixel size")
134 if image_resolution
is None:
135 raise Exception(
"EM2D_FFT: must pass image resolution")
136 if projection_number
is None:
137 raise Exception(
"EM2D_FFT: must pass projection_number")
140 self.m = hier.get_model()
142 hier, resolution=resolution).get_selected_particles()
151 rows = imgs[0].get_header().get_number_of_rows()
152 cols = imgs[0].get_header().get_number_of_columns()
157 params.coarse_registration_method = IMP.em2d.ALIGN2D_PREPROCESSING
158 params.optimization_steps = 50
159 params.simplex_initial_length = 0.1
160 params.simplex_minimum_size = 0.02
163 params.save_match_images =
False
170 em2d_restraint.setup(score_function, params)
171 em2d_restraint.set_images(imgs)
172 em2d_restraint.set_fast_mode(5)
173 em2d_restraint.set_name(
"em2d_restraint")
175 print (
"len(particles) = ", len(particles))
177 em2d_restraint.set_particles(container)
179 self.rs.add_restraint(em2d_restraint)
181 def set_label(self, label):
184 def add_to_model(self):
187 def get_restraint(self):
190 def set_weight(self,weight):
192 self.rs.set_weight(self.weight)
194 def get_output(self):
196 score = self.weight*self.rs.unprotected_evaluate(
None)
197 output[
"_TotalScore"] = str(score)
198 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.