Пример #1
0
    def characteriseWithXmlInput(self, data_collection_id, sampleCharacteriseIndex, beamsize):
        if data_collection_id is not None:
          self.ednaInput.setDataCollectionId(XSDataInteger(data_collection_id))
        else:
          self.ednaInput.setDataCollectionId(None)
          logging.getLogger().warning("The data collection ID is not known for this characterisation. Therefore the EDNA results cannot be put into the database")

        # build data set
        imageSuffix = self.beamlinePars["BCM_PARS"].getProperty("FileSuffix")
        dataSetObj = XSDataMXCuBEDataSet()
        self.ednaInput.setDataSet([])
        methodDCNo = len(self.current_method[1])
        for methodIndex in range(methodDCNo):
          number_of_images = self.current_method[1][methodIndex]['number_of_images']
          imageNameIdx = self.current_method[0]
          listIndex = sampleCharacteriseIndex * methodDCNo + methodIndex
          for imageno in range(int(number_of_images)):
              imageFileObj = XSDataFile()
              pathStrObj = XSDataString()
              pathStrObj.setValue(('%s/%s_%d_%04d.%s' % (self.collectSeqList[listIndex]['fileinfo']['directory'],\
                                                         self.collectSeqList[listIndex]['fileinfo']['prefix'],\
                                                         int(self.collectSeqList[listIndex]['fileinfo']['run_number']),\
                                                         imageno+1,imageSuffix)))
              imageFileObj.setPath(pathStrObj)
              dataSetObj.addImageFile(imageFileObj)
        self.ednaInput.addDataSet(dataSetObj)

        if TEST:
          self.ednaInput.getDataSet()[0].getImageFile()[0].getPath().setValue("/opt/pxsoft/DNA/TestCase/ref-testscale_1_001.img")
          self.ednaInput.getDataSet()[0].getImageFile()[1].getPath().setValue("/opt/pxsoft/DNA/TestCase/ref-testscale_1_002.img")
        path = self.process_dir
        suffix = '_%s.xml' % (self.ednaInput.getDataCollectionId().getValue() or id(self.ednaInput))
        ednaResultsFile = os.path.join(path, 'EDNAOutput%s' % suffix)
        ednaInputXMLFile = os.path.join(path, 'EDNAInput%s' % suffix)
        if not os.path.isdir(path):
            os.makedirs(path)

        beamObj = self.ednaInput.getExperimentalCondition().getBeam()
        beamObj.setSize(XSDataSize(x=XSDataLength(float(beamsize[0])),y=XSDataLength(float(beamsize[1]))))
        """ create an edna input file using the ednainput model """
        ednaInputXML = self.ednaInput.exportToFile(ednaInputXMLFile)

        logging.getLogger().info("Starting Edna using xml file, %s" % ednaInputXMLFile)

        # use an intermediate script to run edna with its command line options
        edna_args = "%s  %s %s" % (ednaInputXMLFile,ednaResultsFile,path)
        edna_cmd=self.StartEdnaCommand+" "+edna_args
        if self.ednaPollTimer is None:
            self.ednaPollTimer = qt.QTimer()
            qt.QObject.connect(self.ednaPollTimer,qt.SIGNAL("timeout()"), self.pollEDNA)

        logging.getLogger().debug(edna_cmd)
        EDNA_PROCESSES.append(EnhancedPopen.Popen(edna_cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True,universal_newlines=True))
        self.EDNAResultsFiles[id(EDNA_PROCESSES[-1])]=ednaResultsFile
        # save image prefix,etc. for next step
        # only take first image, since we just want to have image prefix, run number, etc. :
        # it is the same within the whole collectSeqList (hopefully)
        imagePrefix = self.collectSeqList[0]['fileinfo']['prefix'][4:] #remove ref-
        self.imagePathProperties[id(EDNA_PROCESSES[-1])]={"imagePrefix":imagePrefix, "imageDir": self.collectSeqList[0]['fileinfo']['directory'], "lRunN": int(self.collectSeqList[0]['fileinfo']['run_number'])}
        self.ednaPollTimer.start(100)
    def prepare_edna_input(self, edna_input):

        # used for strategy calculation (characterization) using data analysis cluster
        # ALBA specific

        firstImage = None

        for dataSet in edna_input.getDataSet():
            for imageFile in dataSet.imageFile:
                if imageFile.getPath() is None:
                    continue
                firstImage = imageFile.path.value
                break

        listImageName = os.path.basename(firstImage).split("_")
        prefix = "_".join(listImageName[:-2])
        run_number = listImageName[-2]
        i = 1

        if hasattr(edna_input, "process_directory"):
            edna_directory = os.path.join(edna_input.process_directory, "characterisation_%s_run%s_%d" % (prefix, run_number, i))
            while os.path.exists(edna_directory):
                i += 1
                edna_directory = os.path.join(edna_input.process_directory, "characterisation_%s_run%s_%d" % (prefix, run_number, i))
            os.makedirs(edna_directory)
        else:
            raise RuntimeError("No process directory specified in edna_input")

        edna_input.process_directory = edna_directory

        output_dir = XSDataFile()
        path = XSDataString()
        path.setValue(edna_directory)
        output_dir.setPath(path)
        edna_input.setOutputFileDirectory( output_dir )
 def writeFullPath(self, xsDataFile):
     """
     Add path to the data file directory 
     """
     dataInputPath = XSDataString()
     dataInputName = xsDataFile.getPath().getValue()
     dataInputPath.setValue(os.path.join(self.getPluginTestsDataHome(), dataInputName))
     xsDataFile.setPath(dataInputPath)
