Example #1
0
def xoppy_calc_xxcom(
    NAME="Pyrex Glass",
    SUBSTANCE=3,
    DESCRIPTION="SiO2:B2O3:Na2O:Al2O3:K2O",
    FRACTION="0.807:0.129:0.038:0.022:0.004",
    GRID=1,
    GRIDINPUT=0,
    GRIDDATA="0.0804:0.2790:0.6616:1.3685:2.7541",
    ELEMENTOUTPUT=0,
):
    print("Inside xoppy_calc_xxcom. ")

    try:
        with open("xoppy.inp", "wt") as f:
            f.write(os.path.join(locations.home_data(), "xcom") + os.sep + "\n")
            f.write(NAME + "\n")
            f.write("%d\n" % (1 + SUBSTANCE))
            if (1 + SUBSTANCE) != 4:
                f.write(DESCRIPTION + "\n")
                if (1 + SUBSTANCE) <= 2:
                    f.write("%d\n" % (1 + ELEMENTOUTPUT))
            else:
                nn = DESCRIPTION.split(":")
                mm = FRACTION.split(":")
                f.write("%d\n" % (len(nn)))
                for i in range(len(nn)):
                    f.write(nn[i] + "\n")
                    f.write(mm[i] + "\n")
                f.write("1\n")
            f.write("%d\n" % (1 + GRID))
            if (1 + GRID) != 1:
                f.write("%d\n" % (1 + GRIDINPUT))
                if (1 + GRIDINPUT) == 1:
                    nn = GRIDDATA.split(":")
                    f.write("%d\n" % (len(nn)))
                    for i in nn:
                        f.write(i + "\n")
                    if (1 + GRID) != 1:
                        f.write("N\n")
            f.write("xcom.out\n")
            f.write("1\n")
            f.close()

        command = os.path.join(locations.home_bin(), "xcom") + " < xoppy.inp"
        print("Running command '%s' in directory: %s " % (command, locations.home_bin_run()))
        print("\n--------------------------------------------------------\n")
        os.system(command)
        print("\n--------------------------------------------------------\n")
        # write spec file

        if (1 + SUBSTANCE) <= 2:
            if (1 + ELEMENTOUTPUT) == 1:
                titles = (
                    "Photon Energy [Mev]  Coherent scat [b/atom]  "
                    "Incoherent scat [b/atom]  Photoel abs [b/atom]  "
                    "Pair prod in nucl field [b/atom]  Pair prod in elec field [b/atom]  "
                    "Tot atten with coh scat [b/atom]  Tot atten w/o coh scat [b/atom]"
                )
            elif (1 + ELEMENTOUTPUT) == 2:
                titles = (
                    "Photon Energy [Mev]  Coherent scat [b/atom]  "
                    "Incoherent scat [b/atom]  Photoel abs [b/atom]  "
                    "Pair prod in nucl field [b/atom]  Pair prod in elec field [b/atom]  "
                    "Tot atten with coh scat [cm2/g]  Tot atten w/o coh scat [cm2/g]"
                )
            elif (1 + ELEMENTOUTPUT) == 3:
                titles = (
                    "Photon Energy [Mev]  Coherent scat [cm2/g]  "
                    "Incoherent scat [cm2/g]  Photoel abs [cm2/g]  "
                    "Pair prod in nucl field [cm2/g]  Pair prod in elec field [cm2/g]  "
                    "Tot atten with coh scat [cm2/g]  Tot atten w/o coh scat [cm2/g]"
                )
            else:
                titles = (
                    "Photon Energy [Mev]  Coherent scat [cm2/g]  "
                    "Incoherent scat [cm2/g]  Photoel abs [cm2/g]  "
                    "Pair prod in nucl field [cm2/g]  Pair prod in elec field [cm2/g]  "
                    "Tot atten with coh scat [cm2/g]  Tot atten w/o coh scat [cm2/g]"
                )
        else:
            titles = (
                "Photon Energy [Mev]  Coherent scat [cm2/g]  "
                "Incoherent scat [cm2/g]  Photoel abs [cm2/g]  "
                "Pair prod in nucl field [cm2/g]  Pair prod in elec field [cm2/g]  "
                "Tot atten with coh scat [cm2/g]  Tot atten w/o coh scat [cm2/g]"
            )

        txt = open("xcom.out").readlines()

        # copy to standard output
        for line in txt:
            print(line, end="")

        outFile = "xcom.spec"

        f = open(outFile, "w")

        f.write("#F xcom.spec\n")
        f.write("\n")
        f.write("#S 1 xcom results\n")
        f.write("#N 8\n")
        f.write("#L  " + titles + "\n")
        for i in txt:
            tmp = i.strip(" ")
            if tmp[0].isdigit():
                f.write(tmp)
            else:
                f.write("#UD " + tmp)
        f.close()
        print("File written to disk: xcom.spec")

        return outFile
    except Exception as e:
        raise e
