def setupXmippML3DProtocol(self):       
                ''' sets up ML3D protocol parameters, pickles to file, etc.'''
        
                protocolname = 'xmipp_protocol_ml3d'
                ### Locate protocol_ml3d
                protocol_ml3d = apXmipp.locateXmippProtocol(protocolname)
                                
                ### setup protocol parameters
                protocolPrm = {}
                ### check for n input model dependencies
                protocolPrm["InitialReference"]                                 =       self.params['modelnames'][0]
                if len(self.params['modelnames']) > 1:
                        selfile = "reference_volumes.sel"
                        sf = open(selfile, "w")
                        for model in self.params['modelnames']: 
                                sf.write("%s\t1\n" % os.path.join(self.params['rundir'], model))
                        sf.close()              
                        protocolPrm["SeedsSelfile"]                             =       os.path.join(self.params['rundir'], "reference_volumes.sel")
                        protocolPrm["DoGenerateSeeds"]                  =       False                   
                else:
                        protocolPrm["SeedsSelfile"]                             =       ""
                        protocolPrm["DoGenerateSeeds"]                  =       True
                protocolPrm["InSelFile"]                                        =       "partlist.sel" ### this maybe should not be hardcoded
                protocolPrm["WorkingDir"]                                       =       "ml3d"
                protocolPrm["DoDeleteWorkingDir"]                       =       False
                protocolPrm["ProjectDir"]                                       =       self.params['recondir']
                protocolPrm["LogDir"]                                           =       "Logs"
                protocolPrm["DoMlf"]                                            =       self.params['DoMlf']
                protocolPrm["DoCorrectAmplitudes"]                      =       False   
                protocolPrm["InCtfDatFile"]                                     =       "all_images.ctfdat"
                protocolPrm["HighResLimit"]                                     =       self.params['HighResLimit']
                protocolPrm["ImagesArePhaseFlipped"]            =       self.params['ImagesArePhaseFlipped']
                protocolPrm["InitialMapIsAmplitudeCorrected"]   =       False
                protocolPrm["SeedsAreAmplitudeCorrected"]               =       False
                protocolPrm["DoCorrectGreyScale"]                               =       self.params['DoCorrectGreyScale']       
                protocolPrm["ProjMatchSampling"]                                =       self.params['ProjMatchSampling']
                if (self.params['LowPassFilter']>1) is True:
                        protocolPrm["DoLowPassFilterReference"]         =       True    
                        protocolPrm["LowPassFilter"]                            =       self.params['LowPassFilter']
                else:
                        protocolPrm["DoLowPassFilterReference"]         =       False
                        protocolPrm["LowPassFilter"]                            =       self.params['LowPassFilter']
                protocolPrm["PixelSize"]                                        =       self.params['apix']
                protocolPrm["NumberOfReferences"]                               =       self.params['NumberOfReferences']
                protocolPrm["DoJustRefine"]                                         =   False
                protocolPrm["DoML3DClassification"]                             =       True
                protocolPrm["AngularSampling"]                                  =       self.params['AngularSampling']
                protocolPrm["NumberOfIterations"]                               =       self.params['numiter']
                protocolPrm["Symmetry"]                                         =       self.params['symmetry'][0]
                protocolPrm["DoNorm"]                                           =       False
                protocolPrm["DoFourier"]                                        =       False
                protocolPrm["RestartIter"]                                      =       0
                protocolPrm["ExtraParamsMLrefine3D"]                            =       ""
                protocolPrm["NumberOfThreads"]                                  =       1
                protocolPrm["DoParallel"]                                       =       self.params['nproc']>1
                protocolPrm["NumberOfMpiProcesses"]                             =       self.params['nproc']
                protocolPrm["SystemFlavour"]                                    =       ""
                protocolPrm["AnalysisScript"]                                   =       "visualize_ml3d.py"
                
                ### write out python protocol into run directory
                protocolfile = os.path.join(self.params['remoterundir'],"%s.py" % protocolname)
                apXmipp.particularizeProtocol(protocol_ml3d, protocolPrm, protocolfile)
                os.chmod(os.path.join(self.params['rundir'], protocolfile), 0775)
                                
                ### Write the parameters for posterior uploading, both generic and specific
                self.runparams = {}
                self.runparams['reconstruction_package'] = "xmipp_ml3d"
                self.runparams['remoterundir'] = self.params['remoterundir']