Пример #4
0
 def writeFullPath(self, xsDataFile):
     """
     Add path to the data file directory 
     """
     dataInputPath = XSDataString()
     dataInputName = xsDataFile.getPath().getValue()
     dataInputPath.setValue(
         os.path.join(self.getPluginTestsDataHome(), dataInputName))
     xsDataFile.setPath(dataInputPath)
    def testExecute(self):
        """
        """
        inputPdbPath = XSDataString()

        # Add path to the input data file
        inputPdbName = self.getPlugin().getDataInput().getInputPdbFile().getPath().getValue()
        inputPdbPath.setValue(os.path.join(self.getPluginTestsDataHome(), inputPdbName))
        self.getPlugin().getDataInput().getInputPdbFile().setPath(inputPdbPath)

        self.run()
    def testExecute(self):
        """
        """
        dataInputPath = XSDataString()

        # Add path to the input data file
        dataInputName = self.getPlugin().getDataInput().getGnomOutputFile().getPath().getValue()
        dataInputPath.setValue(os.path.join(self.getPluginTestsDataHome(), dataInputName))
        self.getPlugin().getDataInput().getGnomOutputFile().setPath(dataInputPath)

        self.run()
Пример #7
0
    def testExecute(self):
        """
        """
        dataInputPath = XSDataString()

        # Add path to the input data file
        dataInputName = self.getPlugin().getDataInput().getGnomOutputFile().getPath().getValue()
        dataInputPath.setValue(os.path.join(self.getPluginTestsDataHome(), dataInputName))
        self.getPlugin().getDataInput().getGnomOutputFile().setPath(dataInputPath)

        self.run()
Пример #8
0
    def testExecute(self):
        """
        """
        inputPdbPath = XSDataString()

        # Add path to the input data file
        inputPdbName = self.getPlugin().getDataInput().getInputPdbFile(
        ).getPath().getValue()
        inputPdbPath.setValue(
            os.path.join(self.getPluginTestsDataHome(), inputPdbName))
        self.getPlugin().getDataInput().getInputPdbFile().setPath(inputPdbPath)

        self.run()
    def testExecute(self):
        """
        """
        templateInputPath = XSDataString()
        supimposeInputPath = XSDataString()

        # Add path to the input data file
        templateInputName = self.getPlugin().getDataInput().getTemplateFile().getPath().getValue()
        templateInputPath.setValue(os.path.join(self.getPluginTestsDataHome(), templateInputName))
        self.getPlugin().getDataInput().getTemplateFile().setPath(templateInputPath)

        supimposeInputName = self.getPlugin().getDataInput().getSuperimposeFile().getPath().getValue()
        supimposeInputPath.setValue(os.path.join(self.getPluginTestsDataHome(), supimposeInputName))
        self.getPlugin().getDataInput().getSuperimposeFile().setPath(supimposeInputPath)

        self.run()
    def testExecute(self):
        """
        """
        templateInputPath = XSDataString()
        supimposeInputPath = XSDataString()

        # Add path to the input data file
        templateInputName = self.getPlugin().getDataInput().getTemplateFile().getPath().getValue()
        templateInputPath.setValue(os.path.join(self.getPluginTestsDataHome(), templateInputName))
        self.getPlugin().getDataInput().getTemplateFile().setPath(templateInputPath)

        supimposeInputName = self.getPlugin().getDataInput().getSuperimposeFile().getPath().getValue()
        supimposeInputPath.setValue(os.path.join(self.getPluginTestsDataHome(), supimposeInputName))
        self.getPlugin().getDataInput().getSuperimposeFile().setPath(supimposeInputPath)

        self.run()
Пример #11
0
    def prepare_edna_input(self, edna_input):

        # used for strategy calculation (characterization) using data analysis cluster
        # ALBA specific

        firstImage = None

        for dataSet in edna_input.getDataSet():
            for imageFile in dataSet.imageFile:
                if imageFile.getPath() is None:
                    continue
                firstImage = imageFile.path.value
                break

        listImageName = os.path.basename(firstImage).split("_")
        prefix = "_".join(listImageName[:-2])
        run_number = listImageName[-2]
        i = 1

        if hasattr(edna_input, "process_directory"):
            edna_directory = os.path.join(
                edna_input.process_directory,
                "characterisation_%s_run%s_%d" % (prefix, run_number, i),
            )
            while os.path.exists(edna_directory):
                i += 1
                edna_directory = os.path.join(
                    edna_input.process_directory,
                    "characterisation_%s_run%s_%d" % (prefix, run_number, i),
                )
            os.makedirs(edna_directory)
        else:
            raise RuntimeError("No process directory specified in edna_input")

        edna_input.process_directory = edna_directory

        output_dir = XSDataFile()
        path = XSDataString()
        path.setValue(edna_directory)
        output_dir.setPath(path)
        edna_input.setOutputFileDirectory(output_dir)