Example #2
0
def xoppy_calc_xxcom(NAME="Pyrex Glass",SUBSTANCE=3,DESCRIPTION="SiO2:B2O3:Na2O:Al2O3:K2O",\
                     FRACTION="0.807:0.129:0.038:0.022:0.004",GRID=1,GRIDINPUT=0,\
                     GRIDDATA="0.0804:0.2790:0.6616:1.3685:2.7541",ELEMENTOUTPUT=0):
    print("Inside xoppy_calc_xxcom. ")

    try:
        with open("xoppy.inp","wt") as f:
            f.write(os.path.join(locations.home_data(), 'xcom')+ os.sep + "\n" )
            f.write( NAME+"\n" )
            f.write("%d\n"%(1+SUBSTANCE))
            if (1+SUBSTANCE) != 4:
                f.write( DESCRIPTION+"\n")
                if (1+SUBSTANCE) <= 2:
                    f.write("%d\n"%(1+ELEMENTOUTPUT))
            else:
                nn = DESCRIPTION.split(":")
                mm = FRACTION.split(":")
                f.write("%d\n"%( len(nn)))
                for i in range(len(nn)):
                    f.write(nn[i]+"\n")
                    f.write(mm[i]+"\n")
                f.write("1\n")
            f.write("%d\n"%(1+GRID))
            if (1+GRID) != 1:
                f.write("%d\n"%(1+GRIDINPUT))
                if (1+GRIDINPUT) == 1:
                    nn = GRIDDATA.split(":")
                    f.write("%d\n"%( len(nn)))
                    for i in nn:
                        f.write(i+"\n")
                    if (1+GRID) != 1:
                        f.write("N\n")
            f.write("xcom.out\n")
            f.write("1\n")
            f.close()

        command = "'" + os.path.join(locations.home_bin(),'xcom') + "' < xoppy.inp"
        print("Running command '%s' in directory: %s "%(command,locations.home_bin_run()))
        print("\n--------------------------------------------------------\n")
        os.system(command)
        print("\n--------------------------------------------------------\n")
        # write spec file

        if (1+SUBSTANCE) <= 2:
            if (1+ELEMENTOUTPUT) == 1:
                titles = "Photon Energy [Mev]  Coherent scat [b/atom]  " \
                         "Incoherent scat [b/atom]  Photoel abs [b/atom]  " \
                         "Pair prod in nucl field [b/atom]  Pair prod in elec field [b/atom]  " \
                         "Tot atten with coh scat [b/atom]  Tot atten w/o coh scat [b/atom]"
            elif (1+ELEMENTOUTPUT) == 2:
                titles = "Photon Energy [Mev]  Coherent scat [b/atom]  " \
                         "Incoherent scat [b/atom]  Photoel abs [b/atom]  " \
                         "Pair prod in nucl field [b/atom]  Pair prod in elec field [b/atom]  " \
                         "Tot atten with coh scat [cm2/g]  Tot atten w/o coh scat [cm2/g]"
            elif (1+ELEMENTOUTPUT) == 3:
                titles = "Photon Energy [Mev]  Coherent scat [cm2/g]  " \
                         "Incoherent scat [cm2/g]  Photoel abs [cm2/g]  " \
                         "Pair prod in nucl field [cm2/g]  Pair prod in elec field [cm2/g]  " \
                         "Tot atten with coh scat [cm2/g]  Tot atten w/o coh scat [cm2/g]"
            else:
                titles = "Photon Energy [Mev]  Coherent scat [cm2/g]  " \
                         "Incoherent scat [cm2/g]  Photoel abs [cm2/g]  " \
                         "Pair prod in nucl field [cm2/g]  Pair prod in elec field [cm2/g]  " \
                         "Tot atten with coh scat [cm2/g]  Tot atten w/o coh scat [cm2/g]"
        else:
           titles = "Photon Energy [Mev]  Coherent scat [cm2/g]  " \
                    "Incoherent scat [cm2/g]  Photoel abs [cm2/g]  " \
                    "Pair prod in nucl field [cm2/g]  Pair prod in elec field [cm2/g]  " \
                    "Tot atten with coh scat [cm2/g]  Tot atten w/o coh scat [cm2/g]"


        txt = open("xcom.out").readlines()

        # copy to standard output
        for line in txt:
            print(line,end="")

        outFile = "xcom.spec"

        f = open(outFile, "w")

        f.write("#F xcom.spec\n")
        f.write("\n")
        f.write("#S 1 xcom results\n")
        f.write("#N 8\n")
        f.write("#L  "+titles+"\n")
        for i in txt:
            tmp = i.strip(" ")
            if tmp[0].isdigit():
               f.write(tmp)
            else:
               f.write("#UD "+tmp)
        f.close()
        print("File written to disk: xcom.spec")

        return outFile
    except Exception as e:
        raise e