#               self.runparams['reconstruction_working_dir'] = protocolPrm["WorkingDir"]                
                self.runparams['reconstruction_working_dir'] = protocolPrm['WorkingDir']+"/RunML3D"
                self.runparams['numiter'] = protocolPrm['NumberOfIterations']
                self.runparams['NumberOfReferences'] = protocolPrm['NumberOfReferences']
                self.runparams['symmetry'] = protocolPrm["Symmetry"]
                self.runparams['package_params'] = protocolPrm
                paramfile = os.path.join(self.params['remoterundir'], "xmipp_ml3d_"+self.timestamp+"-params.pickle")
                apParam.dumpParameters(self.runparams, paramfile)
                
                ### finished setup of input files, now run xmipp_protocols_ml3d.py from jobfile
                apDisplay.printMsg("finished setting up input files, now running xmipp_protocols_ml3d.py")
                                
                return protocolfile, protocolPrm
        def setupXmippProtocol(self):
                protocolname = 'xmipp_protocol_projmatch'
                # Locate protocol_projmatch
                protocol_projmatch=apXmipp.locateXmippProtocol(protocolname)

                #make threads and mpi processes compatible with the xmipprequirement
                self.params['alwaysone']=1
                
                protocolPrm={}
                protocolPrm["SelFileName"]                  =   "partlist.sel"
                protocolPrm["DocFileName"]                  =   ""
                protocolPrm["ReferenceFileName"]            =   self.params['modelnames'][0]
                protocolPrm["WorkingDir"]                   =   "ProjMatch"
                protocolPrm["DoDeleteWorkingDir"]           =   True
                protocolPrm["NumberofIterations"]           =   self.params['enditer']
                protocolPrm["ContinueAtIteration"]          =   self.params['startiter']
                protocolPrm["CleanUpFiles"]                 =   False
                protocolPrm["ProjectDir"]                   =   self.params['recondir']
                protocolPrm["LogDir"]                       =   "Logs"
                protocolPrm["DoCtfCorrection"]              =   False
                protocolPrm["CTFDatName"]                   =   ""
                protocolPrm["DoAutoCtfGroup"]               =   False
                protocolPrm["CtfGroupMaxDiff"]              =   0.5
                protocolPrm["CtfGroupMaxResol"]             =   15
                protocolPrm["SplitDefocusDocFile"]          =   ""
                protocolPrm["PaddingFactor"]                =   2
                protocolPrm["WienerConstant"]               =   -1
                protocolPrm["DataArePhaseFlipped"]          =   True
                protocolPrm["ReferenceIsCtfCorrected"]      =   True
                protocolPrm["DoMask"]                       =   self.params['maskvol']>0
                protocolPrm["DoSphericalMask"]              =   self.params['outerMaskRadius']>0
                # split is needed because refineJob base class defines outMaskRadius as iteration parameter but xmipp can
                # no accept such assignment     
                protocolPrm["MaskRadius"]                   =   self.convertAngstromToPixel( self.params['outerMaskRadius'].split()[0] )
                protocolPrm["MaskFileName"]                 =   self.params['maskvol']
                protocolPrm["DoProjectionMatching"]         =   True
                protocolPrm["DisplayProjectionMatching"]    =   False
                protocolPrm["InnerRadius"]                  =  self.convertAngstromToPixel( self.params['innerAlignRadius'] )
                protocolPrm["OuterRadius"]                  =  self.convertAngstromToPixel( self.params['outerAlignRadius'] )
                protocolPrm["AvailableMemory"]              =   self.calcRefineMem()
