def insertMisc(self):
                print "inserting into database"
                miscq = appiondata.ApMiscData()
                if self.params['reconid'] is not None:
                        miscq['refineRun'] = self.recondata
                        sessiondata = apRecon.getSessionDataFromReconId(self.params['reconid'])
                        miscq['session'] = sessiondata
                        projectid = apProject.getProjectIdFromSessionName(sessiondata['name'])
                        miscq['REF|projectdata|projects|project'] = projectid
                elif self.params['fulltomoid'] is not None:
                        miscq['fulltomogram'] = self.tomodata
                        sessiondata = self.tomodata['session']
                        miscq['session'] = sessiondata
                        projectid = apProject.getProjectIdFromSessionName(sessiondata['name'])
                        miscq['REF|projectdata|projects|project'] = projectid
                elif self.params['sessionname'] is not None:
                        miscq['session'] = self.sessiondata
                        projectid = apProject.getProjectIdFromSessionName(self.params['sessionname'])
                        miscq['REF|projectdata|projects|project'] = projectid
                miscq['path'] = appiondata.ApPathData(path=os.path.abspath(self.params['rundir']))
                miscq['name'] = self.filename
                miscq['description'] = self.params['description']
                miscq['md5sum'] = apFile.md5sumfile(self.newfile)
                miscq['hidden'] = False

                if self.params['commit'] is True:
                        miscq.insert()
                else:
                        apDisplay.printWarning("not committing to DB")
        def checkGlobalConflicts(self):
                """
                put in any conflicting parameters
                """
                appionScript.AppionScript.checkGlobalConflicts(self)

                if self.params['runname'] is None:
                        apDisplay.printError("please enter a runname, example: 'runname=run1'")
                if self.params['runname'] == 'templates':
                        apDisplay.printError("templates is a reserved runname, please use another runname")
                if self.params['runname'] == 'models':
                        apDisplay.printError("models is a reserved runname, please use another runname")
                if self.params['rundir']is not None and self.params['runname'] != os.path.basename(self.params['rundir']):
                        apDisplay.printError("runname and rundir basename are different: "
                                +self.params['runname']+" vs. "+os.path.basename(self.params['rundir']))
                if self.params['mrcnames'] and self.params['preset']:
                        apDisplay.printError("preset can not be specified if particular images have been specified")
                if (self.params['sessionname'] is None and self.params['expid'] is None) and self.params['mrcnames'] is None:
                        apDisplay.printError("please specify an mrc name or session")
                if self.params['sessionname'] is None and self.params['expid'] is not None:
                        self.params['sessionname'] = apDatabase.getSessionDataFromSessionId(self.params['expid'])['name']
                if self.params['sessionname'] is not None and self.params['projectid'] is not None:
                        ### Check that project and images are in sync
                        imgproject = apProject.getProjectIdFromSessionName(self.params['sessionname'])
                        if imgproject and imgproject != self.params['projectid']:
                                apDisplay.printError("project id and session do not correlate")
	def start(self):
		if self.params['stackid'] is not None:
			self.useStackForTemplate()
		elif self.params['alignid'] is not None:
			self.useAlignForTemplate()
		elif self.params['clusterid'] is not None:
			self.useClusterForTemplate()
		else:
			apDisplay.printMsg("Using local file: '"+str(self.params['template'])+"' to upload template")
			#find the number of template files
			apTemplate.findTemplates(self.params)

		### check for templates
		apDisplay.printColor("Template List:","green")
		pprint.pprint(self.params['templatelist'])
		if not self.params['templatelist']:
			apDisplay.printError("Could not find templates")

		time.sleep(2)

		# copy templates to final location
		apTemplate.copyTemplatesToOutdir(self.params, self.timestamp)

		self.params['projectId'] = apProject.getProjectIdFromSessionName(self.params['sessionname'])

		# insert templates to database
		apTemplate.insertTemplateImage(self.params)
    def start(self):
        if self.params['stackid'] is not None:
            self.useStackForTemplate()
        elif self.params['alignid'] is not None:
            self.useAlignForTemplate()
        elif self.params['clusterid'] is not None:
            self.useClusterForTemplate()
        else:
            apDisplay.printMsg("Using local file: '" +
                               str(self.params['template']) +
                               "' to upload template")
            #find the number of template files
            apTemplate.findTemplates(self.params)

        ### check for templates
        apDisplay.printColor("Template List:", "green")
        pprint.pprint(self.params['templatelist'])
        if not self.params['templatelist']:
            apDisplay.printError("Could not find templates")

        time.sleep(2)

        # copy templates to final location
        apTemplate.copyTemplatesToOutdir(self.params, self.timestamp)

        self.params['projectId'] = apProject.getProjectIdFromSessionName(
            self.params['sessionname'])

        # insert templates to database
        apTemplate.insertTemplateImage(self.params)
	def onInit(self):
		"""
		standard appionScript
		"""
		sessiondata = apDatabase.getSessionDataFromSessionName(self.params['sessionname'])
		if sessiondata:
			### METHOD 1 : session already exists
			apDisplay.printColor("Add images to an existing session", "cyan")
			### what about linking an existing session with project id to a new project id
			oldprojectid = apProject.getProjectIdFromSessionName(self.params['sessionname'])
			if oldprojectid != self.params['projectid']:
				apDisplay.printError("You cannot assign an existing session (PID %d) to a different project (PID %d)"%
					(oldprojectid, self.params['projectid']))
		else:
			### METHOD 2 : create new session
			apDisplay.printColor("Creating a new session", "cyan")
			### die for now
			apDisplay.printError("Uploading stack to a new session not allowed")
			try:
				directory = leginon.leginonconfig.mapPath(leginon.leginonconfig.IMAGE_PATH)
			except AttributeError:
				apDisplay.printWarning("Could not set directory")
				directory = ''
			userdata = None
			sessiondata = self.createSession(userdata, self.params['sessionname'], self.params['description'], directory)
			self.linkSessionProject(sessiondata, self.params['projectid'])

		self.sessiondata = sessiondata
		return
