Example #1
0
 def test_as_dict_and_from_dict(self):
     filepath1 = os.path.join(test_dir, "xmu.dat")
     filepath2 = os.path.join(test_dir, "feff.inp")
     x = Xmu.from_file(filepath1, filepath2)
     data = x.data.tolist()
     d = x.as_dict()
     x2 = Xmu.from_dict(d)
     data2 = x2.data.tolist()
     self.assertEqual(data, data2, "Xmu to and from dict does not match")
Example #2
0
 def test_as_dict_and_from_dict(self):
     filepath1 = os.path.join(test_dir, 'xmu.dat')
     filepath2 = os.path.join(test_dir, 'feff.inp')
     x = Xmu.from_file(filepath1, filepath2)
     data=x.data.tolist()
     d=x.as_dict()
     x2 = Xmu.from_dict(d)
     data2= x2.data.tolist()
     self.assertEqual(data, data2, "Xmu to and from dict does not match")
def main():
    """
    Main function.
    """
    parser = argparse.ArgumentParser(description="""
    Convenient DOS Plotter for Feff runs.
    Author: Alan Dozier
    Version: 1.0
    Last updated: April, 2013""")

    parser.add_argument("filename",
                        metavar="filename",
                        type=str,
                        nargs=1,
                        help="xmu file to plot")
    parser.add_argument(
        "filename1",
        metavar="filename1",
        type=str,
        nargs=1,
        help="feff.inp filename to import",
    )

    plt = pretty_plot(12, 8)
    color_order = ["r", "b", "g", "c", "k", "m", "y"]

    args = parser.parse_args()
    xmu = Xmu.from_file(args.filename[0], args.filename1[0])

    data = xmu.as_dict()

    plt.title(data["calc"] + " Feff9.6 Calculation for " + data["atom"] +
              " in " + data["formula"] + " unit cell")
    plt.xlabel("Energies (eV)")
    plt.ylabel("Absorption Cross-section")

    x = data["energies"]
    y = data["scross"]
    tle = "Single " + data["atom"] + " " + data["edge"] + " edge"
    plt.plot(x, y, color_order[1 % 7], label=tle)

    y = data["across"]
    tle = data["atom"] + " " + data["edge"] + " edge in " + data["formula"]
    plt.plot(x, y, color_order[2 % 7], label=tle)

    plt.legend()
    leg = plt.gca().get_legend()
    ltext = leg.get_texts()  # all the text.Text instance in the legend
    plt.setp(ltext, fontsize=15)
    plt.tight_layout()
    plt.show()
def main():
    """
    Main function.
    """
    parser = argparse.ArgumentParser(description='''
    Convenient DOS Plotter for Feff runs.
    Author: Alan Dozier
    Version: 1.0
    Last updated: April, 2013''')

    parser.add_argument('filename',
                        metavar='filename',
                        type=str,
                        nargs=1,
                        help='xmu file to plot')
    parser.add_argument('filename1',
                        metavar='filename1',
                        type=str,
                        nargs=1,
                        help='feff.inp filename to import')

    plt = pretty_plot(12, 8)
    color_order = ['r', 'b', 'g', 'c', 'k', 'm', 'y']

    args = parser.parse_args()
    xmu = Xmu.from_file(args.filename[0], args.filename1[0])

    data = xmu.to_dict

    plt.title(data['calc'] + ' Feff9.6 Calculation for ' + data['atom'] +
              ' in ' + data['formula'] + ' unit cell')
    plt.xlabel('Energies (eV)')
    plt.ylabel('Absorption Cross-section')

    x = data['energies']
    y = data['scross']
    tle = 'Single ' + data['atom'] + ' ' + data['edge'] + ' edge'
    plt.plot(x, y, color_order[1 % 7], label=tle)

    y = data['across']
    tle = data['atom'] + ' ' + data['edge'] + ' edge in ' + data['formula']
    plt.plot(x, y, color_order[2 % 7], label=tle)

    plt.legend()
    leg = plt.gca().get_legend()
    ltext = leg.get_texts()  # all the text.Text instance in the legend
    plt.setp(ltext, fontsize=15)
    plt.tight_layout()
    plt.show()
Example #5
0
def parse_spectrum(output: str,
                   feff_inp: str = '',
                   kind='2dcsv',
                   *args,
                   **kwargs):
    """

    Open a spectrum file with x as the first column
    and y as the second

    :param feff_inp:
    :param output:
    :param kind: default, 2-dimensional comma separated values
    :return:
    """

    if kind == '2dcsv':
        values = loadtxt(fname=output, *args, **kwargs)

        return XAS_Spectrum(x=values[:, 1], y=values[:, 0])

    if kind == '2dcsv_spec':
        values = loadtxt(fname=output, *args, **kwargs)

        return XAS_Spectrum(x=values[:, 0], y=values[:, 1])

    if kind == 'feff_mu':
        xmu = Xmu.from_file(output, feff_inp)

        return XAS_Spectrum(x=xmu.energies, y=xmu.mu)

    if kind == 'json':

        line = open(output, 'r').readline().strip()

        xas = loads(line)

        return XAS_Spectrum.from_dict(xas)

    else:
        raise NotImplementedError("Type of data file not found")
def main():
    parser = argparse.ArgumentParser(description='''
    Convenient DOS Plotter for Feff runs.
    Author: Alan Dozier
    Version: 1.0
    Last updated: April, 2013''')

    parser.add_argument('filename', metavar='filename', type=str, nargs=1,
                        help='xmu file to plot')
    parser.add_argument('filename1', metavar='filename1', type=str, nargs=1,
                        help='feff.inp filename to import')

    plt = get_publication_quality_plot(12, 8)
    color_order = ['r', 'b', 'g', 'c', 'k', 'm', 'y']

    args = parser.parse_args()
    xmu = Xmu.from_file(args.filename[0], args.filename1[0])

    data = xmu.to_dict

    plt.title(data['calc'] + ' Feff9.6 Calculation for ' + data['atom'] + ' in ' +
              data['formula'] + ' unit cell')
    plt.xlabel('Energies (eV)')
    plt.ylabel('Absorption Cross-section')

    x = data['energies']
    y = data['scross']
    tle = 'Single ' + data['atom'] + ' ' + data['edge'] + ' edge'
    plt.plot(x, y, color_order[1 % 7], label=tle)

    y = data['across']
    tle = data['atom'] + ' ' + data['edge'] + ' edge in ' + data['formula']
    plt.plot(x, y, color_order[2 % 7], label=tle)

    plt.legend()
    leg = plt.gca().get_legend()
    ltext = leg.get_texts()  # all the text.Text instance in the legend
    plt.setp(ltext, fontsize=15)
    plt.tight_layout()
    plt.show()
Example #7
0
 def test_init(self):
     filepath1 = os.path.join(test_dir, "xmu.dat")
     filepath2 = os.path.join(test_dir, "feff.inp")
     x = Xmu.from_file(filepath1, filepath2)
     self.assertEqual(x.absorbing_atom, "O", "failed to read xmu.dat file properly")
Example #8
0
 def test_init(self):
     filepath1 = os.path.join(test_dir, 'xmu.dat')
     filepath2 = os.path.join(test_dir, 'feff.inp')
     x = Xmu.from_file(filepath1, filepath2)
     self.assertEqual(x.absorbing_atom, 'O',
                      "failed to read xmu.dat file properly")