#               protocolPrm["AngSamplingRateDeg"]           =   self.params['AngularSteps']
                protocolPrm["AngSamplingRateDeg"]           =   self.params['angSampRate']
                protocolPrm["MaxChangeInAngles"]            =   self.params['maxAngularChange']
                protocolPrm["PerturbProjectionDirections"]  =   False
                protocolPrm["MaxChangeOffset"]              =   self.params['maxChangeOffset']
                protocolPrm["Search5DShift"]                =   self.params['search5DShift']
                protocolPrm["Search5DStep"]                 =   self.params['search5DStep']
                protocolPrm["DoRetricSearchbyTiltAngle"]    =   False
                protocolPrm["Tilt0"]                        =   0
                protocolPrm["TiltF"]                        =   0
                protocolPrm["SymmetryGroup"]                =   self.params['symmetry']
                protocolPrm["SymmetryGroupNeighbourhood"]   =   ''
                protocolPrm["OnlyWinner"]                   =   False
                protocolPrm["MinimumCrossCorrelation"]      =   '-1'
                protocolPrm["DiscardPercentage"]            =   self.params['percentDiscard']
                protocolPrm["ProjMatchingExtra"]            =   ''
                protocolPrm["DoAlign2D"]                    =   '0'
                protocolPrm["Align2DIterNr"]                =   4
                protocolPrm["Align2dMaxChangeOffset"]       =   '1000'
                protocolPrm["Align2dMaxChangeRot"]          =   '1000'
                if not self.params['refineonly']:
                        protocolPrm["DoReconstruction"]             =   True
                else:
                        protocolPrm["DoReconstruction"]             =   False
                protocolPrm["DisplayReconstruction"]        =   False
                protocolPrm["ARTLambda"]                    =   self.params['ARTLambda']
                protocolPrm["ARTReconstructionExtraCommand"]=   ''
                protocolPrm["FourierMaxFrequencyOfInterest"]=   self.params['fouriermaxfrequencyofinterest']
                protocolPrm["WBPReconstructionExtraCommand"]=''
                protocolPrm["FourierReconstructionExtraCommand"]=''
                if not self.params['refineonly']:
                        protocolPrm["ReconstructionMethod"]         =   self.params['reconMethod']
                        protocolPrm["DoComputeResolution"]          =   self.params['docomputeresolution']
                        protocolPrm["DoSplitReferenceImages"]       =   True
                        protocolPrm["DoLowPassFilter"]              =   self.params['dolowpassfilter']
                        protocolPrm["UseFscForFilter"]              =   self.params['usefscforfilter']
                else:
                        #Xmipp does not allow False SplitReferenceImage except the exact syntex of 'fourier' in ReconstructionMethod
                        protocolPrm["ReconstructionMethod"]         =   'fourier'
                        #These should never be used if reconstruction is not done
                        protocolPrm["DoComputeResolution"]          =   False
                        protocolPrm["DoSplitReferenceImages"]       =   False
                        protocolPrm["DoLowPassFilter"]              =   False 
                        protocolPrm["UseFscForFilter"]              =   False
                protocolPrm["ResolSam"]                     =   self.params['apix']
                protocolPrm["DisplayResolution"]            =   False
                if self.params['usefscforfilter'] is False and self.params['filterResolution']:
                        protocolPrm["ConstantToAddToFiltration"] = str(self.params['apix'] / self.params['filterResolution'])
                else:
                        protocolPrm["ConstantToAddToFiltration"]    =   str(self.params['filterConstant'])
                print protocolPrm["ConstantToAddToFiltration"]
                protocolPrm["NumberOfThreads"]              =   self.params['alwaysone']
                protocolPrm["DoParallel"]                   =   self.params['nproc']>1
                protocolPrm["NumberOfMpiProcesses"]         =   self.params['nproc']
                protocolPrm["MpiJobSize"]                   =   '10'
                protocolPrm["SystemFlavour"]                =   ''
                protocolPrm["AnalysisScript"]               =   'visualize_projmatch.py'

                ### write out python protocol into run directory
                protocolfile = os.path.join(self.params['remoterundir'],"%s.py" % protocolname)
                if self.params['refineonly']:
                        tempprotocolfile = os.path.join(self.params['remoterundir'],"%s.temp" % protocolname)
                        apXmipp.fixRefineOnlyProtocol(protocol_projmatch,tempprotocolfile)
                        apXmipp.particularizeProtocol(tempprotocolfile, protocolPrm, protocolfile)
                        os.remove(tempprotocolfile)
                else:
                        apXmipp.particularizeProtocol(protocol_projmatch, protocolPrm, protocolfile)
                os.chmod(os.path.join(self.params['rundir'], protocolfile), 0775)
                                
                ### Write the parameters for posterior uploading, both generic and specific
                self.runparams = {} ### these are generic params that includes a dictionary entry for package-specific params