Example #3
0
def xoppy_calc_xinpro(CRYSTAL_MATERIAL=0,MODE=0,ENERGY=8000.0,MILLER_INDEX_H=1,MILLER_INDEX_K=1,MILLER_INDEX_L=1,\
                      ASYMMETRY_ANGLE=0.0,THICKNESS=500.0,TEMPERATURE=300.0,NPOINTS=100,SCALE=0,XFROM=-50.0,XTO=50.0):
    print("Inside xoppy_calc_xinpro. ")

    try:
        with open("xoppy.inp", "wt") as f:
            f.write("%s\n"% (os.path.join(locations.home_data(), "inpro" + os.sep)))
            if MODE == 0:
                f.write("+1\n")
            elif MODE == 1:
                f.write("-1\n")
            elif MODE == 2:
                f.write("+2\n")
            elif MODE == 3:
                f.write("-1\n")
            else:
                f.write("ERROR!!\n")

            f.write("%f\n%d\n"%(THICKNESS,CRYSTAL_MATERIAL+1))
            f.write("%s\n%f\n"%("EV",ENERGY))
            f.write("%d\n%d\n%d\n"%(MILLER_INDEX_H,MILLER_INDEX_K,MILLER_INDEX_L))
            f.write("%f\n%f\n%s\n"%(ASYMMETRY_ANGLE,TEMPERATURE, "inpro.dat"))
            if SCALE == 0:
                f.write("1\n")
            else:
                f.write("%d\n%f\n%f\n"%(2,XFROM,XTO))
            f.write("%d\n"%(NPOINTS))


        for file in ["inpro.par","inpro.dat","inpro.spec"]:
            try:
                os.remove(os.path.join(locations.home_bin_run(),file))
            except:
                pass


        command = os.path.join(locations.home_bin(), 'inpro') + " < xoppy.inp"
        print("Running command '%s' in directory: %s "%(command, locations.home_bin_run()))
        print("\n--------------------------------------------------------\n")
        os.system(command)
        print("\n--------------------------------------------------------\n")

        #add SPEC header
        txt = open("inpro.dat").read()
        outFile = "inpro.spec"

        f = open(outFile,"w")
        f.write("#F inpro.spec\n")
        f.write("\n")
        f.write("#S 1 inpro results\n")
        f.write("#N 3\n")
        f.write("#L Theta-TetaB  s-polarized reflectivity  p-polarized reflectivity\n")
        f.write(txt)
        f.close()
        print("File written to disk: inpro.dat, inpro.par, inpro.spec")

        #show calculated parameters in standard output
        txt_info = open("inpro.par").read()
        for line in txt_info:
            print(line,end="")


        return outFile
    except Exception as e:
        raise e
