Skip to content

Commit fe2d616

Browse files
authored
Merge branch 'devel' into tests
2 parents 460f9d0 + 4464933 commit fe2d616

File tree

5 files changed

+64
-20
lines changed

5 files changed

+64
-20
lines changed

xmipptomo/protocols/protocol_phantom_subtomo.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from pyworkflow.protocol.params import LEVEL_ADVANCED,IntParam, FloatParam, EnumParam, PointerParam, TextParam, BooleanParam
3636
from tomo.protocols import ProtTomoBase
3737
from tomo.objects import SetOfSubTomograms, SubTomogram, TomoAcquisition, Coordinate3D, SetOfCoordinates3D
38+
from pwem.objects import Acquisition, Volume
3839

3940
import tomo.constants as const
4041
from pwem.convert.headers import setMRCSamplingRate
@@ -181,13 +182,13 @@ def _defineParams(self, form):
181182
lineStat.addParam('meanNoise', IntParam, label='mean', default=0, condition='not differentStatistics')
182183
lineStat.addParam('stdNoise', IntParam, label='std', default=40, condition='not differentStatistics')
183184

185+
184186
# --------------------------- INSERT steps functions --------------------------------------------
185187
def _insertAllSteps(self):
186188

187189
#NOTE: This protocol was discussed with the ScipionTeam about if the subtomograms have or do not have tomogramId.
188190
# The agreement was that the tomogramId should not appear if subtomograms are imported or phantoms created
189191
self._insertFunctionStep(self.createSubtomogramsStep)
190-
self._insertFunctionStep(self.createOutputStep)
191192

192193
# --------------------------- STEPS functions --------------------------------------------
193194
def createSubtomogramsStep(self):
@@ -197,24 +198,38 @@ def createPhantomSubtomograms(self):
197198
if self.mwfilter.get():
198199
mwangle = self.mwangle.get()
199200
else:
200-
mwangle = 90
201+
mwangle = 90.0
201202

202203
fnInVol = None
203204
dim = None
204205
if self.option == 0:
205206
inputVol = self.inputVolume.get()
206207
fnInVol = inputVol.getFileName()
207208
dim = inputVol.getDim()
209+
fnRef = self.inputVolume.get().getFileName()
208210
if self.option == 1:
209211
dim, fnInVol = self.createGeometricalPhantom()
212+
fnRef = self._getExtraPath(FN_PHANTOM+MRC_EXT)
213+
214+
if self.nsubtomos.get() == 1:
215+
volume = Volume()
216+
volume.setFileName(fnRef)
217+
volume.setSamplingRate(self.sampling.get())
218+
self._defineOutputs(outputVolume=volume)
219+
if self.option.get() == 0:
220+
self._defineSourceRelation(self.inputVolume.get(), volume)
221+
else:
222+
self.definingOrientationsAndRegisteringInformation(dim, mwangle, fnInVol)
223+
self.createOutputStep()
210224

211-
self.definingOrientationsAndRegisteringInformation(dim, mwangle, fnInVol)
212225

213226
def definingOrientationsAndRegisteringInformation(self, dim, mwangle, fnVol):
227+
228+
numberOfSubtomos = self.nsubtomos.get()
214229
self.createOutputSet(dim)
230+
215231
tomo = None
216-
coordsBool = self.generateCoordinates()
217-
if coordsBool:
232+
if self.generateCoordinates():
218233
tomos = self.tomos.get()
219234
tomo = tomos.getFirstItem()
220235
self.coordsSet = self._createSetOfCoordinates3D(tomos)
@@ -228,11 +243,21 @@ def definingOrientationsAndRegisteringInformation(self, dim, mwangle, fnVol):
228243
acq = TomoAcquisition()
229244
acq.setAngleMax(mwangle)
230245
acq.setAngleMin(mwangle * -1)
246+
acq.setStep(3.0)
247+
acq.setAccumDose(100.0)
248+
acq.setDosePerFrame(3.0)
249+
acq.setTiltAxisAngle(0.0)
250+
251+
acq.setAmplitudeContrast(0.1)
252+
acq.setSphericalAberration(2.7)
253+
acq.setVoltage(300)
254+
acq.setMagnification(50000)
255+
231256

232257
if self.randomseed.get():
233258
np.random.seed(42)
234259

235-
for i in range(int(self.nsubtomos.get())):
260+
for i in range(int(numberOfSubtomos)):
236261
fnPhantomi = self._getExtraPath(FN_PHANTOM + str(int(i+1)) + MRC_EXT)
237262

238263
if self.addNoise.get():
@@ -254,6 +279,7 @@ def definingOrientationsAndRegisteringInformation(self, dim, mwangle, fnVol):
254279
# Add the subtomogram and the coordinate if applies
255280
self._addSubtomogram(tomo, acq, fn_aux, rot, tilt, psi, shiftX, shiftY, shiftZ)
256281

