3535from  pyworkflow .protocol .params  import  LEVEL_ADVANCED ,IntParam , FloatParam , EnumParam , PointerParam , TextParam , BooleanParam 
3636from  tomo .protocols  import  ProtTomoBase 
3737from  tomo .objects  import  SetOfSubTomograms , SubTomogram , TomoAcquisition , Coordinate3D , SetOfCoordinates3D 
38+ from  pwem .objects  import  Acquisition , Volume 
3839
3940import  tomo .constants  as  const 
4041from  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 ])
0 commit comments