Пример #12
0
    def postProcess(self, _edObject=None):
        """
        Postprocess of the plugin:
         
        * set output of the plugin
        * free some memory from large arrays
        """
        EDPluginExec.postProcess(self)
        EDVerbose.DEBUG("EDPluginExecThumbnailv10.postProcess")
        # Create some output data

        xsDataResult = XSDataResultExecThumbnail()
        if os.path.isfile(self.output):
            xsDataFile = XSDataFile()
            xsDataFile.setPath(XSDataString(self.output))
            xsDataResult.setThumbnailPath(xsDataFile)
            xsDataString = XSDataString()
            xsDataString.setValue(self.format)
            xsDataResult.setThumbnailType(xsDataString)
        self.setDataOutput(xsDataResult)
        self.npaImage = None
Пример #13
0
    def postProcess(self, _edObject=None):
        """
        Postprocess of the plugin:
         
        * set output of the plugin
        * free some memory from large arrays
        """
        EDPluginExec.postProcess(self)
        EDVerbose.DEBUG("EDPluginExecThumbnailv10.postProcess")
        # Create some output data

        xsDataResult = XSDataResultExecThumbnail()
        if os.path.isfile(self.output):
            xsDataFile = XSDataFile()
            xsDataFile.setPath(XSDataString(self.output))
            xsDataResult.setThumbnailPath(xsDataFile)
            xsDataString = XSDataString()
            xsDataString.setValue(self.format)
            xsDataResult.setThumbnailType(xsDataString)
        self.setDataOutput(xsDataResult)
        self.npaImage = None
    def create_input_files(self, xds_dir, mosflm_dir, dc_pars):

        fileinfo = dc_pars["fileinfo"]
        osc_seq = dc_pars["oscillation_sequence"][0]

        prefix = fileinfo["prefix"]
        runno = fileinfo["run_number"]

        exp_time = osc_seq["exposure_time"]

        start_angle = osc_seq["start"]
        nb_images = osc_seq["number_of_images"]
        start_img_num = osc_seq["start_image_number"]
        angle_increment = osc_seq["range"]

        wavelength = osc_seq.get("wavelength", 0)

        xds_template_name = "XDS_TEMPLATE.INP"
        mosflm_template_name = "mosflm_template.dat"

        xds_template_path = os.path.join(self.template_dir, xds_template_name)
        mosflm_template_path = os.path.join(self.template_dir, mosflm_template_name)

        xds_file = os.path.join(xds_dir, "XDS.INP")
        mosflm_file = os.path.join(mosflm_dir, "mosflm.dat")

        t = datetime.now()

        # PREPARE VARIABLES
        detsamdis = self.var_ds.detsamdis
        beamx, beamy = self.var_ds.beamx, self.var_ds.beamy

        mbeamx, mbeamy = beamy * 0.172, beamx * 0.172

        datarangestartnum = start_img_num
        datarangefinishnum = start_img_num + nb_images - 1
        backgroundrangestartnum = start_img_num
        spotrangestartnum = start_img_num
        if angle_increment != 0:
            minimumrange = int(round(20 / angle_increment))
        elif angle_increment == 0:
            minimumrange = 1
        if nb_images >= minimumrange:
            backgroundrangefinishnum = start_img_num + minimumrange - 1
        if nb_images >= minimumrange:
            spotrangefinishnum = start_img_num + minimumrange - 1
        if nb_images < minimumrange:
            backgroundrangefinishnum = start_img_num + nb_images - 1
        if nb_images < minimumrange:
            spotrangefinishnum = start_img_num + nb_images - 1

        testlowres = 8.0
        largestvector = (
            0.172
            * ((max(beamx, 2463 - beamx)) ** 2 + (max(beamy, 2527 - beamy)) ** 2) ** 0.5
        )
        testhighres = round(
            wavelength / (2 * math.sin(0.5 * math.atan(largestvector / detsamdis))), 2
        )
        lowres = 50.0
        highres = testhighres
        datafilename = prefix + "_" + str(runno) + "_????"
        mdatafilename = prefix + "_" + str(runno) + "_####.cbf"
        seconds = 5 * exp_time

        if angle_increment < 1 and not angle_increment == 0:
            seconds = 5 * exp_time / angle_increment

        # DEFINE SG/UNIT CELL
        spacegroupnumber = ""
        unitcellconstants = ""

        datapath_dir = os.path.abspath(xds_file).replace("PROCESS_DATA", "RAW_DATA")
        datapath_dir = os.path.dirname(os.path.dirname(datapath_dir)) + os.path.sep

        # CREATE XDS.INP FILE
        xds_templ = open(xds_template_path, "r").read()

        xds_templ = xds_templ.replace("###BEAMX###", str(round(beamx, 2)))
        xds_templ = xds_templ.replace("###BEAMY###", str(round(beamy, 2)))
        xds_templ = xds_templ.replace("###DETSAMDIS###", str(round(detsamdis, 2)))
        xds_templ = xds_templ.replace("###ANGLEINCREMENT###", str(angle_increment))
        xds_templ = xds_templ.replace("###WAVELENGTH###", str(wavelength))
        xds_templ = xds_templ.replace("###DATARANGESTARTNUM###", str(datarangestartnum))
        xds_templ = xds_templ.replace(
            "###DATARANGEFINISHNUM###", str(datarangefinishnum)
        )
        xds_templ = xds_templ.replace(
            "###BACKGROUNDRANGESTART###", str(backgroundrangestartnum)
        )
        xds_templ = xds_templ.replace(
            "###BACKGROUNDRANGEFINISHNUM###", str(backgroundrangefinishnum)
        )
        xds_templ = xds_templ.replace("###SPOTRANGESTARTNUM###", str(spotrangestartnum))
        xds_templ = xds_templ.replace(
            "###SPOTRANGEFINISHNUM###", str(spotrangefinishnum)
        )
        xds_templ = xds_templ.replace("###TESTLOWRES###", str(testlowres))
        xds_templ = xds_templ.replace("###TESTHIGHRES###", str(testhighres))
        xds_templ = xds_templ.replace("###LOWRES###", str(lowres))
        xds_templ = xds_templ.replace("###HIGHRES###", str(highres))
        xds_templ = xds_templ.replace("###DIRECTORY###", str(datapath_dir))
        xds_templ = xds_templ.replace("###FILENAME###", str(datafilename))
        xds_templ = xds_templ.replace("###SECONDS###", str(int(seconds)))
        xds_templ = xds_templ.replace(
            "###LYSOZYME_SPACE_GROUP_NUMBER###", str(spacegroupnumber)
        )
        xds_templ = xds_templ.replace(
            "###LYSOZYME_UNIT_CELL_CONSTANTS###", str(unitcellconstants)
        )

        open(xds_file, "w").write(xds_templ)

        # CREATE MOSFLM.DAT FILE

        mosflm_templ = open(mosflm_template_path, "r").read()

        mosflm_templ = mosflm_templ.replace("###DETSAMDIS###", str(round(detsamdis, 2)))
        mosflm_templ = mosflm_templ.replace("###BEAMX###", str(round(mbeamx, 2)))
        mosflm_templ = mosflm_templ.replace("###BEAMY###", str(round(mbeamy, 2)))
        mosflm_templ = mosflm_templ.replace("###DIRECTORY###", str(datapath_dir))
        mosflm_templ = mosflm_templ.replace("###FILENAME###", str(mdatafilename))
        mosflm_templ = mosflm_templ.replace("###WAVELENGTH###", str(wavelength))
        mosflm_templ = mosflm_templ.replace(
            "###DATARANGESTARTNUM###", str(datarangestartnum)
        )

        open(mosflm_file, "w").write(mosflm_templ)

        # CREATE EDNAPROC XML FILE
        collection_id = dc_pars["collection_id"]
        output_dir = dc_pars["ednaproc_dir"]

        ednaproc_input_file = os.path.join(
            output_dir, "EDNAprocInput_%d.xml" % collection_id
        )

        ednaproc_input = XSDataAutoprocInput()

        input_file = XSDataFile()
        path = XSDataString()
        path.setValue(xds_file)
        input_file.setPath(path)

        ednaproc_input.setInput_file(input_file)
        ednaproc_input.setData_collection_id(XSDataInteger(collection_id))

        # output_dir = XSDataFile()
        # outpath = XSDataString()
        # outpath.setValue(output_dir)
        # output_dir.setPath(path)

        # ednaproc_input.setOutput_directory( output_dir )

        ednaproc_input.exportToFile(ednaproc_input_file)

        self.input_file = ednaproc_input_file