Example #4
0
class OWxpowder_fml(XoppyWidget):
    name = "POWDER_FML"
    id = "orange.widgets.dataxpowder_fml"
    description = "X-ray Powder Diffraction Pattern"
    icon = "icons/xoppy_xpowder_fml.png"
    priority = 23
    category = ""
    keywords = ["xoppy", "xpowder_fml"]

    FILE = Setting(
        os.path.join(
            locations.home_data(),
            "cif" + os.sep + "icsd_31142_sepiolite_BraunerPreisinger.cif"))
    TITLE = Setting("powder pattern using crysFML")
    LAMBDA = Setting(1.54056)
    JOB = Setting(0)
    U = Setting(0.0002)
    V = Setting(-0.0002)
    W = Setting(0.012)
    X = Setting(0.0019)
    LS = Setting(1900.0)
    THMIN = Setting(1.0)
    STEP = Setting(0.05)
    THMAX = Setting(135.0)

    def build_gui(self):

        box = oasysgui.widgetBox(self.controlArea,
                                 self.name + " Input Parameters",
                                 orientation="vertical",
                                 width=self.CONTROL_AREA_WIDTH - 5)

        idx = -1

        #widget index 0
        idx += 1
        box1 = gui.widgetBox(box)

        file_box = oasysgui.widgetBox(box1,
                                      "",
                                      addSpace=False,
                                      orientation="horizontal",
                                      height=25)

        self.le_file = oasysgui.lineEdit(file_box,
                                         self,
                                         "FILE",
                                         label=self.unitLabels()[idx],
                                         addSpace=False,
                                         orientation="horizontal")
        self.show_at(self.unitFlags()[idx], box1)

        gui.button(file_box, self, "...", callback=self.selectFile)

        #widget index 1
        idx += 1
        box1 = gui.widgetBox(box)
        oasysgui.lineEdit(box1,
                          self,
                          "TITLE",
                          label=self.unitLabels()[idx],
                          addSpace=False,
                          orientation="horizontal")
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 2
        idx += 1
        box1 = gui.widgetBox(box)
        oasysgui.lineEdit(box1,
                          self,
                          "LAMBDA",
                          label=self.unitLabels()[idx],
                          addSpace=False,
                          valueType=float,
                          validator=QDoubleValidator(),
                          orientation="horizontal",
                          labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 3
        idx += 1
        box1 = gui.widgetBox(box)
        gui.comboBox(box1,
                     self,
                     "JOB",
                     label=self.unitLabels()[idx],
                     addSpace=False,
                     items=['X rays', 'Neutrons'],
                     valueType=int,
                     orientation="horizontal",
                     labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 4
        idx += 1
        box1 = gui.widgetBox(box)
        oasysgui.lineEdit(box1,
                          self,
                          "U",
                          label=self.unitLabels()[idx],
                          addSpace=False,
                          valueType=float,
                          validator=QDoubleValidator(),
                          orientation="horizontal",
                          labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 5
        idx += 1
        box1 = gui.widgetBox(box)
        oasysgui.lineEdit(box1,
                          self,
                          "V",
                          label=self.unitLabels()[idx],
                          addSpace=False,
                          valueType=float,
                          validator=QDoubleValidator(),
                          orientation="horizontal",
                          labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 6
        idx += 1
        box1 = gui.widgetBox(box)
        oasysgui.lineEdit(box1,
                          self,
                          "W",
                          label=self.unitLabels()[idx],
                          addSpace=False,
                          valueType=float,
                          validator=QDoubleValidator(),
                          orientation="horizontal",
                          labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 7
        idx += 1
        box1 = gui.widgetBox(box)
        oasysgui.lineEdit(box1,
                          self,
                          "X",
                          label=self.unitLabels()[idx],
                          addSpace=False,
                          valueType=float,
                          validator=QDoubleValidator(),
                          orientation="horizontal",
                          labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 8
        idx += 1
        box1 = gui.widgetBox(box)
        oasysgui.lineEdit(box1,
                          self,
                          "LS",
                          label=self.unitLabels()[idx],
                          addSpace=False,
                          valueType=float,
                          validator=QDoubleValidator(),
                          orientation="horizontal",
                          labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 9
        idx += 1
        box1 = gui.widgetBox(box)
        oasysgui.lineEdit(box1,
                          self,
                          "THMIN",
                          label=self.unitLabels()[idx],
                          addSpace=False,
                          valueType=float,
                          validator=QDoubleValidator(),
                          orientation="horizontal",
                          labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 10
        idx += 1
        box1 = gui.widgetBox(box)
        oasysgui.lineEdit(box1,
                          self,
                          "STEP",
                          label=self.unitLabels()[idx],
                          addSpace=False,
                          valueType=float,
                          validator=QDoubleValidator(),
                          orientation="horizontal",
                          labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 11
        idx += 1
        box1 = gui.widgetBox(box)
        oasysgui.lineEdit(box1,
                          self,
                          "THMAX",
                          label=self.unitLabels()[idx],
                          addSpace=False,
                          valueType=float,
                          validator=QDoubleValidator(),
                          orientation="horizontal",
                          labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

    def unitLabels(self):
        return [
            'CIF File: ', 'Title:', 'Lambda [A]: ', 'Radiation:', 'U: ', 'V: ',
            'W: ', 'X: ', 'Ls:', 'TwoTheta from [deg]', 'TwoTheta step: ',
            'TwoTheta to', 'None'
        ]

    def unitFlags(self):
        return [
            '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1'
        ]

    def selectFile(self):
        self.le_file.setText(
            oasysgui.selectFileFromDialog(self,
                                          self.FILE,
                                          "Open CIF File",
                                          file_extension_filter="*.cif"))

    def get_help_name(self):
        return 'powder_fml'

    def check_fields(self):
        congruence.checkFile(self.FILE)
        self.LAMBDA = congruence.checkStrictlyPositiveNumber(
            self.LAMBDA, "Lambda")
        self.U = congruence.checkNumber(self.U, "U")
        self.V = congruence.checkNumber(self.V, "V")
        self.W = congruence.checkNumber(self.W, "W")
        self.X = congruence.checkNumber(self.X, "X")
        self.LS = congruence.checkNumber(self.LS, "LS")
        self.THMIN = congruence.checkPositiveAngle(self.THMIN, "TwoTheta from")
        self.THMAX = congruence.checkPositiveAngle(self.THMAX, "TwoTheta to")
        self.STEP = congruence.checkStrictlyPositiveAngle(
            self.STEP, "TwoTheta step")
        congruence.checkGreaterThan(self.THMAX, self.THMIN, "TwoTheta to",
                                    "TwoTheta from")

    def do_xoppy_calculation(self):
        return self.xoppy_calc_xpowder_fml()

    def extract_data_from_xoppy_output(self, calculation_output):
        return calculation_output

    def get_data_exchange_widget_name(self):
        return "XPOWDER_FML"

    def getTitles(self):
        return ["Diffraction Pattern"]

    def getXTitles(self):
        return ["TwoTheta[Deg]"]

    def getYTitles(self):
        return ["Intensity[a.u.]"]

    def xoppy_calc_xpowder_fml(self):

        for file in ["xpowder_fml.par", "xpowder_fml.ref", "xpowder_fml.out"]:
            try:
                os.remove(os.path.join(locations.home_bin_run(), file))
            except:
                pass

        with open("xoppy.inp", "wt") as f:
            f.write("%s\n" % (self.FILE))
            f.write("%s\n" % (self.TITLE))
            f.write("%g\n" % (self.LAMBDA))
            f.write("%s\n" % (self.JOB))
            f.write("%g\n" % (self.U))
            f.write("%g\n" % (self.V))
            f.write("%g\n" % (self.W))
            f.write("%g\n" % (self.X))
            f.write("%g\n" % (self.LS))
            f.write("%g\n" % (self.THMIN))
            f.write("%g\n" % (self.STEP))
            f.write("%s\n" % (self.THMAX))

        command = "'" + os.path.join(locations.home_bin(),
                                     'xpowder_fml') + "' < xoppy.inp"
        print("Running command '%s' in directory: %s " %
              (command, locations.home_bin_run()))
        print("\n--------------------------------------------------------\n")
        os.system(command)
        print("\n--------------------------------------------------------\n")

        print(
            "Files written to disk:\n    xpowder_fml.par (text output)\n    xpowder_fml.ref (reflections)\n    xpowder_fml.out (diffractogram)",
        )
        #
        # data = numpy.loadtxt("xpowder_fml.out",skiprows=3).T

        #send exchange
        calculated_data = DataExchangeObject(
            "XOPPY", self.get_data_exchange_widget_name())

        try:
            calculated_data.add_content(
                "xoppy_data", numpy.loadtxt("xpowder_fml.out", skiprows=3))
            calculated_data.add_content("plot_x_col", 0)
            calculated_data.add_content("plot_y_col", -1)
        except:
            pass
        try:
            calculated_data.add_content("labels",
                                        ["TwoTheta[Deg]", "Intensity[a.u.]"])
        except:
            pass
        try:
            with open("xpowder_fml.par") as f:
                info = f.readlines()
            info = [line[:-1] for line in info]  # remove "\n"
            calculated_data.add_content("info", info)
        except:
            pass

        return calculated_data
Example #5
0
def xoppy_calc_xinpro(CRYSTAL_MATERIAL=0,MODE=0,ENERGY=8000.0,MILLER_INDEX_H=1,MILLER_INDEX_K=1,MILLER_INDEX_L=1,\
                      ASYMMETRY_ANGLE=0.0,THICKNESS=500.0,TEMPERATURE=300.0,NPOINTS=100,SCALE=0,XFROM=-50.0,XTO=50.0):
    print("Inside xoppy_calc_xinpro. ")

    try:
        with open("xoppy.inp", "wt") as f:
            f.write("%s\n" %
                    (os.path.join(locations.home_data(), "inpro" + os.sep)))
            if MODE == 0:
                f.write("+1\n")
            elif MODE == 1:
                f.write("-1\n")
            elif MODE == 2:
                f.write("+2\n")
            elif MODE == 3:
                f.write("-1\n")
            else:
                f.write("ERROR!!\n")

            f.write("%f\n%d\n" % (THICKNESS, CRYSTAL_MATERIAL + 1))
            f.write("%s\n%f\n" % ("EV", ENERGY))
            f.write("%d\n%d\n%d\n" %
                    (MILLER_INDEX_H, MILLER_INDEX_K, MILLER_INDEX_L))
            f.write("%f\n%f\n%s\n" %
                    (ASYMMETRY_ANGLE, TEMPERATURE, "inpro.dat"))
            if SCALE == 0:
                f.write("1\n")
            else:
                f.write("%d\n%f\n%f\n" % (2, XFROM, XTO))
            f.write("%d\n" % (NPOINTS))

        for file in ["inpro.par", "inpro.dat", "inpro.spec"]:
            try:
                os.remove(os.path.join(locations.home_bin_run(), file))
            except:
                pass

        command = "'" + os.path.join(locations.home_bin(),
                                     'inpro') + "' < xoppy.inp"
        print("Running command '%s' in directory: %s " %
              (command, locations.home_bin_run()))
        print("\n--------------------------------------------------------\n")
        os.system(command)
        print("\n--------------------------------------------------------\n")

        #add SPEC header
        txt = open("inpro.dat").read()
        outFile = "inpro.spec"

        f = open(outFile, "w")
        f.write("#F inpro.spec\n")
        f.write("\n")
        f.write("#S 1 inpro results\n")
        f.write("#N 3\n")
        f.write(
            "#L Theta-TetaB  s-polarized reflectivity  p-polarized reflectivity\n"
        )
        f.write(txt)
        f.close()
        print("File written to disk: inpro.dat, inpro.par, inpro.spec")

        #show calculated parameters in standard output
        txt_info = open("inpro.par").read()
        for line in txt_info:
            print(line, end="")

        return outFile
    except Exception as e:
        raise e