Ejemplo n.º 6
0
    def start(self):

        if self.params['reconid'] is not None:
            self.recondata = apRecon.getRefineRunDataFromID(
                self.params['reconid'])
            print "Associated with", self.recondata[
                'name'], ":", self.recondata['path']
        if self.params['fulltomoid'] is not None:
            self.tomodata = apTomo.getFullTomoData(self.params['fulltomoid'])
            print "Associated with", self.tomodata['name'], ":", self.tomodata[
                'path']['path']
        if self.params['sessionname'] is not None:
            self.sessiondata = apDatabase.getSessionDataFromSessionName(
                self.params['sessionname'])
            self.params['projectId'] = apProject.getProjectIdFromSessionName(
                self.params['sessionname'])

        self.filename = os.path.basename(self.params['file'])
        self.newfile = os.path.join(self.params['rundir'], self.filename)
        if os.path.isfile(self.newfile):
            apDisplay.printError("File " + self.filename +
                                 " already exists in dir " +
                                 self.params['rundir'])
        shutil.copy(self.oldfile, self.newfile)

        # insert the info
        self.insertMisc()
Ejemplo n.º 7
0
    def checkGlobalConflicts(self):
        """
                put in any conflicting parameters
                """
        appionScript.AppionScript.checkGlobalConflicts(self)

        if self.params['runname'] is None:
            apDisplay.printError(
                "please enter a runname, example: 'runname=run1'")
        if self.params['runname'] == 'templates':
            apDisplay.printError(
                "templates is a reserved runname, please use another runname")
        if self.params['runname'] == 'models':
            apDisplay.printError(
                "models is a reserved runname, please use another runname")
        if self.params['rundir'] is not None and self.params[
                'runname'] != os.path.basename(self.params['rundir']):
            apDisplay.printError(
                "runname and rundir basename are different: " +
                self.params['runname'] + " vs. " +
                os.path.basename(self.params['rundir']))
        if self.params['mrcnames'] and self.params['preset']:
            apDisplay.printError(
                "preset can not be specified if particular images have been specified"
            )
        if self.params['sessionname'] is None and self.params[
                'mrcnames'] is None:
            apDisplay.printError("please specify an mrc name or session")
        if self.params['sessionname'] is not None and self.params[
                'projectid'] is not None:
            ### Check that project and tilt series are in sync
            seriesproject = apProject.getProjectIdFromSessionName(
                self.params['sessionname'])
            if seriesproject and seriesproject != self.params['projectid']:
                apDisplay.printError("project id and session do not correlate")
	def checkConflicts(self):
		if self.params['sessionname'] is None:
			apDisplay.printError("Enter a session name (e.g. --session=06jul12a)")
		if self.params['projectid'] is not None:
			projid = apProject.getProjectIdFromSessionName(self.params['sessionname'])
			if projid != self.params['projectid']:
				apDisplay.printError("Project ID and Session name do not match")
		if self.params['description'] is None:
			apDisplay.printError("Enter a description of the initial model")
		if self.params['chimeraonly'] is True:
			self.params['commit'] = False
		if self.params['newbox'] is not None and self.params['newbox'] % 8 != 0:
			apDisplay.printWarning("Box size is not a multiple of 8")
		### program requires either a model id or density id or filename
		checkvalue = int(self.params['file'] is not None)
		checkvalue += int(self.params['oldmodelid'] is not None)
		checkvalue += int(self.params['densityid'] is not None)
		if checkvalue != 1:
			apDisplay.printError("Either provide a modelid or densityid or file, but not more than one of them")
		elif self.params['oldmodelid'] is not None and self.params['newbox'] is None:
			apDisplay.printError("Please specify either a new boxsize or scale for your model")
		elif self.params['densityid'] is not None:
			self.getDensityParams()
		elif self.params['oldmodelid'] is not None:
			self.getModelParams()
		elif self.params['file'] is not None:
			if not os.path.isfile(self.params['file']):
				apDisplay.printError("could not find file: "+self.params['file'])
			if self.params['file'][-4:] != ".mrc":
				apDisplay.printError("uploadModel.py only supports MRC files")
			self.params['file'] = os.path.abspath(self.params['file'])
		else:
			apDisplay.printError("Please provide either a --modelid=112 or --file=initmodel.mrc")
		### required only if now model id is provided
		if self.params['newapix'] is None:
			apDisplay.printError("Enter the pixel size of the model")
		if self.params['symmetry'] is None:
			apSymmetry.printSymmetries()
			apDisplay.printError("Enter a symmetry ID, e.g. --symm=19")
		self.params['symdata'] = apSymmetry.findSymmetry(self.params['symmetry'])
		if self.params['res'] is None:
			apDisplay.printError("Enter the resolution of the initial model")

		self.params['oldbox'] = apVolume.getModelDimensions(self.params['file'])
		if self.params['newbox'] is None:
			self.params['newbox'] = self.params['oldbox']
		if self.params['oldapix'] is None:
			self.params['oldapix'] = self.params['newapix']
        def start(self):

                if self.params['reconid'] is not None:
                        self.recondata = apRecon.getRefineRunDataFromID(self.params['reconid'])
                        print "Associated with",self.recondata['name'],":",self.recondata['path']
                if self.params['fulltomoid'] is not None:
                        self.tomodata = apTomo.getFullTomoData(self.params['fulltomoid'])
                        print "Associated with",self.tomodata['name'],":",self.tomodata['path']['path']
                if self.params['sessionname'] is not None:
                        self.sessiondata = apDatabase.getSessionDataFromSessionName(self.params['sessionname'])
                        self.params['projectId'] = apProject.getProjectIdFromSessionName(self.params['sessionname'])

                self.filename = os.path.basename(self.params['file'])
                self.newfile = os.path.join(self.params['rundir'], self.filename)
                if os.path.isfile(self.newfile):
                        apDisplay.printError("File "+self.filename+" already exists in dir "+self.params['rundir'])
                shutil.copy(self.oldfile, self.newfile)

                # insert the info
                self.insertMisc()