Пример #15
0
    def from_params(self, data_collection, char_params):
        edna_input = XSDataInputMXCuBE.parseString(self.edna_default_input)

        if data_collection.id:
            edna_input.setDataCollectionId(XSDataInteger(data_collection.id))

        #Beam object
        beam = edna_input.getExperimentalCondition().getBeam()

        try:
            transmission = self.collect_obj.get_transmission()
            beam.setTransmission(XSDataDouble(transmission))
        except AttributeError:
            pass

        try:
            wavelength = self.collect_obj.get_wavelength()
            beam.setWavelength(XSDataWavelength(wavelength))
        except AttributeError:
            pass

        try:
            beam.setFlux(XSDataFlux(self.collect_obj.get_measured_intensity()))
        except AttributeError:
            pass

        try:
            beamsize = self.get_beam_size()
            if not None in beamsize:
                beam.setSize(
                    XSDataSize(x=XSDataLength(float(beamsize[0])),
                               y=XSDataLength(float(beamsize[1]))))
        except AttributeError:
            pass

        #Optimization parameters
        diff_plan = edna_input.getDiffractionPlan()

        aimed_i_sigma = XSDataDouble(char_params.aimed_i_sigma)
        aimed_completness = XSDataDouble(char_params.aimed_completness)
        aimed_multiplicity = XSDataDouble(char_params.aimed_multiplicity)
        aimed_resolution = XSDataDouble(char_params.aimed_resolution)

        complexity = char_params.strategy_complexity
        complexity = XSDataString(qme.STRATEGY_COMPLEXITY[complexity])

        permitted_phi_start = XSDataAngle(char_params.permitted_phi_start)
        _range = char_params.permitted_phi_end - char_params.permitted_phi_start
        rotation_range = XSDataAngle(_range)

        diff_plan.setAimedIOverSigmaAtHighestResolution(aimed_i_sigma)
        diff_plan.setAimedCompleteness(aimed_completness)

        if char_params.use_aimed_multiplicity:
            diff_plan.setAimedMultiplicity(aimed_multiplicity)

        if char_params.use_aimed_resolution:
            diff_plan.setAimedResolution(aimed_resolution)

        diff_plan.setComplexity(complexity)

        if char_params.use_permitted_rotation:
            diff_plan.setUserDefinedRotationStart(permitted_phi_start)
            diff_plan.setUserDefinedRotationRange(rotation_range)

        #Vertical crystal dimension
        sample = edna_input.getSample()
        sample.getSize().setY(XSDataLength(char_params.max_crystal_vdim))
        sample.getSize().setZ(XSDataLength(char_params.min_crystal_vdim))

        #Radiation damage model
        sample.setSusceptibility(XSDataDouble(char_params.rad_suscept))
        sample.setChemicalComposition(None)
        sample.setRadiationDamageModelBeta(XSDataDouble(char_params.beta /
                                                        1e6))
        sample.setRadiationDamageModelGamma(
            XSDataDouble(char_params.gamma / 1e6))

        diff_plan.setForcedSpaceGroup(XSDataString(char_params.space_group))

        # Characterisation type - Routine DC
        if char_params.use_min_dose:
            pass

        if char_params.use_min_time:
            time = XSDataTime(char_params.min_time)
            diff_plan.setMaxExposureTimePerDataCollection(time)

        # Account for radiation damage
        if char_params.induce_burn:
            diff_plan.setStrategyOption(XSDataString("-DamPar"))
        else:
            diff_plan.setStrategyOption(None)

        # Characterisation type - SAD
        if char_params.opt_sad:
            diff_plan.setAnomalousData(XSDataBoolean(True))
        else:
            diff_plan.setAnomalousData(XSDataBoolean(False))

        #Data set
        data_set = XSDataMXCuBEDataSet()
        acquisition_parameters = data_collection.acquisitions[
            0].acquisition_parameters
        path_template = data_collection.acquisitions[0].path_template
        path_str = os.path.join(path_template.directory,
                                path_template.get_image_file_name())

        for img_num in range(int(acquisition_parameters.num_images)):
            image_file = XSDataFile()
            path = XSDataString()
            path.setValue(path_str % (img_num + 1))
            image_file.setPath(path)
            data_set.addImageFile(image_file)

        edna_input.addDataSet(data_set)
        edna_input.process_directory = path_template.process_directory

        return edna_input