#               self.runparams['symmetry'] = apSymmetry.getSymmetryDataFromName(self.params['symmetry'])

                #sym = apSymmetry.getSymmetryDataFromID(self.params['symmetry'])
                #sym2 = self.convertSymmetryNameForPackage(sym)
                
                sym = protocolPrm["SymmetryGroup"][0]
                if sym in ('i','I'):
                        self.runparams['symmetry'] = "Icos (2 3 5) Viper/3DEM"
                else:
                        self.runparams['symmetry'] = protocolPrm["SymmetryGroup"]
                self.runparams['numiter'] = protocolPrm['NumberofIterations']
                self.runparams['mask'] = protocolPrm["MaskRadius"] 
                self.runparams['imask'] = None
                self.runparams['alignmentInnerRadius'] = protocolPrm["InnerRadius"] 
                self.runparams['alignmentOuterRadius'] = protocolPrm["OuterRadius"]
                self.runparams['reconstruction_package'] = "Xmipp"
                self.runparams['remoterundir'] = self.params['remoterundir']
                self.runparams['reconstruction_working_dir'] = protocolPrm["WorkingDir"] 
                self.runparams['package_params'] = protocolPrm
                self.picklefile = os.path.join(self.params['remoterundir'], "xmipp_projection_matching_"+self.timestamp+"-params.pickle")
                apParam.dumpParameters(self.runparams, self.picklefile)
                
                ### finished setup of input files, now run xmipp_protocols_ml3d.py from jobfile
                apDisplay.printMsg("finished setting up input files, now ready to run protocol")

                return protocolfile, protocolPrm
    def setupXmippProtocol(self):
        protocolname = 'xmipp_protocol_projmatch'
        # Locate protocol_projmatch
        protocol_projmatch = apXmipp.locateXmippProtocol(protocolname)

        #make threads and mpi processes compatible with the xmipprequirement
        self.params['alwaysone'] = 1

        protocolPrm = {}
        protocolPrm["SelFileName"] = "partlist.sel"
        protocolPrm["DocFileName"] = ""
        protocolPrm["ReferenceFileName"] = self.params['modelnames'][0]
        protocolPrm["WorkingDir"] = "ProjMatch"
        protocolPrm["DoDeleteWorkingDir"] = True
        protocolPrm["NumberofIterations"] = self.params['enditer']
        protocolPrm["ContinueAtIteration"] = self.params['startiter']
        protocolPrm["CleanUpFiles"] = False
        protocolPrm["ProjectDir"] = self.params['recondir']
        protocolPrm["LogDir"] = "Logs"
        protocolPrm["DoCtfCorrection"] = False
        protocolPrm["CTFDatName"] = ""
        protocolPrm["DoAutoCtfGroup"] = False
        protocolPrm["CtfGroupMaxDiff"] = 0.5
        protocolPrm["CtfGroupMaxResol"] = 15
        protocolPrm["SplitDefocusDocFile"] = ""
        protocolPrm["PaddingFactor"] = 2
        protocolPrm["WienerConstant"] = -1
        protocolPrm["DataArePhaseFlipped"] = True
        protocolPrm["ReferenceIsCtfCorrected"] = True
        protocolPrm["DoMask"] = self.params['maskvol'] > 0
        protocolPrm["DoSphericalMask"] = self.params['outerMaskRadius'] > 0
        # split is needed because refineJob base class defines outMaskRadius as iteration parameter but xmipp can
        # no accept such assignment
        protocolPrm["MaskRadius"] = self.convertAngstromToPixel(
            self.params['outerMaskRadius'].split()[0])
        protocolPrm["MaskFileName"] = self.params['maskvol']
        protocolPrm["DoProjectionMatching"] = True
        protocolPrm["DisplayProjectionMatching"] = False
        protocolPrm["InnerRadius"] = self.convertAngstromToPixel(
            self.params['innerAlignRadius'])
        protocolPrm["OuterRadius"] = self.convertAngstromToPixel(
            self.params['outerAlignRadius'])
        protocolPrm["AvailableMemory"] = self.calcRefineMem()
        #		protocolPrm["AngSamplingRateDeg"]           =   self.params['AngularSteps']
        protocolPrm["AngSamplingRateDeg"] = self.params['angSampRate']
        protocolPrm["MaxChangeInAngles"] = self.params['maxAngularChange']
        protocolPrm["PerturbProjectionDirections"] = False
        protocolPrm["MaxChangeOffset"] = self.params['maxChangeOffset']
        protocolPrm["Search5DShift"] = self.params['search5DShift']
        protocolPrm["Search5DStep"] = self.params['search5DStep']
        protocolPrm["DoRetricSearchbyTiltAngle"] = False
        protocolPrm["Tilt0"] = 0
        protocolPrm["TiltF"] = 0
        protocolPrm["SymmetryGroup"] = self.params['symmetry']
        protocolPrm["SymmetryGroupNeighbourhood"] = ''
        protocolPrm["OnlyWinner"] = False
        protocolPrm["MinimumCrossCorrelation"] = '-1'
        protocolPrm["DiscardPercentage"] = self.params['percentDiscard']
        protocolPrm["ProjMatchingExtra"] = ''
        protocolPrm["DoAlign2D"] = '0'
        protocolPrm["Align2DIterNr"] = 4
        protocolPrm["Align2dMaxChangeOffset"] = '1000'
        protocolPrm["Align2dMaxChangeRot"] = '1000'
        if not self.params['refineonly']:
            protocolPrm["DoReconstruction"] = True
        else:
            protocolPrm["DoReconstruction"] = False
        protocolPrm["DisplayReconstruction"] = False
        protocolPrm["ARTLambda"] = self.params['ARTLambda']
        protocolPrm["ARTReconstructionExtraCommand"] = ''
        protocolPrm["FourierMaxFrequencyOfInterest"] = self.params[
            'fouriermaxfrequencyofinterest']
        protocolPrm["WBPReconstructionExtraCommand"] = ''
        protocolPrm["FourierReconstructionExtraCommand"] = ''
        if not self.params['refineonly']:
            protocolPrm["ReconstructionMethod"] = self.params['reconMethod']
            protocolPrm["DoComputeResolution"] = self.params[
                'docomputeresolution']
            protocolPrm["DoSplitReferenceImages"] = True
            protocolPrm["DoLowPassFilter"] = self.params['dolowpassfilter']
            protocolPrm["UseFscForFilter"] = self.params['usefscforfilter']
        else:
            #Xmipp does not allow False SplitReferenceImage except the exact syntex of 'fourier' in ReconstructionMethod
            protocolPrm["ReconstructionMethod"] = 'fourier'
            #These should never be used if reconstruction is not done
            protocolPrm["DoComputeResolution"] = False
            protocolPrm["DoSplitReferenceImages"] = False
            protocolPrm["DoLowPassFilter"] = False
            protocolPrm["UseFscForFilter"] = False
        protocolPrm["ResolSam"] = self.params['apix']
        protocolPrm["DisplayResolution"] = False
        if self.params['usefscforfilter'] is False and self.params[
                'filterResolution']:
            protocolPrm["ConstantToAddToFiltration"] = str(
                self.params['apix'] / self.params['filterResolution'])
        else:
            protocolPrm["ConstantToAddToFiltration"] = str(
                self.params['filterConstant'])
        print protocolPrm["ConstantToAddToFiltration"]
        protocolPrm["NumberOfThreads"] = self.params['alwaysone']
        protocolPrm["DoParallel"] = self.params['nproc'] > 1
        protocolPrm["NumberOfMpiProcesses"] = self.params['nproc']
        protocolPrm["MpiJobSize"] = '10'
        protocolPrm["SystemFlavour"] = ''
        protocolPrm["AnalysisScript"] = 'visualize_projmatch.py'

        ### write out python protocol into run directory
        protocolfile = os.path.join(self.params['remoterundir'],
                                    "%s.py" % protocolname)
        if self.params['refineonly']:
            tempprotocolfile = os.path.join(self.params['remoterundir'],
                                            "%s.temp" % protocolname)
            apXmipp.fixRefineOnlyProtocol(protocol_projmatch, tempprotocolfile)
            apXmipp.particularizeProtocol(tempprotocolfile, protocolPrm,
                                          protocolfile)
            os.remove(tempprotocolfile)
        else:
            apXmipp.particularizeProtocol(protocol_projmatch, protocolPrm,
                                          protocolfile)
        os.chmod(os.path.join(self.params['rundir'], protocolfile), 0775)

        ### Write the parameters for posterior uploading, both generic and specific
        self.runparams = {
        }  ### these are generic params that includes a dictionary entry for package-specific params
        #		self.runparams['symmetry'] = apSymmetry.getSymmetryDataFromName(self.params['symmetry'])

        #sym = apSymmetry.getSymmetryDataFromID(self.params['symmetry'])
        #sym2 = self.convertSymmetryNameForPackage(sym)

        sym = protocolPrm["SymmetryGroup"][0]
        if sym in ('i', 'I'):
            self.runparams['symmetry'] = "Icos (2 3 5) Viper/3DEM"
        else:
            self.runparams['symmetry'] = protocolPrm["SymmetryGroup"]
        self.runparams['numiter'] = protocolPrm['NumberofIterations']
        self.runparams['mask'] = protocolPrm["MaskRadius"]
        self.runparams['imask'] = None
        self.runparams['alignmentInnerRadius'] = protocolPrm["InnerRadius"]
        self.runparams['alignmentOuterRadius'] = protocolPrm["OuterRadius"]
        self.runparams['reconstruction_package'] = "Xmipp"
        self.runparams['remoterundir'] = self.params['remoterundir']
        self.runparams['reconstruction_working_dir'] = protocolPrm[
            "WorkingDir"]
        self.runparams['package_params'] = protocolPrm
        self.picklefile = os.path.join(
            self.params['remoterundir'],
            "xmipp_projection_matching_" + self.timestamp + "-params.pickle")
        apParam.dumpParameters(self.runparams, self.picklefile)

        ### finished setup of input files, now run xmipp_protocols_ml3d.py from jobfile
        apDisplay.printMsg(
            "finished setting up input files, now ready to run protocol")

        return protocolfile, protocolPrm
    def setupXmippML3DProtocol(self):
        ''' sets up ML3D protocol parameters, pickles to file, etc.'''

        protocolname = 'xmipp_protocol_ml3d'
        ### Locate protocol_ml3d
        protocol_ml3d = apXmipp.locateXmippProtocol(protocolname)

        ### setup protocol parameters
        protocolPrm = {}
        ### check for n input model dependencies
        protocolPrm["InitialReference"] = self.params['modelnames'][0]
        if len(self.params['modelnames']) > 1:
            selfile = "reference_volumes.sel"
            sf = open(selfile, "w")
            for model in self.params['modelnames']:
                sf.write("%s\t1\n" %
                         os.path.join(self.params['rundir'], model))
            sf.close()
            protocolPrm["SeedsSelfile"] = os.path.join(
                self.params['rundir'], "reference_volumes.sel")
            protocolPrm["DoGenerateSeeds"] = False
        else:
            protocolPrm["SeedsSelfile"] = ""
            protocolPrm["DoGenerateSeeds"] = True
        protocolPrm[
            "InSelFile"] = "partlist.sel"  ### this maybe should not be hardcoded
        protocolPrm["WorkingDir"] = "ml3d"
        protocolPrm["DoDeleteWorkingDir"] = False
        protocolPrm["ProjectDir"] = self.params['recondir']
        protocolPrm["LogDir"] = "Logs"
        protocolPrm["DoMlf"] = self.params['DoMlf']
        protocolPrm["DoCorrectAmplitudes"] = False
        protocolPrm["InCtfDatFile"] = "all_images.ctfdat"
        protocolPrm["HighResLimit"] = self.params['HighResLimit']
        protocolPrm["ImagesArePhaseFlipped"] = self.params[
            'ImagesArePhaseFlipped']
        protocolPrm["InitialMapIsAmplitudeCorrected"] = False
        protocolPrm["SeedsAreAmplitudeCorrected"] = False
        protocolPrm["DoCorrectGreyScale"] = self.params['DoCorrectGreyScale']
        protocolPrm["ProjMatchSampling"] = self.params['ProjMatchSampling']
        if (self.params['LowPassFilter'] > 1) is True:
            protocolPrm["DoLowPassFilterReference"] = True
            protocolPrm["LowPassFilter"] = self.params['LowPassFilter']
        else:
            protocolPrm["DoLowPassFilterReference"] = False
            protocolPrm["LowPassFilter"] = self.params['LowPassFilter']
        protocolPrm["PixelSize"] = self.params['apix']
        protocolPrm["NumberOfReferences"] = self.params['NumberOfReferences']
        protocolPrm["DoJustRefine"] = False
        protocolPrm["DoML3DClassification"] = True
        protocolPrm["AngularSampling"] = self.params['AngularSampling']
        protocolPrm["NumberOfIterations"] = self.params['numiter']
        protocolPrm["Symmetry"] = self.params['symmetry'][0]
        protocolPrm["DoNorm"] = False
        protocolPrm["DoFourier"] = False
        protocolPrm["RestartIter"] = 0
        protocolPrm["ExtraParamsMLrefine3D"] = ""
        protocolPrm["NumberOfThreads"] = 1
        protocolPrm["DoParallel"] = self.params['nproc'] > 1
        protocolPrm["NumberOfMpiProcesses"] = self.params['nproc']
        protocolPrm["SystemFlavour"] = ""
        protocolPrm["AnalysisScript"] = "visualize_ml3d.py"

        ### write out python protocol into run directory
        protocolfile = os.path.join(self.params['remoterundir'],
                                    "%s.py" % protocolname)
        apXmipp.particularizeProtocol(protocol_ml3d, protocolPrm, protocolfile)
        os.chmod(os.path.join(self.params['rundir'], protocolfile), 0775)

        ### Write the parameters for posterior uploading, both generic and specific
        self.runparams = {}
        self.runparams['reconstruction_package'] = "xmipp_ml3d"
        self.runparams['remoterundir'] = self.params['remoterundir']
        #               self.runparams['reconstruction_working_dir'] = protocolPrm["WorkingDir"]
        self.runparams['reconstruction_working_dir'] = protocolPrm[
            'WorkingDir'] + "/RunML3D"
        self.runparams['numiter'] = protocolPrm['NumberOfIterations']
        self.runparams['NumberOfReferences'] = protocolPrm[
            'NumberOfReferences']
        self.runparams['symmetry'] = protocolPrm["Symmetry"]
        self.runparams['package_params'] = protocolPrm
        paramfile = os.path.join(
            self.params['remoterundir'],
            "xmipp_ml3d_" + self.timestamp + "-params.pickle")
        apParam.dumpParameters(self.runparams, paramfile)

        ### finished setup of input files, now run xmipp_protocols_ml3d.py from jobfile
        apDisplay.printMsg(
            "finished setting up input files, now running xmipp_protocols_ml3d.py"
        )

        return protocolfile, protocolPrm