Ejemplo n.º 10
0
    def onInit(self):
        """
		standard appionScript
		"""
        sessiondata = apDatabase.getSessionDataFromSessionName(
            self.params['sessionname'])
        if sessiondata:
            ### METHOD 1 : session already exists
            apDisplay.printColor("Add images to an existing session", "cyan")
            ### what about linking an existing session with project id to a new project id
            oldprojectid = apProject.getProjectIdFromSessionName(
                self.params['sessionname'])
            if oldprojectid != self.params['projectid']:
                apDisplay.printError(
                    "You cannot assign an existing session (PID %d) to a different project (PID %d)"
                    % (oldprojectid, self.params['projectid']))
        else:
            ### METHOD 2 : create new session
            apDisplay.printColor("Creating a new session", "cyan")
            ### die for now
            apDisplay.printError(
                "Uploading stack to a new session not allowed")
            try:
                directory = leginon.leginonconfig.mapPath(
                    leginon.leginonconfig.IMAGE_PATH)
            except AttributeError:
                apDisplay.printWarning("Could not set directory")
                directory = ''
            userdata = None
            sessiondata = self.createSession(userdata,
                                             self.params['sessionname'],
                                             self.params['description'],
                                             directory)
            self.linkSessionProject(sessiondata, self.params['projectid'])

        self.sessiondata = sessiondata
        return
def setAppiondb(sessionname):
        projectid = apProject.getProjectIdFromSessionName(sessionname)
        apProject.setDBfromProjectId(projectid, die=True)