Пример #16
0
    def from_params(self, data_collection, char_params):
        edna_input = XSDataInputMXCuBE.parseString(EDNA_DEFAULT_INPUT)

        if data_collection.id:
            edna_input.setDataCollectionId(XSDataInteger(data_collection.id))

        #Beam object
        beam = edna_input.getExperimentalCondition().getBeam()

        try:
            beam.setTransmission(XSDataDouble(self.collect_obj.get_transmission()))
        except AttributeError:
            pass

        try:
            beam.setWavelength(XSDataWavelength(self.collect_obj.get_wavelength()))
        except AttributeError:
            pass

        try:
            beam.setFlux(XSDataFlux(self.collect_obj.get_measured_intensity()))
        except AttributeError:
            pass

        try:
            beamsize = self.get_beam_size()
            if not None in beamsize:
                beam.setSize(XSDataSize(x=XSDataLength(float(beamsize[0])),
                                        y=XSDataLength(float(beamsize[1]))))
        except AttributeError:
            pass

        #Optimization parameters
        diff_plan = edna_input.getDiffractionPlan()

        diff_plan.setAimedIOverSigmaAtHighestResolution(\
            XSDataDouble(char_params.aimed_i_sigma))

        diff_plan.setAimedCompleteness(XSDataDouble(char_params.\
                                                    aimed_completness))

        if char_params.use_aimed_multiplicity:
            diff_plan.setAimedMultiplicity(XSDataDouble(char_params.\
                                                        aimed_multiplicity))
            
        if char_params.use_aimed_resolution:
            diff_plan.setAimedResolution(XSDataDouble(char_params.aimed_resolution))

        diff_plan.setComplexity(XSDataString(\
                queue_model_enumerables.STRATEGY_COMPLEXITY[char_params.strategy_complexity]))

        if char_params.use_permitted_rotation:
            diff_plan.setUserDefinedRotationStart(XSDataAngle(char_params.\
                                                              permitted_phi_start))

            diff_plan.setUserDefinedRotationRange(XSDataAngle(char_params.permitted_phi_end -\
                                                              char_params.permitted_phi_start))


        #Vertical crystal dimension
        sample = edna_input.getSample()
        sample.getSize().setY(XSDataLength(char_params.max_crystal_vdim))
        sample.getSize().setZ(XSDataLength(char_params.min_crystal_vdim))


        #Radiation damage model
        sample.setSusceptibility(XSDataDouble(char_params.rad_suscept))
        sample.setChemicalComposition(None)
        sample.setRadiationDamageModelBeta(XSDataDouble(char_params.beta/1e6))
        sample.setRadiationDamageModelGamma(XSDataDouble(char_params.gamma/1e6))
            

        diff_plan.setForcedSpaceGroup(XSDataString(char_params.\
                                                   space_group))


        # Characterisation type - Routine DC
        if char_params.use_min_dose:
            pass

        if char_params.use_min_time:
            diff_plan.setMaxExposureTimePerDataCollection(XSDataTime(char_params.\
                                                                     min_time))

        
        # Account for radiation damage
        if char_params.induce_burn:
            diff_plan.setStrategyOption(XSDataString("-DamPar")) # What is -DamPar ?
        else:
            diff_plan.setStrategyOption(None)


        # Characterisation type - SAD
        if queue_model_enumerables.EXPERIMENT_TYPE[char_params.experiment_type] is \
               queue_model_enumerables.EXPERIMENT_TYPE.SAD:
            diff_plan.setAnomalousData(XSDataBoolean(True))
        else:
            diff_plan.setAnomalousData(XSDataBoolean(False))

        
        #Data set
        data_set = XSDataMXCuBEDataSet()
        acquisition_parameters = data_collection.acquisitions[0].acquisition_parameters
        path_str = os.path.join(data_collection.acquisitions[0].path_template.directory,
                                data_collection.acquisitions[0].path_template.get_image_file_name())
        
        for img_num in range(int(acquisition_parameters.num_images)):
            image_file = XSDataFile()
            path = XSDataString()
            path.setValue(path_str % (img_num + 1))
            image_file.setPath(path)
            data_set.addImageFile(image_file)

        edna_input.addDataSet(data_set)
        edna_input.process_directory = data_collection.acquisitions[0].path_template.process_directory
        
        return edna_input
