示例#1
0
def plot_chem_pot_diag(args) -> None:
    cpd = ChemPotDiag.from_yaml(args.yaml)
    if cpd.dim == 1:
        logger.warning("Single element is not supported for the plot.")
        return

    print(cpd)
    if cpd.dim == 2:
        plotter = ChemPotDiagMpl2DMplPlotter(CpdPlotInfo(cpd))
    elif cpd.dim == 3:
        plotter = ChemPotDiagMpl3DMplPlotter(CpdPlotInfo(cpd))
    else:
        logger.info("Number of elements must be 2 or 3. "
                    f"Now, elements are {cpd.vertex_elements}.")
        return
    plt = plotter.draw_diagram()
    plt.savefig(fname="cpd.pdf")
    plt.show()
示例#2
0
def make_chem_pot_diag(args) -> None:
    if args.elements:
        cpd = make_chem_pot_diag_from_mp(additional_elements=args.elements,
                                         target=args.target,
                                         atom_energy_yaml=args.atom_energy_yaml)
    else:
        comp_es = []
        for d in args.dirs:
            vasprun = Vasprun(d / defaults.vasprun)
            composition = vasprun.final_structure.composition
            energy = float(vasprun.final_energy)  # type is FloatWithUnit
            comp_es.append(CompositionEnergy(composition, energy, "local"))
        if args.update:
            cpd = ChemPotDiag.from_yaml(args.yaml)
            replace_comp_energy(cpd, comp_es)
        else:
            cpd = ChemPotDiag(comp_es, args.target)
    cpd.to_yaml(args.yaml)
示例#3
0
def make_defect_formation_energy(args):
    title = latexify(
        args.perfect_calc_results.structure.composition.reduced_formula)
    chem_pot_diag = ChemPotDiag.from_yaml(args.chem_pot_diag)
    abs_chem_pot = chem_pot_diag.abs_chem_pot_dict(args.label)

    single_energies = []
    for d in args.dirs:
        if args.skip_shallow and loadfn(
                d / "band_edge_states.json").is_shallow:
            continue
        single_energies.append(
            make_single_defect_energy(args.perfect_calc_results,
                                      loadfn(d / "calc_results.json"),
                                      loadfn(d / "defect_entry.json"),
                                      abs_chem_pot,
                                      loadfn(d / "correction.json")))

    defect_energies = make_defect_energies(single_energies)
    if args.print:
        print("         charge          E_f   correction    ")
        for e in defect_energies:
            print(e)
            print("")

        print("-- cross points -- ")
        for e in defect_energies:
            print(e.name)
            print(e.cross_points(args.unitcell.vbm, args.unitcell.cbm))
            print("")
        return

    plotter = DefectEnergyMplPlotter(
        title=title,
        defect_energies=defect_energies,
        vbm=args.unitcell.vbm,
        cbm=args.unitcell.cbm,
        supercell_vbm=args.perfect_calc_results.vbm,
        supercell_cbm=args.perfect_calc_results.cbm,
        y_range=args.y_range)

    plotter.construct_plot()
    plotter.plt.savefig(f"energy_{args.label}.pdf")
示例#4
0
def make_defect_formation_energy(args):
    formula = args.perfect_calc_results.structure.composition.reduced_formula
    chem_pot_diag = ChemPotDiag.from_yaml(args.cpd_yaml)
    pcr = args.perfect_calc_results

    defects, defect_entries, corrections, edge_states = [], [], [], []
    for d in args.dirs:
        if args.skip_shallow:
            edge_states = BandEdgeStates.from_yaml(d / "band_edge_states.yaml")
            if edge_states.is_shallow:
                continue
        defects.append(loadfn(d / "calc_results.json"))
        defect_entries.append(loadfn(d / "defect_entry.json"))
        corrections.append(loadfn(d / "correction.json"))

    if args.web_gui:
        from crystal_toolkit.settings import SETTINGS
        import dash_html_components as html
        from crystal_toolkit.helpers.layouts import Column
        import crystal_toolkit.components as ctc
        import dash

        edge_states = []
        for d in args.dirs:
            edge_states.append(
                BandEdgeStates.from_yaml(d / "band_edge_states.yaml"))

        app = dash.Dash(__name__,
                        suppress_callback_exceptions=True,
                        assets_folder=SETTINGS.ASSETS_PATH,
                        external_stylesheets=[
                            'https://codepen.io/chriddyp/pen/bWLwgP.css'
                        ])

        cpd_plot_info = CpdPlotInfo(chem_pot_diag)
        cpd_e_component = CpdEnergyComponent(cpd_plot_info, pcr, defects,
                                             defect_entries, corrections,
                                             args.unitcell.vbm,
                                             args.unitcell.cbm, edge_states)
        my_layout = html.Div([Column(cpd_e_component.layout)])
        ctc.register_crystal_toolkit(app=app, layout=my_layout, cache=None)
        app.run_server(port=args.port)
        return

    abs_chem_pot = chem_pot_diag.abs_chem_pot_dict(args.label)
    title = " ".join([latexify(formula), "point", args.label])
    defect_energies = make_energies(pcr, defects, defect_entries, corrections,
                                    abs_chem_pot)

    if args.print:
        defect_energies = slide_energy(defect_energies, args.unitcell.vbm)
        print("         charge          E_f   correction    ")
        for e in defect_energies:
            print(e)
            print("")

        print("-- cross points -- ")
        for e in defect_energies:
            print(e.name)
            print(
                e.cross_points(ef_min=args.unitcell.vbm,
                               ef_max=args.unitcell.cbm,
                               base_ef=args.unitcell.vbm))
            print("")
        return

    plotter = DefectEnergyMplPlotter(title=title,
                                     defect_energies=defect_energies,
                                     vbm=args.unitcell.vbm,
                                     cbm=args.unitcell.cbm,
                                     supercell_vbm=pcr.vbm,
                                     supercell_cbm=pcr.cbm,
                                     y_range=args.y_range,
                                     supercell_edge=args.supercell_edge,
                                     label_line=args.label_line,
                                     add_charges=args.add_charges)

    plotter.construct_plot()
    plotter.plt.savefig(f"energy_{args.label}.pdf")
示例#5
0
# -*- coding: utf-8 -*-
#  Copyright (c) 2020 Kumagai group.
import argparse
import sys

from pydefect.chem_pot_diag.chem_pot_diag import ChemPotDiag, CpdPlotInfo
from pydefect.chem_pot_diag.cpd_plotter import ChemPotDiag3DPlotlyPlotter


def parse_args(args):
    parser = argparse.ArgumentParser(description="")
    parser.add_argument("-c", "--chem_pot_diag", type=str)
    parser.add_argument("--port", type=int)
    return parser.parse_args(args)


if __name__ == "__main__":
    args = parse_args(sys.argv[1:])
    cpd = ChemPotDiag.from_yaml(args.chem_pot_diag)
    print(cpd.target_vertices)
    print(cpd.vertex_coords)
    cpd_plot_info = CpdPlotInfo(cpd)
    print(cpd_plot_info.comp_vertices)
    plotter = ChemPotDiag3DPlotlyPlotter(cpd_plot_info)
    fig = plotter.figure
    fig.show()
#    ctc.register_crystal_toolkit(app=app, layout=layout, cache=None)
#    app.run_server(debug=True, port=args.port)