282+
257283
def createGeometricalPhantom(self):
258284
fnVol = self._getExtraPath(FN_PHANTOM+MRC_EXT)
259285
desc = self.create.get()
@@ -374,6 +400,7 @@ def createOutputSet(self, dim):
374400
self.outputSet.setDim(dim)
375401
self.outputSet.setSamplingRate(self.sampling.get())
376402

403+
377404
def _addSubtomogram(self, tomo, acq, phantomfn, rot, tilt, psi, shiftX, shiftY, shiftZ):
378405
""" Creates and adds a the phantom subtomogram to the set. It creates the coordinate as well if active"""
379406
subtomo = SubTomogram()
@@ -389,6 +416,7 @@ def _addSubtomogram(self, tomo, acq, phantomfn, rot, tilt, psi, shiftX, shiftY,
389416
subtomo.phantom_shiftX = Integer(shiftX)
390417
subtomo.phantom_shiftY = Integer(shiftY)
391418
subtomo.phantom_shiftZ = Integer(shiftZ)
419+
392420

393421
# Scipion alignment matrix
394422
A = euler_matrix(np.deg2rad(psi), np.deg2rad(tilt), np.deg2rad(rot), 'szyz')
@@ -419,6 +447,7 @@ def _addCoordinate(self, subtomo, tomo):
419447
coor.setX(rng.integers(tomoDim[0]), const.BOTTOM_LEFT_CORNER)
420448
coor.setY(rng.integers(tomoDim[1]), const.BOTTOM_LEFT_CORNER)
421449
coor.setZ(rng.integers(tomoDim[2]), const.BOTTOM_LEFT_CORNER)
450+
coor.setVolId(1)
422451

423452
self.coordsSet.append(coor)
424453
self.coordsSet.setBoxSize(subtomo.getDim()[0])

xmipptomo/protocols/protocol_resolution_local_monotomo.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from pwem.emlib.image import ImageHandler
3939
import pwem.emlib.metadata as md
4040
from pwem.protocols import EMProtocol
41+
from pyworkflow import utils as pwutils
4142

4243
from tomo.protocols import ProtTomoBase
4344
from tomo.objects import Tomogram
@@ -120,7 +121,7 @@ def _defineParams(self, form):
120121

121122
line.addParam('minRes', FloatParam, default=0, label='High')
122123
line.addParam('maxRes', FloatParam, allowsNull=True, label='Low')
123-
line.addParam('stepSize', FloatParam, allowsNull=True, default=0.5,
124+
line.addParam('stepSize', FloatParam, allowsNull=True, default=1.0,
124125
expertLevel=LEVEL_ADVANCED, label='Step')
125126

126127
form.addParallelSection(threads=4, mpi=0)
@@ -179,7 +180,8 @@ def resolutionMonoTomoStep(self, tomId):
179180

180181
# Defining the output folder
181182
tomoPath = self._getExtraPath(tsId)
182-
os.mkdir(tomoPath)
183+
184+
pwutils.path.makePath(tomoPath)
183185

184186
# Defining outfiles
185187
outputlocalResTomoFn = self.createOutputPath(TOMOGRAM_RESOLUTION_FILE, tsId, MRCEXT)

xmipptomo/protocols/protocol_subtraction_subtomo.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@
2626
# *
2727
# **************************************************************************
2828

29-
from pyworkflow import BETA, UPDATED, NEW, PROD
29+
from pyworkflow import UPDATED
3030
from pyworkflow.protocol.params import PointerParam, BooleanParam, IntParam, FloatParam
3131
from pyworkflow.protocol.constants import LEVEL_ADVANCED
3232
from pwem.protocols import EMProtocol
33+
from pwem.objects import Volume
3334
from pwem.constants import ALIGN_3D
3435
from tomo.protocols import ProtTomoBase
36+
from tomo.objects import SetOfSubTomograms, SubTomogram
37+
import pwem.emlib.metadata as md
38+
from pwem.emlib import lib
3539
from xmipptomo.convert import writeSetOfSubtomograms, readSetOfSubtomograms
3640

3741
OUTPUT = "output_subtomograms.xmd"
@@ -51,7 +55,7 @@ def _defineParams(self, form):
5155
form.addSection(label='Input')
5256
form.addParam('inputSubtomos', PointerParam, pointerClass='SetOfSubTomograms', label="Subtomograms ",
5357
help='Select the SetOfSubTomograms with transform matrix which will be subtracted.')
54-
form.addParam('average', PointerParam, pointerClass='SubTomogram', label="Average subtomogram ",
58+
form.addParam('average', PointerParam, pointerClass='Volume', label="Average subtomogram ",
5559
help='Select an average subtomogram to be subtracted.')
5660
form.addParam('maskBool', BooleanParam, label='Mask subtomograms?', default=True,
5761
help='The mask are not mandatory but highly recommendable.')
@@ -79,9 +83,9 @@ def _defineParams(self, form):
7983

8084
# --------------------------- INSERT steps functions --------------------------------------------
8185
def _insertAllSteps(self):
82-
self._insertFunctionStep('convertStep')
83-
self._insertFunctionStep('subtractionStep')
84-
self._insertFunctionStep('createOutputStep')
86+
self._insertFunctionStep(self.convertStep)
87+
self._insertFunctionStep(self.subtractionStep)
88+
self._insertFunctionStep(self.createOutputStep)
8589

8690
# --------------------------- STEPS functions --------------------------------------------
8791
def convertStep(self):
@@ -114,7 +118,19 @@ def createOutputStep(self):
114118
inputSubtomos = self.inputSubtomos.get()
115119
outputSet = self._createSetOfSubTomograms()
116120
outputSet.copyInfo(inputSubtomos)
117-
readSetOfSubtomograms(self._getExtraPath(OUTPUT), outputSet, alignType=ALIGN_3D)
121+
sampling = self.average.get().getSamplingRate()
122+
#readSetOfSubtomograms(self._getExtraPath(OUTPUT), outputSet, alignType=ALIGN_3D)
123+
124+
mdsubtomos = lib.MetaData(self._getExtraPath(OUTPUT))
125+
126+
for row in md.iterRows(mdsubtomos):
127+
idx = row.getValue(md.MDL_PARTICLE_ID)
128+
subtomo = SubTomogram(objId=idx)
129+
fn = row.getValue(md.MDL_IMAGE)
130+
subtomo.setFileName(fn)
131+
subtomo.setSamplingRate(sampling)
132+
outputSet.append(subtomo)
133+
118134
self._defineOutputs(outputSubtomograms=outputSet)
119135
self._defineSourceRelation(inputSubtomos, outputSet)
120136

xmipptomo/tests/test_protocol_monotomo.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,13 @@ def testMonoTomo(self):
6464
useMask=False,
6565
minRes=1,
6666
maxRes=150,
67+
stepSize = 5.0
6768
)
6869
self.launchProtocol(MonoTomo)
69-
self.assertTrue(exists(MonoTomo._getExtraPath('odd_tomogram_rx1/fullTomogram_odd_tomogram_rx1.mrc')),
70-
"MonoTomo has failed creating the resolution tomogram")
7170
self.assertTrue(exists(MonoTomo._getExtraPath('odd_tomogram_rx1/histogram_resolution_odd_tomogram_rx1.xmd')),
7271
"MonoTomo has failed creating the resolution histogram")
7372
self.assertTrue(exists(MonoTomo._getExtraPath('odd_tomogram_rx1/localResolutionTomogram_odd_tomogram_rx1.mrc')),
7473
"MonoTomo has failed creating the mean tomogram")
75-
self.assertTrue(exists(MonoTomo._getExtraPath('odd_tomogram_rx2/fullTomogram_odd_tomogram_rx2.mrc')),
76-
"MonoTomo has failed creating the resolution tomogram")
7774
self.assertTrue(exists(MonoTomo._getExtraPath('odd_tomogram_rx2/histogram_resolution_odd_tomogram_rx2.xmd')),
7875
"MonoTomo has failed creating the resolution histogram")
7976
self.assertTrue(exists(MonoTomo._getExtraPath('odd_tomogram_rx2/localResolutionTomogram_odd_tomogram_rx2.mrc')),

xmipptomo/tests/test_protocol_subtraction_subtomo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _runPreviousProtocols(self):
4242
option=1,
4343
nsubtomos=1)
4444
self.launchProtocol(createAverage)
45-
self.assertIsNotNone(createAverage.outputSubtomograms,
45+
self.assertIsNotNone(createAverage.outputVolume,
4646
"There was a problem with subtomogram average phantom output")
4747
createSubtomos = self.newProtocol(XmippProtPhantomSubtomo,
4848
option=1,
@@ -58,7 +58,7 @@ def test_subtraction(self):
5858
createAverage, createSubtomos = self._runPreviousProtocols()
5959
subtraction = self.newProtocol(XmippProtSubtractionSubtomo,
6060
inputSubtomos=createSubtomos.outputSubtomograms,
61-
average=createAverage.outputSubtomograms,
61+
average=createAverage.outputVolume,
6262
maskBool=False)
6363
self.launchProtocol(subtraction)
6464
self.assertIsNotNone(subtraction.outputSubtomograms,

0 commit comments

Comments
 (0)