Пример #17
0
    def create_input_files(self, xds_dir, mosflm_dir, dc_pars):

        fileinfo = dc_pars['fileinfo']
        osc_seq = dc_pars['oscillation_sequence'][0]

        prefix = fileinfo['prefix']
        runno = fileinfo['run_number']

        exp_time = osc_seq['exposure_time']

        start_angle = osc_seq['start']
        nb_images = osc_seq['number_of_images']
        start_img_num = osc_seq['start_image_number']
        angle_increment = osc_seq['range']

        wavelength = osc_seq.get('wavelength', 0)

        xds_template_name = 'XDS_TEMPLATE.INP'
        mosflm_template_name = 'mosflm_template.dat'

        xds_template_path = os.path.join(self.template_dir, xds_template_name)
        mosflm_template_path = os.path.join(self.template_dir,
                                            mosflm_template_name)

        xds_file = os.path.join(xds_dir, "XDS.INP")
        mosflm_file = os.path.join(mosflm_dir, "mosflm.dat")

        t = datetime.now()

        # PREPARE VARIABLES
        detsamdis = self.var_ds.detsamdis
        beamx, beamy = self.var_ds.beamx, self.var_ds.beamy

        mbeamx, mbeamy = beamy * 0.172, beamx * 0.172

        datarangestartnum = start_img_num
        datarangefinishnum = start_img_num + nb_images - 1
        backgroundrangestartnum = start_img_num
        spotrangestartnum = start_img_num
        if angle_increment != 0:
            minimumrange = int(round(20 / angle_increment))
        elif angle_increment == 0:
            minimumrange = 1
        if nb_images >= minimumrange:
            backgroundrangefinishnum = start_img_num + minimumrange - 1
        if nb_images >= minimumrange:
            spotrangefinishnum = start_img_num + minimumrange - 1
        if nb_images < minimumrange:
            backgroundrangefinishnum = start_img_num + nb_images - 1
        if nb_images < minimumrange:
            spotrangefinishnum = start_img_num + nb_images - 1

        testlowres = 8.
        largestvector = 0.172 * ((max(beamx, 2463 - beamx))**2 +
                                 (max(beamy, 2527 - beamy))**2)**0.5
        testhighres = round(
            wavelength /
            (2 * math.sin(0.5 * math.atan(largestvector / detsamdis))), 2)
        lowres = 50.
        highres = testhighres
        datafilename = prefix + '_' + str(runno) + '_????'
        mdatafilename = prefix + '_' + str(runno) + '_####.cbf'
        seconds = 5 * exp_time

        if angle_increment < 1 and not angle_increment == 0:
            seconds = 5 * exp_time / angle_increment

        # DEFINE SG/UNIT CELL
        spacegroupnumber = ''
        unitcellconstants = ''

        datapath_dir = os.path.abspath(xds_file).replace(
            'PROCESS_DATA', 'RAW_DATA')
        datapath_dir = os.path.dirname(
            os.path.dirname(datapath_dir)) + os.path.sep

        # CREATE XDS.INP FILE
        xds_templ = open(xds_template_path, "r").read()

        xds_templ = xds_templ.replace('###BEAMX###', str(round(beamx, 2)))
        xds_templ = xds_templ.replace("###BEAMY###", str(round(beamy, 2)))
        xds_templ = xds_templ.replace("###DETSAMDIS###",
                                      str(round(detsamdis, 2)))
        xds_templ = xds_templ.replace("###ANGLEINCREMENT###",
                                      str(angle_increment))
        xds_templ = xds_templ.replace("###WAVELENGTH###", str(wavelength))
        xds_templ = xds_templ.replace("###DATARANGESTARTNUM###",
                                      str(datarangestartnum))
        xds_templ = xds_templ.replace("###DATARANGEFINISHNUM###",
                                      str(datarangefinishnum))
        xds_templ = xds_templ.replace("###BACKGROUNDRANGESTART###",
                                      str(backgroundrangestartnum))
        xds_templ = xds_templ.replace("###BACKGROUNDRANGEFINISHNUM###",
                                      str(backgroundrangefinishnum))
        xds_templ = xds_templ.replace("###SPOTRANGESTARTNUM###",
                                      str(spotrangestartnum))
        xds_templ = xds_templ.replace("###SPOTRANGEFINISHNUM###",
                                      str(spotrangefinishnum))
        xds_templ = xds_templ.replace("###TESTLOWRES###", str(testlowres))
        xds_templ = xds_templ.replace("###TESTHIGHRES###", str(testhighres))
        xds_templ = xds_templ.replace("###LOWRES###", str(lowres))
        xds_templ = xds_templ.replace("###HIGHRES###", str(highres))
        xds_templ = xds_templ.replace("###DIRECTORY###", str(datapath_dir))
        xds_templ = xds_templ.replace("###FILENAME###", str(datafilename))
        xds_templ = xds_templ.replace("###SECONDS###", str(int(seconds)))
        xds_templ = xds_templ.replace("###LYSOZYME_SPACE_GROUP_NUMBER###",
                                      str(spacegroupnumber))
        xds_templ = xds_templ.replace("###LYSOZYME_UNIT_CELL_CONSTANTS###",
                                      str(unitcellconstants))

        open(xds_file, "w").write(xds_templ)

        # CREATE MOSFLM.DAT FILE

        mosflm_templ = open(mosflm_template_path, "r").read()

        mosflm_templ = mosflm_templ.replace("###DETSAMDIS###",
                                            str(round(detsamdis, 2)))
        mosflm_templ = mosflm_templ.replace('###BEAMX###',
                                            str(round(mbeamx, 2)))
        mosflm_templ = mosflm_templ.replace("###BEAMY###",
                                            str(round(mbeamy, 2)))
        mosflm_templ = mosflm_templ.replace("###DIRECTORY###",
                                            str(datapath_dir))
        mosflm_templ = mosflm_templ.replace("###FILENAME###",
                                            str(mdatafilename))
        mosflm_templ = mosflm_templ.replace("###WAVELENGTH###",
                                            str(wavelength))
        mosflm_templ = mosflm_templ.replace("###DATARANGESTARTNUM###",
                                            str(datarangestartnum))

        open(mosflm_file, "w").write(mosflm_templ)

        # CREATE EDNAPROC XML FILE
        collection_id = dc_pars['collection_id']
        output_dir = dc_pars['ednaproc_dir']

        ednaproc_input_file = os.path.join(
            output_dir, "EDNAprocInput_%d.xml" % collection_id)

        ednaproc_input = XSDataAutoprocInput()

        input_file = XSDataFile()
        path = XSDataString()
        path.setValue(xds_file)
        input_file.setPath(path)

        ednaproc_input.setInput_file(input_file)
        ednaproc_input.setData_collection_id(XSDataInteger(collection_id))

        #output_dir = XSDataFile()
        #outpath = XSDataString()
        #outpath.setValue(output_dir)
        #output_dir.setPath(path)

        #ednaproc_input.setOutput_directory( output_dir )

        ednaproc_input.exportToFile(ednaproc_input_file)

        self.input_file = ednaproc_input_file
    def from_params(self, data_collection, char_params):
        edna_input = XSDataInputMXCuBE.parseString(self.edna_default_input)

        if data_collection.id:
            edna_input.setDataCollectionId(XSDataInteger(data_collection.id))

        # Beam object
        beam = edna_input.getExperimentalCondition().getBeam()

        try:
            transmission = self.collect_obj.get_transmission()
            beam.setTransmission(XSDataDouble(transmission))
        except AttributeError:
            import traceback

            logging.getLogger("HWR").debug("DataAnalysis. transmission not saved ")
            logging.getLogger("HWR").debug(traceback.format_exc())

        try:
            wavelength = self.collect_obj.get_wavelength()
            beam.setWavelength(XSDataWavelength(wavelength))
        except AttributeError:
            pass

        try:
            beam.setFlux(XSDataFlux(self.collect_obj.get_measured_intensity()))
        except AttributeError:
            pass

        try:
            min_exp_time = self.collect_obj.detector_hwobj.get_exposure_time_limits()[0]
            beam.setMinExposureTimePerImage(XSDataTime(min_exp_time))
        except AttributeError:
            pass

        try:
            beamsize = self.get_beam_size()
            if None not in beamsize:
                beam.setSize(
                    XSDataSize(
                        x=XSDataLength(float(beamsize[0])),
                        y=XSDataLength(float(beamsize[1])),
                    )
                )
        except AttributeError:
            pass

        # Optimization parameters
        diff_plan = edna_input.getDiffractionPlan()

        aimed_i_sigma = XSDataDouble(char_params.aimed_i_sigma)
        aimed_completness = XSDataDouble(char_params.aimed_completness)
        aimed_multiplicity = XSDataDouble(char_params.aimed_multiplicity)
        aimed_resolution = XSDataDouble(char_params.aimed_resolution)

        complexity = char_params.strategy_complexity
        complexity = XSDataString(qme.STRATEGY_COMPLEXITY[complexity])

        permitted_phi_start = XSDataAngle(char_params.permitted_phi_start)
        _range = char_params.permitted_phi_end - char_params.permitted_phi_start
        rotation_range = XSDataAngle(_range)

        if char_params.aimed_i_sigma:
            diff_plan.setAimedIOverSigmaAtHighestResolution(aimed_i_sigma)

        if char_params.aimed_completness:
            diff_plan.setAimedCompleteness(aimed_completness)

        if char_params.use_aimed_multiplicity:
            diff_plan.setAimedMultiplicity(aimed_multiplicity)

        if char_params.use_aimed_resolution:
            diff_plan.setAimedResolution(aimed_resolution)

        diff_plan.setComplexity(complexity)

        if char_params.use_permitted_rotation:
            diff_plan.setUserDefinedRotationStart(permitted_phi_start)
            diff_plan.setUserDefinedRotationRange(rotation_range)

        # Vertical crystal dimension
        sample = edna_input.getSample()
        sample.getSize().setY(XSDataLength(char_params.max_crystal_vdim))
        sample.getSize().setZ(XSDataLength(char_params.min_crystal_vdim))

        # Radiation damage model
        sample.setSusceptibility(XSDataDouble(char_params.rad_suscept))
        sample.setChemicalComposition(None)
        sample.setRadiationDamageModelBeta(XSDataDouble(char_params.beta / 1e6))
        sample.setRadiationDamageModelGamma(XSDataDouble(char_params.gamma / 1e6))

        diff_plan.setForcedSpaceGroup(XSDataString(char_params.space_group))

        # Characterisation type - Routine DC
        if char_params.use_min_dose:
            pass

        if char_params.use_min_time:
            time = XSDataTime(char_params.min_time)
            diff_plan.setMaxExposureTimePerDataCollection(time)

        # Account for radiation damage
        if char_params.induce_burn:
            self.modify_strategy_option(diff_plan, "-DamPar")

        # Characterisation type - SAD
        if char_params.opt_sad:
            if char_params.auto_res:
                diff_plan.setAnomalousData(XSDataBoolean(True))
            else:
                diff_plan.setAnomalousData(XSDataBoolean(False))
                self.modify_strategy_option(diff_plan, "-SAD yes")
                diff_plan.setAimedResolution(XSDataDouble(char_params.sad_res))
        else:
            diff_plan.setAnomalousData(XSDataBoolean(False))

        # Data set
        data_set = XSDataMXCuBEDataSet()
        acquisition_parameters = data_collection.acquisitions[0].acquisition_parameters
        path_template = data_collection.acquisitions[0].path_template
        path_str = os.path.join(
            path_template.directory, path_template.get_image_file_name()
        )

        for img_num in range(int(acquisition_parameters.num_images)):
            image_file = XSDataFile()
            path = XSDataString()
            path.setValue(path_str % (img_num + 1))
            image_file.setPath(path)
            data_set.addImageFile(image_file)

        edna_input.addDataSet(data_set)
        edna_input.process_directory = path_template.process_directory

        return edna_input