scipion-em-xmipp 24.12.2__py3-none-any.whl → 25.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {scipion_em_xmipp-24.12.2.dist-info → scipion_em_xmipp-25.6.0.dist-info}/METADATA +10 -10
- scipion_em_xmipp-25.6.0.dist-info/RECORD +255 -0
- {scipion_em_xmipp-24.12.2.dist-info → scipion_em_xmipp-25.6.0.dist-info}/WHEEL +1 -1
- {scipion_em_xmipp-24.12.2.dist-info → scipion_em_xmipp-25.6.0.dist-info}/entry_points.txt +0 -1
- xmipp3/__init__.py +106 -73
- xmipp3/base.py +2 -1
- xmipp3/convert/convert.py +1 -1
- xmipp3/legacy/protocols/protocol_angular_resolution_alignment.py +204 -0
- xmipp3/legacy/protocols/protocol_apply_deformation_zernike3d.py +113 -0
- xmipp3/legacy/protocols/protocol_classification_gpuCorr.py +821 -0
- xmipp3/legacy/protocols/protocol_classification_gpuCorr_full.py +1014 -0
- xmipp3/legacy/protocols/protocol_classification_gpuCorr_semi.py +462 -0
- xmipp3/legacy/protocols/protocol_classify_kmeans2d.py +285 -0
- xmipp3/legacy/protocols/protocol_deep_align.py +859 -0
- xmipp3/legacy/protocols/protocol_deep_denoising.py +425 -0
- xmipp3/legacy/protocols/protocol_kmeans_clustering.py +122 -0
- xmipp3/legacy/protocols/protocol_metaprotocol_create_output.py +146 -0
- xmipp3/legacy/protocols/protocol_metaprotocol_create_subset.py +96 -0
- xmipp3/legacy/protocols/protocol_metaprotocol_discrete_heterogeneity_scheduler.py +516 -0
- xmipp3/legacy/protocols/protocol_metaprotocol_golden_highres.py +663 -0
- xmipp3/legacy/protocols/protocol_mltomo.py +576 -0
- xmipp3/legacy/protocols/protocol_movie_average.py +202 -0
- xmipp3/legacy/protocols/protocol_movie_opticalflow.py +416 -0
- xmipp3/legacy/protocols/protocol_particle_boxsize.py +133 -0
- xmipp3/legacy/protocols/protocol_reconstruct_heterogeneous.py +1031 -0
- xmipp3/legacy/protocols/protocol_rotational_spectra.py +212 -0
- xmipp3/legacy/protocols/protocol_solid_angles.py +632 -0
- xmipp3/legacy/protocols/protocol_split_volume.py +112 -0
- xmipp3/legacy/protocols/protocol_split_volume_hierarchical_cluster.py +865 -0
- xmipp3/legacy/protocols/protocol_subtract_projection.py +265 -0
- xmipp3/legacy/tests/test_protocol_deep_denoising.py +64 -0
- xmipp3/legacy/tests/test_protocols_angular_resolution_alignment.py +88 -0
- xmipp3/legacy/tests/test_protocols_gpuCorr_classifier.py +141 -0
- xmipp3/legacy/tests/test_protocols_gpuCorr_fullStreaming.py +172 -0
- xmipp3/legacy/tests/test_protocols_gpuCorr_semiStreaming.py +68 -0
- xmipp3/legacy/tests/test_protocols_metaprotocol_golden_highres.py +96 -0
- xmipp3/legacy/tests/test_protocols_metaprotocol_heterogeneity.py +78 -0
- xmipp3/legacy/tests/test_protocols_mixed_movies.py +148 -0
- xmipp3/legacy/tests/test_protocols_solid_angles.py +161 -0
- xmipp3/legacy/tests/test_protocols_subtract_projection.py +595 -0
- xmipp3/legacy/tests/test_protocols_xmipp_movies.py +229 -0
- xmipp3/legacy/viewers/viewer_angular_resolution_alignment.py +148 -0
- xmipp3/legacy/viewers/viewer_deep_align.py +121 -0
- xmipp3/legacy/viewers/viewer_metaprotocol_golden_highres.py +140 -0
- xmipp3/legacy/viewers/viewer_mltomo.py +297 -0
- xmipp3/legacy/viewers/viewer_solid_angles.py +91 -0
- xmipp3/legacy/viewers/viewer_split_volume.py +57 -0
- xmipp3/protocols/__init__.py +1 -2
- xmipp3/protocols/protocol_align_volume.py +34 -8
- xmipp3/protocols/protocol_apply_alignment.py +1 -1
- xmipp3/protocols/protocol_apply_tilt_to_ctf.py +2 -3
- xmipp3/protocols/protocol_apply_zernike3d.py +2 -1
- xmipp3/protocols/protocol_assignment_tilt_pair.py +1 -2
- xmipp3/protocols/protocol_center_particles.py +1 -1
- xmipp3/protocols/protocol_cl2d.py +1 -2
- xmipp3/protocols/protocol_cl2d_align.py +1 -1
- xmipp3/protocols/protocol_cl2d_clustering.py +1 -1
- xmipp3/protocols/protocol_classify_pca.py +25 -9
- xmipp3/protocols/protocol_classify_pca_streaming.py +67 -42
- xmipp3/protocols/protocol_compute_likelihood.py +368 -0
- xmipp3/protocols/protocol_consensus_local_ctf.py +1 -1
- xmipp3/protocols/protocol_convert_pdb.py +9 -1
- xmipp3/protocols/protocol_create_gallery.py +1 -1
- xmipp3/protocols/protocol_ctf_consensus.py +14 -8
- xmipp3/protocols/protocol_ctf_correct_wiener2d.py +1 -1
- xmipp3/protocols/protocol_ctf_micrographs.py +1 -1
- xmipp3/protocols/protocol_deep_center_predict.py +10 -1
- xmipp3/protocols/protocol_deep_hand.py +19 -2
- xmipp3/protocols/protocol_deep_micrograph_screen.py +1 -1
- xmipp3/protocols/protocol_extract_asymmetric_unit.py +1 -1
- xmipp3/protocols/protocol_extract_particles.py +22 -10
- xmipp3/protocols/protocol_extract_particles_movies.py +1 -1
- xmipp3/protocols/protocol_extract_particles_pairs.py +1 -1
- xmipp3/protocols/protocol_flexalign.py +3 -4
- xmipp3/protocols/protocol_helical_parameters.py +1 -4
- xmipp3/protocols/protocol_movie_alignment_consensus.py +122 -40
- xmipp3/protocols/protocol_movie_dose_analysis.py +79 -82
- xmipp3/protocols/protocol_movie_max_shift.py +6 -2
- xmipp3/protocols/protocol_movie_split_frames.py +165 -88
- xmipp3/protocols/protocol_particle_pick_automatic.py +1 -2
- xmipp3/protocols/protocol_particle_pick_consensus.py +7 -0
- xmipp3/protocols/protocol_particle_pick_pairs.py +1 -1
- xmipp3/protocols/protocol_phantom_create.py +1 -1
- xmipp3/protocols/protocol_pick_noise.py +1 -1
- xmipp3/protocols/protocol_postProcessing_deepPostProcessing.py +5 -5
- xmipp3/protocols/protocol_preprocess/protocol_crop_resize.py +3 -2
- xmipp3/protocols/protocol_preprocess/protocol_filter.py +2 -2
- xmipp3/protocols/protocol_preprocess/protocol_image_operate.py +2 -2
- xmipp3/protocols/protocol_preprocess/protocol_mask.py +1 -1
- xmipp3/protocols/protocol_preprocess/protocol_preprocess.py +6 -4
- xmipp3/protocols/protocol_preprocess/protocol_process.py +20 -7
- xmipp3/protocols/protocol_preprocess_micrographs.py +3 -2
- xmipp3/protocols/protocol_projmatch/projmatch_steps.py +1 -1
- xmipp3/protocols/protocol_projmatch/protocol_projmatch.py +1 -1
- xmipp3/protocols/protocol_random_conical_tilt.py +1 -2
- xmipp3/protocols/protocol_ransac.py +41 -37
- xmipp3/protocols/protocol_reconstruct_fourier.py +5 -1
- xmipp3/protocols/protocol_reconstruct_highres.py +13 -7
- xmipp3/protocols/protocol_reconstruct_significant.py +14 -21
- xmipp3/protocols/protocol_resolution3d.py +1 -1
- xmipp3/protocols/protocol_resolution_deepres.py +1 -1
- xmipp3/protocols/protocol_resolution_directional.py +1 -1
- xmipp3/protocols/protocol_resolution_fso.py +1 -1
- xmipp3/protocols/protocol_resolution_monogenic_signal.py +19 -4
- xmipp3/protocols/protocol_rotate_volume.py +1 -1
- xmipp3/protocols/protocol_screen_deepConsensus.py +25 -5
- xmipp3/protocols/protocol_shift_volume.py +1 -1
- xmipp3/protocols/protocol_simulate_ctf.py +5 -3
- xmipp3/protocols/protocol_structure_map.py +9 -1
- xmipp3/protocols/protocol_subtract_projection.py +25 -10
- xmipp3/protocols/protocol_tilt_analysis.py +3 -3
- xmipp3/protocols/protocol_validate_fscq.py +2 -2
- xmipp3/protocols/protocol_validate_nontilt.py +1 -1
- xmipp3/protocols/protocol_volume_adjust_sub.py +8 -4
- xmipp3/protocols/protocol_volume_deform_zernike3d.py +1 -1
- xmipp3/protocols/protocol_volume_local_sharpening.py +1 -1
- xmipp3/protocols/protocol_volume_strain.py +1 -1
- xmipp3/protocols.conf +1 -3
- xmipp3/tests/test_protocol_likelihood.py +240 -0
- xmipp3/tests/test_protocol_split_frames.py +136 -0
- xmipp3/tests/test_protocol_validate_fscq.py +2 -2
- xmipp3/tests/test_protocols_highres.py +44 -5
- xmipp3/tests/test_protocols_xmipp_2d.py +1 -48
- xmipp3/tests/test_protocols_xmipp_mics.py +20 -16
- xmipp3/tests/test_protocols_xmipp_movies.py +4 -4
- xmipp3/version.py +5 -5
- xmipp3/viewers/__init__.py +1 -1
- xmipp3/viewers/viewer_LL_matrix.py +273 -0
- xmipp3/viewers/viewer_deep_consensus.py +1 -7
- xmipp3/viewers/viewer_dose_analysis.py +18 -2
- xmipp3/viewers/viewer_resolution_fso.py +18 -6
- xmipp3/viewers/viewer_structure_map.py +53 -11
- xmipp3/wizards.py +3 -2
- xmipp3/xmipp_logo_devel.png +0 -0
- scipion_em_xmipp-24.12.2.dist-info/RECORD +0 -210
- {scipion_em_xmipp-24.12.2.dist-info → scipion_em_xmipp-25.6.0.dist-info}/LICENSE +0 -0
- {scipion_em_xmipp-24.12.2.dist-info → scipion_em_xmipp-25.6.0.dist-info}/top_level.txt +0 -0
- /xmipp3/{protocols → legacy/protocols}/protocol_enrich.py +0 -0
- /xmipp3/{protocols → legacy/protocols}/protocol_screen_deeplearning.py +0 -0
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
# ******************************************************************************
|
|
2
|
+
# *
|
|
3
|
+
# * Authors: Josue Gomez Blanco (jgomez@cnb.csic.es)
|
|
4
|
+
# * Amaya Jimenez Moreno (ajimenez@cnb.csic.es)
|
|
5
|
+
# *
|
|
6
|
+
# * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
|
|
7
|
+
# *
|
|
8
|
+
# * This program is free software; you can redistribute it and/or modify
|
|
9
|
+
# * it under the terms of the GNU General Public License as published by
|
|
10
|
+
# * the Free Software Foundation; either version 2 of the License, or
|
|
11
|
+
# * (at your option) any later version.
|
|
12
|
+
# *
|
|
13
|
+
# * This program is distributed in the hope that it will be useful,
|
|
14
|
+
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
# * GNU General Public License for more details.
|
|
17
|
+
# *
|
|
18
|
+
# * You should have received a copy of the GNU General Public License
|
|
19
|
+
# * along with this program; if not, write to the Free Software
|
|
20
|
+
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
21
|
+
# * 02111-1307 USA
|
|
22
|
+
# *
|
|
23
|
+
# * All comments concerning this program package may be sent to the
|
|
24
|
+
# * e-mail address 'scipion@cnb.csic.es'
|
|
25
|
+
# *
|
|
26
|
+
# ******************************************************************************
|
|
27
|
+
|
|
28
|
+
from os.path import getmtime
|
|
29
|
+
from datetime import datetime
|
|
30
|
+
from os.path import exists, splitext
|
|
31
|
+
import os
|
|
32
|
+
|
|
33
|
+
from pyworkflow import VERSION_2_0
|
|
34
|
+
import pyworkflow.protocol.params as params
|
|
35
|
+
from pyworkflow.object import Set, Float, String
|
|
36
|
+
from pyworkflow.protocol.constants import STATUS_NEW
|
|
37
|
+
from pyworkflow.utils import prettyTime
|
|
38
|
+
import pyworkflow.protocol.constants as const
|
|
39
|
+
|
|
40
|
+
from pwem.objects import SetOfParticles, SetOfClasses2D, Class2D
|
|
41
|
+
from pwem.constants import ALIGN_2D, ALIGN_NONE
|
|
42
|
+
from pwem.protocols import ProtAlign2D
|
|
43
|
+
import pwem.emlib.metadata as md
|
|
44
|
+
|
|
45
|
+
from xmipp3.constants import CUDA_ALIGN_SIGNIFICANT
|
|
46
|
+
from xmipp3.convert import (writeSetOfParticles, rowToAlignment,
|
|
47
|
+
writeSetOfClasses2D)
|
|
48
|
+
from xmipp3.base import isXmippCudaPresent
|
|
49
|
+
|
|
50
|
+
REF_CLASSES = 0
|
|
51
|
+
REF_AVERAGES = 1
|
|
52
|
+
HASH_SIZE = 100
|
|
53
|
+
|
|
54
|
+
class HashTableDict:
|
|
55
|
+
def __init__(self, Ndict=HASH_SIZE):
|
|
56
|
+
self.Ndict = Ndict
|
|
57
|
+
self.dict = [{}]*Ndict
|
|
58
|
+
|
|
59
|
+
def isItemPresent(self, idx):
|
|
60
|
+
return idx in self.dict[idx % self.Ndict]
|
|
61
|
+
|
|
62
|
+
def pushItem(self, idx):
|
|
63
|
+
idxDict = idx % self.Ndict
|
|
64
|
+
if not idx in self.dict[idxDict]:
|
|
65
|
+
self.dict[idxDict][idx]=1
|
|
66
|
+
|
|
67
|
+
class XmippProtStrGpuCrrSimple(ProtAlign2D):
|
|
68
|
+
""" 2D alignment in semi streaming using Xmipp GPU Correlation.
|
|
69
|
+
A previous set of classes must be provided to include the new images in the
|
|
70
|
+
corresponding class although the representatives will be maintained."""
|
|
71
|
+
_label = 'gl2d static'
|
|
72
|
+
_lastUpdateVersion = VERSION_2_0
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# --------------------------- DEFINE param functions -----------------------
|
|
76
|
+
def _defineAlignParams(self, form):
|
|
77
|
+
form.addHidden(params.GPU_LIST, params.StringParam, default='0',
|
|
78
|
+
expertLevel=const.LEVEL_ADVANCED,
|
|
79
|
+
label="Choose GPU IDs",
|
|
80
|
+
help="Add a list of GPU devices that can be used")
|
|
81
|
+
form.addParam('inputRefs', params.PointerParam,
|
|
82
|
+
pointerClass='SetOfClasses2D, SetOfAverages',
|
|
83
|
+
important=True,
|
|
84
|
+
label="Set of references",
|
|
85
|
+
help='Set of references that will serve as reference for '
|
|
86
|
+
'the classification. This can be a set of classes '
|
|
87
|
+
'or set of averages')
|
|
88
|
+
form.addParam('maxShift', params.IntParam, default=10,
|
|
89
|
+
label='Maximum shift (px):',
|
|
90
|
+
help='Maximum shift allowed during the alignment as '
|
|
91
|
+
'percentage of the input set size',
|
|
92
|
+
expertLevel=const.LEVEL_ADVANCED)
|
|
93
|
+
form.addParam('keepBest', params.IntParam, default=1,
|
|
94
|
+
label='Number of best images:',
|
|
95
|
+
help='Number of the best images to keep for every class',
|
|
96
|
+
expertLevel=const.LEVEL_ADVANCED)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# --------------------------- INSERT steps functions -----------------------
|
|
100
|
+
def _insertAllSteps(self):
|
|
101
|
+
"""" Insert the steps to call cuda correlation program"""
|
|
102
|
+
|
|
103
|
+
self.listInFn = []
|
|
104
|
+
self.listOutFn = []
|
|
105
|
+
self.doneListFn = []
|
|
106
|
+
self.lastDate = 0
|
|
107
|
+
self.flag_relion = False
|
|
108
|
+
self.imgsRef = self._getExtraPath('imagesRef.xmd')
|
|
109
|
+
self.htAlreadyProcessed = HashTableDict()
|
|
110
|
+
xOrig = self.inputParticles.get().getXDim()
|
|
111
|
+
self.maximumShift = int(self.maxShift.get() * xOrig / 100)
|
|
112
|
+
|
|
113
|
+
self._loadInputList()
|
|
114
|
+
if isinstance(self.inputRefs.get(), SetOfClasses2D):
|
|
115
|
+
self.useAsRef = REF_CLASSES
|
|
116
|
+
else:
|
|
117
|
+
self.useAsRef = REF_AVERAGES
|
|
118
|
+
|
|
119
|
+
deps = []
|
|
120
|
+
self._insertFunctionStep('convertAveragesStep')
|
|
121
|
+
deps = self._insertStepsForParticles(deps)
|
|
122
|
+
|
|
123
|
+
self._insertFunctionStep('createOutputStep',
|
|
124
|
+
prerequisites=deps, wait=True)
|
|
125
|
+
|
|
126
|
+
def _insertStepsForParticles(self, deps):
|
|
127
|
+
stepIdClassify = self._insertFunctionStep('classifyStep',
|
|
128
|
+
prerequisites= deps)
|
|
129
|
+
deps.append(stepIdClassify)
|
|
130
|
+
return deps
|
|
131
|
+
|
|
132
|
+
# --------------------------- STEPS functions ------------------------------
|
|
133
|
+
def convertAveragesStep(self):
|
|
134
|
+
|
|
135
|
+
if self.useAsRef == REF_CLASSES:
|
|
136
|
+
writeSetOfClasses2D(self.inputRefs.get(), self.imgsRef,
|
|
137
|
+
writeParticles=True)
|
|
138
|
+
else:
|
|
139
|
+
writeSetOfParticles(self.inputRefs.get(), self.imgsRef)
|
|
140
|
+
|
|
141
|
+
def classifyStep(self):
|
|
142
|
+
|
|
143
|
+
inputImgs = self._getInputFn()
|
|
144
|
+
writeSetOfParticles(self.listOfParticles, inputImgs,
|
|
145
|
+
alignType=ALIGN_NONE)
|
|
146
|
+
|
|
147
|
+
for p in self.listOfParticles:
|
|
148
|
+
partId = p.getObjId()
|
|
149
|
+
self.htAlreadyProcessed.pushItem(partId)
|
|
150
|
+
self.lastDate = p.getObjCreation()
|
|
151
|
+
self._saveCreationTimeFile(self.lastDate)
|
|
152
|
+
|
|
153
|
+
metadataRef = md.MetaData(self.imgsRef)
|
|
154
|
+
if metadataRef.containsLabel(md.MDL_REF) is False:
|
|
155
|
+
args = ('-i %s --fill ref lineal 1 1 -o %s')%(self.imgsRef, self.imgsRef)
|
|
156
|
+
self.runJob("xmipp_metadata_utilities", args, numberOfMpi=1)
|
|
157
|
+
|
|
158
|
+
# Calling program xmipp_cuda_correlation
|
|
159
|
+
count = 0
|
|
160
|
+
GpuListCuda = ''
|
|
161
|
+
if self.useQueueForSteps() or self.useQueue():
|
|
162
|
+
GpuList = os.environ["CUDA_VISIBLE_DEVICES"]
|
|
163
|
+
GpuList = GpuList.split(",")
|
|
164
|
+
for elem in GpuList:
|
|
165
|
+
GpuListCuda = GpuListCuda + str(count) + ' '
|
|
166
|
+
count += 1
|
|
167
|
+
else:
|
|
168
|
+
GpuListAux = ''
|
|
169
|
+
for elem in self.getGpuList():
|
|
170
|
+
GpuListCuda = GpuListCuda + str(count) + ' '
|
|
171
|
+
GpuListAux = GpuListAux + str(elem) + ','
|
|
172
|
+
count += 1
|
|
173
|
+
os.environ["CUDA_VISIBLE_DEVICES"] = GpuListAux
|
|
174
|
+
|
|
175
|
+
outImgs, clasesOut = self._getOutputsFn()
|
|
176
|
+
self._params = {'imgsRef': self.imgsRef,
|
|
177
|
+
'imgsExp': inputImgs,
|
|
178
|
+
'outputFile': outImgs,
|
|
179
|
+
'keepBest': self.keepBest.get(),
|
|
180
|
+
'maxshift': self.maximumShift,
|
|
181
|
+
'outputClassesFile': clasesOut,
|
|
182
|
+
'device': GpuListCuda,
|
|
183
|
+
'outputClassesFileNoExt': splitext(clasesOut)[0],
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
args = '-i %(imgsExp)s -r %(imgsRef)s -o %(outputFile)s ' \
|
|
187
|
+
'--keepBestN 1 --oUpdatedRefs %(outputClassesFileNoExt)s --dev %(device)s '
|
|
188
|
+
self.runJob(CUDA_ALIGN_SIGNIFICANT, args % self._params, numberOfMpi=1)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
# ------ Methods for Streaming 2D Classification --------------
|
|
192
|
+
def _stepsCheck(self):
|
|
193
|
+
self._checkNewInput()
|
|
194
|
+
self._checkNewOutput()
|
|
195
|
+
|
|
196
|
+
def _checkNewInput(self):
|
|
197
|
+
""" Check if there are new particles to be processed and add
|
|
198
|
+
the necessary steps."""
|
|
199
|
+
particlesFile = self.inputParticles.get().getFileName()
|
|
200
|
+
|
|
201
|
+
now = datetime.now()
|
|
202
|
+
self.lastCheck = getattr(self, 'lastCheck', now)
|
|
203
|
+
mTime = datetime.fromtimestamp(getmtime(particlesFile))
|
|
204
|
+
self.debug('Last check: %s, modification: %s'
|
|
205
|
+
% (prettyTime(self.lastCheck),
|
|
206
|
+
prettyTime(mTime)))
|
|
207
|
+
|
|
208
|
+
# If the input have not changed since our last check,
|
|
209
|
+
# it does not make sense to check for new input data
|
|
210
|
+
if self.lastCheck > mTime and hasattr(self, 'listOfParticles'):
|
|
211
|
+
return None
|
|
212
|
+
|
|
213
|
+
self.lastCheck = now
|
|
214
|
+
outputStep = self._getFirstJoinStep()
|
|
215
|
+
|
|
216
|
+
# Open input and close it as soon as possible
|
|
217
|
+
self._loadInputList()
|
|
218
|
+
|
|
219
|
+
fDeps=[]
|
|
220
|
+
fDeps = self._insertStepsForParticles(fDeps)
|
|
221
|
+
if outputStep is not None:
|
|
222
|
+
outputStep.addPrerequisites(*fDeps)
|
|
223
|
+
self.updateSteps()
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _checkNewOutput(self):
|
|
227
|
+
""" Check for already done files and update the output set. """
|
|
228
|
+
|
|
229
|
+
# Check for newly done items
|
|
230
|
+
newDone = self._readDoneList()
|
|
231
|
+
|
|
232
|
+
# We have finished when there is not more inputs (stream closed)
|
|
233
|
+
# and the number of processed particles is equal to the number of inputs
|
|
234
|
+
self.finished = (self.isStreamClosed == Set.STREAM_CLOSED
|
|
235
|
+
and len(newDone)==0)
|
|
236
|
+
streamMode = Set.STREAM_CLOSED if self.finished else Set.STREAM_OPEN
|
|
237
|
+
|
|
238
|
+
if newDone:
|
|
239
|
+
self._updateOutputSetOfClasses(newDone, streamMode)
|
|
240
|
+
self.doneListFn += newDone
|
|
241
|
+
|
|
242
|
+
elif not self.finished:
|
|
243
|
+
# If we are not finished and no new output have been produced
|
|
244
|
+
# it does not make sense to proceed and updated the outputs
|
|
245
|
+
# so we exit from the function here
|
|
246
|
+
return
|
|
247
|
+
|
|
248
|
+
if self.finished: # Unlock createOutputStep if finished all jobs
|
|
249
|
+
outputStep = self._getFirstJoinStep()
|
|
250
|
+
if outputStep and outputStep.isWaiting():
|
|
251
|
+
outputStep.setStatus(STATUS_NEW)
|
|
252
|
+
|
|
253
|
+
def createOutputStep(self):
|
|
254
|
+
self._closeOutputSet()
|
|
255
|
+
#pass
|
|
256
|
+
|
|
257
|
+
# --------------------------- INFO functions -------------------------------
|
|
258
|
+
def _validate(self):
|
|
259
|
+
errors = []
|
|
260
|
+
refImage = self.inputRefs.get()
|
|
261
|
+
[x1, y1, _] = refImage.getDimensions()
|
|
262
|
+
[x2, y2, _] = self.inputParticles.get().getDim()
|
|
263
|
+
if x1 != x2 or y1 != y2:
|
|
264
|
+
errors.append('The input images (%s, %s) and the reference images (%s, %s) '
|
|
265
|
+
'have different sizes' % (x1, y1, x2, y2))
|
|
266
|
+
return errors
|
|
267
|
+
|
|
268
|
+
def _summary(self):
|
|
269
|
+
summary = []
|
|
270
|
+
if not hasattr(self, 'outputClasses'):
|
|
271
|
+
summary.append("Output alignment not ready yet.")
|
|
272
|
+
else:
|
|
273
|
+
summary.append("Input Particles: %s"
|
|
274
|
+
% self.inputParticles.get().getSize())
|
|
275
|
+
if isinstance(self.inputRefs.get(), SetOfClasses2D):
|
|
276
|
+
summary.append("Aligned with reference classes: %s"
|
|
277
|
+
% self.inputRefs.get().getSize())
|
|
278
|
+
else:
|
|
279
|
+
summary.append("Aligned with reference averages: %s"
|
|
280
|
+
% self.inputRefs.get().getDimensions())
|
|
281
|
+
return summary
|
|
282
|
+
|
|
283
|
+
def _methods(self):
|
|
284
|
+
methods = []
|
|
285
|
+
if not hasattr(self, 'outputClasses'):
|
|
286
|
+
methods.append("Output alignment not ready yet.")
|
|
287
|
+
else:
|
|
288
|
+
methods.append(
|
|
289
|
+
"We aligned images %s with respect to the reference image set "
|
|
290
|
+
"%s using Xmipp CUDA correlation"
|
|
291
|
+
% (self.getObjectTag('inputParticles'),
|
|
292
|
+
self.getObjectTag('inputRefs')))
|
|
293
|
+
|
|
294
|
+
return methods
|
|
295
|
+
|
|
296
|
+
# --------------------------- UTILS functions ------------------------------
|
|
297
|
+
def _loadInputList(self):
|
|
298
|
+
""" Load the input set of ctfs and create a list. """
|
|
299
|
+
particlesSet = self._loadInputParticleSet()
|
|
300
|
+
|
|
301
|
+
self.isStreamClosed = particlesSet.getStreamState()
|
|
302
|
+
self.listOfParticles = []
|
|
303
|
+
lastDate = self._readCreationTimeFile()
|
|
304
|
+
|
|
305
|
+
for p in particlesSet.iterItems(orderBy='creation',
|
|
306
|
+
where="creation>'%s'"
|
|
307
|
+
% lastDate):
|
|
308
|
+
idx = p.getObjId()
|
|
309
|
+
if not self.htAlreadyProcessed.isItemPresent(idx):
|
|
310
|
+
newPart = p.clone()
|
|
311
|
+
newPart.setObjCreation(p.getObjCreation())
|
|
312
|
+
self.listOfParticles.append(newPart)
|
|
313
|
+
|
|
314
|
+
particlesSet.close()
|
|
315
|
+
self.debug("Closed db.")
|
|
316
|
+
|
|
317
|
+
def _loadInputParticleSet(self):
|
|
318
|
+
partSetFn = self.inputParticles.get().getFileName()
|
|
319
|
+
updatedSet = SetOfParticles(filename=partSetFn)
|
|
320
|
+
copyPartSet = SetOfParticles()
|
|
321
|
+
updatedSet.loadAllProperties()
|
|
322
|
+
copyPartSet.copy(updatedSet)
|
|
323
|
+
updatedSet.close()
|
|
324
|
+
return copyPartSet
|
|
325
|
+
|
|
326
|
+
def _getFirstJoinStep(self):
|
|
327
|
+
for s in self._steps:
|
|
328
|
+
if s.funcName == 'createOutputStep':
|
|
329
|
+
return s
|
|
330
|
+
return None
|
|
331
|
+
|
|
332
|
+
def _readDoneList(self):
|
|
333
|
+
return [fn for fn in self.listOutFn if fn not in self.doneListFn]
|
|
334
|
+
|
|
335
|
+
def _updateOutputSetOfClasses(self, outFnDone, streamMode):
|
|
336
|
+
outputName = 'outputClasses'
|
|
337
|
+
outputClasses = getattr(self, outputName, None)
|
|
338
|
+
firstTime = True
|
|
339
|
+
|
|
340
|
+
if outputClasses is None:
|
|
341
|
+
outputClasses = self._createSetOfClasses2D(self.inputParticles)
|
|
342
|
+
else:
|
|
343
|
+
firstTime = False
|
|
344
|
+
outputClasses = SetOfClasses2D(filename=outputClasses.getFileName())
|
|
345
|
+
outputClasses.setStreamState(streamMode)
|
|
346
|
+
outputClasses.setImages(self.inputParticles)
|
|
347
|
+
|
|
348
|
+
self._fillClassesFromMd(outFnDone, outputClasses, firstTime, streamMode)
|
|
349
|
+
self._updateOutputSet(outputName, outputClasses, streamMode)
|
|
350
|
+
|
|
351
|
+
if firstTime:
|
|
352
|
+
self._defineSourceRelation(self.inputParticles, outputClasses)
|
|
353
|
+
|
|
354
|
+
def _updateParticle(self, item, row):
|
|
355
|
+
item.setClassId(row.getValue(md.MDL_REF))
|
|
356
|
+
item.setTransform(rowToAlignment(row, ALIGN_2D))
|
|
357
|
+
if self.flag_relion:
|
|
358
|
+
item._rlnLogLikeliContribution=Float(None)
|
|
359
|
+
item._rlnMaxValueProbDistribution=Float(None)
|
|
360
|
+
item._rlnGroupName=String(None)
|
|
361
|
+
item._rlnNormCorrection=Float(None)
|
|
362
|
+
|
|
363
|
+
def _fillClassesFromMd(self, outFnDone, outputClasses, firstTime,
|
|
364
|
+
streamMode):
|
|
365
|
+
|
|
366
|
+
for outFn in outFnDone:
|
|
367
|
+
mdImages = md.MetaData(outFn)
|
|
368
|
+
inputSet = self._loadInputParticleSet()
|
|
369
|
+
clsIdList = []
|
|
370
|
+
|
|
371
|
+
if self.useAsRef == REF_CLASSES:
|
|
372
|
+
cls2d = self.inputRefs.get()
|
|
373
|
+
for cls in cls2d:
|
|
374
|
+
for img in cls:
|
|
375
|
+
if img.hasAttribute('_rlnGroupName'):
|
|
376
|
+
self.flag_relion = True
|
|
377
|
+
break
|
|
378
|
+
break
|
|
379
|
+
|
|
380
|
+
if firstTime:
|
|
381
|
+
|
|
382
|
+
self.lastId = 0
|
|
383
|
+
if self.useAsRef == REF_AVERAGES:
|
|
384
|
+
repSet = self.inputRefs.get()
|
|
385
|
+
for rep in repSet:
|
|
386
|
+
repId = rep.getObjId()
|
|
387
|
+
newClass = Class2D(objId=repId)
|
|
388
|
+
newClass.setAlignment2D()
|
|
389
|
+
newClass.copyInfo(inputSet)
|
|
390
|
+
newClass.setAcquisition(inputSet.getAcquisition())
|
|
391
|
+
newClass.setRepresentative(rep)
|
|
392
|
+
newClass.setStreamState(streamMode)
|
|
393
|
+
outputClasses.append(newClass)
|
|
394
|
+
else:
|
|
395
|
+
cls2d = self.inputRefs.get()
|
|
396
|
+
for cls in cls2d:
|
|
397
|
+
representative = cls.getRepresentative()
|
|
398
|
+
repId = cls.getObjId()
|
|
399
|
+
newClass = Class2D(objId=repId)
|
|
400
|
+
newClass.setAlignment2D()
|
|
401
|
+
newClass.copyInfo(inputSet)
|
|
402
|
+
newClass.setAcquisition(inputSet.getAcquisition())
|
|
403
|
+
newClass.setRepresentative(representative)
|
|
404
|
+
newClass.setStreamState(streamMode)
|
|
405
|
+
outputClasses.append(newClass)
|
|
406
|
+
|
|
407
|
+
for imgRow in md.iterRows(mdImages, sortByLabel=md.MDL_REF):
|
|
408
|
+
imgClassId = imgRow.getValue(md.MDL_REF)
|
|
409
|
+
imgId = imgRow.getValue(md.MDL_ITEM_ID)
|
|
410
|
+
|
|
411
|
+
if imgClassId not in clsIdList:
|
|
412
|
+
if len(clsIdList) > 0:
|
|
413
|
+
newClass.setAlignment2D()
|
|
414
|
+
outputClasses.update(newClass)
|
|
415
|
+
newClass = outputClasses[imgClassId]
|
|
416
|
+
newClass.enableAppend()
|
|
417
|
+
clsIdList.append(imgClassId)
|
|
418
|
+
|
|
419
|
+
part = inputSet[imgId]
|
|
420
|
+
self._updateParticle(part, imgRow)
|
|
421
|
+
newClass.append(part)
|
|
422
|
+
|
|
423
|
+
# this is to update the last class into the set.
|
|
424
|
+
newClass.setAlignment2D()
|
|
425
|
+
outputClasses.update(newClass)
|
|
426
|
+
|
|
427
|
+
# FirstTime to False if iterate more than one metadata file.
|
|
428
|
+
if firstTime:
|
|
429
|
+
firstTime = False
|
|
430
|
+
|
|
431
|
+
def _getUniqueFn(self, basename, list):
|
|
432
|
+
if list == []:
|
|
433
|
+
fn = basename + "_1.xmd"
|
|
434
|
+
else:
|
|
435
|
+
number = int(list[-1].split("_")[-1].split(".")[0]) + 1
|
|
436
|
+
fn = basename + "_%s.xmd" % number
|
|
437
|
+
list.append(fn)
|
|
438
|
+
return fn
|
|
439
|
+
|
|
440
|
+
def _getInputFn(self):
|
|
441
|
+
basename = self._getExtraPath('imagesExp')
|
|
442
|
+
return self._getUniqueFn(basename, self.listInFn)
|
|
443
|
+
|
|
444
|
+
def _getOutputsFn(self):
|
|
445
|
+
nameImages = self._getExtraPath('general_images')
|
|
446
|
+
imagesFn = self._getUniqueFn(nameImages, self.listOutFn)
|
|
447
|
+
classesFn = imagesFn.replace('images', 'classes')
|
|
448
|
+
return imagesFn, classesFn
|
|
449
|
+
|
|
450
|
+
def _saveCreationTimeFile(self, cTime):
|
|
451
|
+
fn = open(self._getExtraPath('creation.txt'),'w')
|
|
452
|
+
fn.write(cTime)
|
|
453
|
+
fn.close()
|
|
454
|
+
|
|
455
|
+
def _readCreationTimeFile(self):
|
|
456
|
+
if exists(self._getExtraPath('creation.txt')):
|
|
457
|
+
fn = open(self._getExtraPath('creation.txt'), 'r')
|
|
458
|
+
cTime = fn.readline()
|
|
459
|
+
fn.close()
|
|
460
|
+
else:
|
|
461
|
+
cTime = 0
|
|
462
|
+
return cTime
|