Ejemplo n.º 12
0
    def checkConflicts(self):
        """
                standard appionScript
                """
        if self.params['batchscript'] is None:
            #mode 1: command line params
            if self.params['apix'] is None:
                apDisplay.printError(
                    "If not specifying a parameter file, supply apix")
            if self.params['df'] is None:
                apDisplay.printError(
                    "If not specifying a parameter file, supply defocus of the images"
                )
            if self.params['df'] > 0:
                apDisplay.printWarning("defocus is being switched to negative")
                self.params['df'] *= -1
            if self.params['df'] > -0.1:
                apDisplay.printError("defocus must be in microns")
            if self.params['mag'] is None:
                apDisplay.printError(
                    "If not specifying a parameter file, supply magnification")
            if self.params['kv'] is None:
                apDisplay.printError(
                    "If not specifying a parameter file, supply a high tension"
                )
            if self.params['kv'] > 1000:
                apDisplay.printError(
                    "High tension must be in kilovolts (e.g., 120)")
            if self.params['cs'] < 0.0:
                apDisplay.printError("Cs value must be in mm (e.g., 2.0)")
            if self.params['imgdir'] is None:
                apDisplay.printError(
                    "If not specifying a parameter file, specify directory containing images"
                )
            if not os.path.exists(self.params['imgdir']):
                apDisplay.printError("specified path '%s' does not exist\n" %
                                     self.params['imgdir'])
        elif not os.path.isfile(self.params["batchscript"]):
            #mode 2: batch script
            apDisplay.printError("Could not find Batch parameter file: %s" %
                                 (self.params["batchscript"]))

        if self.params['sessionname'] is None:
            apDisplay.printError(
                "Please provide a Session name, e.g., --session=09feb12b")
        if self.params['projectid'] is None:
            apDisplay.printError(
                "Please provide a Project database ID, e.g., --projectid=42")
        if self.params['description'] is None:
            apDisplay.printError(
                "Please provide a Description, e.g., --description='awesome data'"
            )
        if self.params['userid'] is None:
            self.params['userid'] = self.getLeginonUserId()

        #This really is not conflict checking but to set up new session.
        #There is no place in Appion script for this special case

        sessionq = leginon.leginondata.SessionData(
            name=self.params['sessionname'])
        sessiondatas = sessionq.query()
        if len(sessiondatas) > 0:
            ### METHOD 1 : session already exists
            apDisplay.printColor("Add images to an existing session", "cyan")
            sessiondata = sessiondatas[0]
            ### what about linking an existing session with project id to a new project id
            oldprojectid = apProject.getProjectIdFromSessionName(
                self.params['sessionname'])
            if oldprojectid != self.params['projectid']:
                apDisplay.printError(
                    "You cannot assign an existing session (PID %d) to a different project (PID %d)"
                    % (oldprojectid, self.params['projectid']))
            if self.params['rundir'] is not None and self.params[
                    'rundir'] != sessiondata['image path']:
                apDisplay.printError(
                    "Specified Rundir is different from current session path\n%s\n%s"
                    % (self.params['rundir'], sessiondata['image path']))
            ### only allows uploading more images if all images are uploaded through appion host.
            instrumentq = leginon.leginondata.InstrumentData(hostname='appion',
                                                             name='AppionTEM')
            appiontems = instrumentq.query()
            allappionscopeems = []
            for appiontem in appiontems:
                scopeemq = leginon.leginondata.ScopeEMData(
                    session=sessiondatas[0], tem=appiontem)
                appionscopeems = scopeemq.query()
                if appionscopeems:
                    allappionscopeems.extend(appionscopeems)
            scopeemq = leginon.leginondata.ScopeEMData(session=sessiondatas[0])
            allscopeems = scopeemq.query()
            if len(allscopeems) > len(allappionscopeems):

                apDisplay.printError(
                    "You can only add more images to an existing session that contains only appion uploads"
                )
        else:
            ### METHOD 2 : create new session
            apDisplay.printColor("Creating a new session", "cyan")
            try:
                directory = leginon.leginonconfig.mapPath(
                    leginon.leginonconfig.IMAGE_PATH)
            except AttributeError:
                apDisplay.printWarning("Could not set directory")
                directory = ''
            if self.params['userid'] is not None:
                userdata = leginon.leginondata.UserData.direct_query(
                    self.params['userid'])
            else:
                userdata = None
            sessiondata = self.createSession(userdata,
                                             self.params['sessionname'],
                                             self.params['description'],
                                             directory)

        self.linkSessionProject(sessiondata, self.params['projectid'])
        self.session = sessiondata
        return
        def checkConflicts(self):
                """
                standard appionScript
                """
                if self.params['batchscript'] is None:
                        #mode 1: command line params
                        if self.params['apix'] is None:
                                apDisplay.printError("If not specifying a parameter file, supply apix")
                        if self.params['df'] is None:
                                apDisplay.printError("If not specifying a parameter file, supply defocus of the images")
                        if self.params['df'] > 0:
                                apDisplay.printWarning("defocus is being switched to negative")
                                self.params['df']*=-1
                        if self.params['df'] > -0.1:
                                apDisplay.printError("defocus must be in microns")
                        if self.params['mag'] is None:
                                apDisplay.printError("If not specifying a parameter file, supply magnification")
                        if self.params['kv'] is None:
                                apDisplay.printError("If not specifying a parameter file, supply a high tension")
                        if self.params['kv'] > 1000:
                                apDisplay.printError("High tension must be in kilovolts (e.g., 120)")
                        if self.params['cs'] < 0.0:
                                apDisplay.printError("Cs value must be in mm (e.g., 2.0)")
                        if self.params['imgdir'] is None:
                                apDisplay.printError("If not specifying a parameter file, specify directory containing images")
                        if not os.path.exists(self.params['imgdir']):
                                apDisplay.printError("specified path '%s' does not exist\n"%self.params['imgdir'])
                elif not os.path.isfile(self.params["batchscript"]):
                        #mode 2: batch script
                        apDisplay.printError("Could not find Batch parameter file: %s"%(self.params["batchscript"]))

                if self.params['sessionname'] is None:
                        apDisplay.printError("Please provide a Session name, e.g., --session=09feb12b")
                if self.params['projectid'] is None:
                        apDisplay.printError("Please provide a Project database ID, e.g., --projectid=42")
                if self.params['description'] is None:
                        apDisplay.printError("Please provide a Description, e.g., --description='awesome data'")
                if self.params['userid'] is None:
                        self.params['userid'] = self.getLeginonUserId()

                #This really is not conflict checking but to set up new session.
                #There is no place in Appion script for this special case

                sessionq = leginon.leginondata.SessionData(name=self.params['sessionname'])
                sessiondatas = sessionq.query()
                if len(sessiondatas) > 0:
                        ### METHOD 1 : session already exists
                        apDisplay.printColor("Add images to an existing session", "cyan")
                        sessiondata = sessiondatas[0]
                        ### what about linking an existing session with project id to a new project id
                        oldprojectid = apProject.getProjectIdFromSessionName(self.params['sessionname'])
                        if oldprojectid != self.params['projectid']:
                                apDisplay.printError("You cannot assign an existing session (PID %d) to a different project (PID %d)"%
                                        (oldprojectid, self.params['projectid']))
                        if self.params['rundir'] is not None and self.params['rundir'] != sessiondata['image path']:
                                apDisplay.printError("Specified Rundir is different from current session path\n%s\n%s"
                                        %( self.params['rundir'], sessiondata['image path']))
                        ### only allows uploading more images if all images are uploaded through appion host.
                        instrumentq = leginon.leginondata.InstrumentData(hostname='appion',name='AppionTEM')
                        appiontems = instrumentq.query()
                        allappionscopeems = []
                        for appiontem in appiontems:
                                scopeemq = leginon.leginondata.ScopeEMData(session=sessiondatas[0],tem=appiontem)
                                appionscopeems = scopeemq.query()
                                if appionscopeems:
                                        allappionscopeems.extend(appionscopeems)
                        scopeemq = leginon.leginondata.ScopeEMData(session=sessiondatas[0])
                        allscopeems = scopeemq.query()
                        if len(allscopeems) > len(allappionscopeems):

                                apDisplay.printError("You can only add more images to an existing session that contains only appion uploads")
                else:
                        ### METHOD 2 : create new session
                        apDisplay.printColor("Creating a new session", "cyan")
                        try:
                                directory = leginon.leginonconfig.mapPath(leginon.leginonconfig.IMAGE_PATH)
                        except AttributeError:
                                apDisplay.printWarning("Could not set directory")
                                directory = ''
                        if self.params['userid'] is not None:
                                userdata = leginon.leginondata.UserData.direct_query(self.params['userid'])
                        else:
                                userdata = None
                        sessiondata = self.createSession(userdata, self.params['sessionname'], self.params['description'], directory)

                self.linkSessionProject(sessiondata, self.params['projectid']) 
                self.session = sessiondata
                return
Ejemplo n.º 14
0
def setAppiondb(sessionname):
    projectid = apProject.getProjectIdFromSessionName(sessionname)
    apProject.setDBfromProjectId(projectid, die=True)