コード例 #1
0
    def prepare_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.set_value(edna_directory)
        output_dir.setPath(path)
        edna_input.setOutputFileDirectory(output_dir)
コード例 #2
0
    def input_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 = HWR.beamline.transmission.get_value()
            beam.setTransmission(XSDataDouble(transmission))
        except AttributeError:
            import traceback

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

        try:
            wavelength = HWR.beamline.energy.get_wavelength()
            beam.setWavelength(XSDataWavelength(wavelength))
        except AttributeError:
            pass

        try:
            beam.setFlux(XSDataFlux(HWR.beamline.flux.get_value()))
        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.collect_obj.beam_info_hwobj.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.set_value(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
コード例 #3
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.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.set_value(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.set_value(output_dir)
        # output_dir.setPath(path)

        # ednaproc_input.setOutput_directory( output_dir )

        ednaproc_input.exportToFile(ednaproc_input_file)

        self.input_file = ednaproc_input_file