Exemplo n.º 1
0
def plot_chem_pot_diag(args) -> None:
    cpd = ChemPotDiag.from_yaml(args.yaml)
    if cpd.dim == 2:
        plotter = ChemPotDiagMpl2DMplPlotter(CpdPlotInfo(cpd))
    elif cpd.dim == 3:
        plotter = ChemPotDiagMpl3DMplPlotter(CpdPlotInfo(cpd))
    else:
        raise CpdNotSupportedError("Number of elements must be 2 or 3. "
                                   f"Now {cpd.vertex_elements}.")
    print(cpd)
    plt = plotter.draw_diagram()
    plt.savefig(fname="cpd.pdf")
    plt.show()
Exemplo n.º 2
0
def cpd_plot_info_2d():
    energies = [
        CompositionEnergy(Composition("H"), 0.0, ""),
        CompositionEnergy(Composition("O"), 1.0, ""),
        CompositionEnergy(Composition("H4O2"), -4.0, "")
    ]
    cpd = ChemPotDiag(energies, target=Composition("H2O"))
    return CpdPlotInfo(cpd, min_range=-10)
Exemplo n.º 3
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()
Exemplo n.º 4
0
def make_layouts(structure: Structure, dos_plot_data, band_plot_data,
                 perfect_dirname, defect_dirnames, supercell_info,
                 chem_pot_diag):
    cpd_plot_info = CpdPlotInfo(ChemPotDiag.from_yaml(chem_pot_diag))
    perfect: CalcResults = loadfn(perfect_dirname / "calc_results.json")

    defects, defect_entries, corrections, single_defect_layouts = [], [], [], []
    for d in defect_dirnames:
        #TODO: check convergence
        defects.append(loadfn(d / "calc_results.json"))
        defect_entry = loadfn(d / "defect_entry.json")
        defect_entries.append(defect_entry)
        corrections.append(loadfn(d / "correction.json"))
        defect_entry: DefectEntry = loadfn(d / "defect_entry.json")
        efnv_correction = loadfn(d / "correction.json")
        eigval = loadfn(d / "band_edge_eigenvalues.json")

        pot = SitePotentialPlotlyPlotter(title=defect_entry.full_name,
                                         efnv_correction=efnv_correction)
        eig = EigenvaluePlotlyPlotter(title=defect_entry.full_name,
                                      band_edge_eigenvalues=eigval,
                                      supercell_vbm=perfect.vbm,
                                      supercell_cbm=perfect.cbm)
        scene_dicts = loadfn(d / "parchgs" / "scene_dicts.json")
        if isinstance(scene_dicts, dict):
            scene_dicts = SceneDicts.from_dict(scene_dicts)

        single_defect_layouts.append(
            SingleDefectComponent(pot,
                                  eig,
                                  scene_dicts,
                                  defect_entry.full_name,
                                  id=f"{defect_entry.full_name}").layout())

    if cpd_plot_info.cpd.dim in [2, 3]:
        cpd_energy_comp = CpdEnergy2D3DComponent(cpd_plot_info, perfect,
                                                 defects, defect_entries,
                                                 corrections)
    else:
        cpd_energy_comp = CpdEnergyOtherComponent(cpd_plot_info, perfect,
                                                  defects, defect_entries,
                                                  corrections)

    structure_component = StructureComponent(structure)
    comp = structure.composition.reduced_formula
    band_dos_component = BandDosComponent(
        dos_plot_data,
        band_plot_data,
        id=f"band_dos_{comp}",
    )
    supercell_component = SupercellComponent(supercell_info)
    symmetrizer = StructureSymmetrizer(structure)
    return create_ctk(structure_component, symmetry_layout(structure),
                      mpid_and_link(symmetrizer), site_layout(symmetrizer),
                      band_dos_component, supercell_component.layout,
                      cpd_energy_comp.layout, single_defect_layouts)
Exemplo n.º 5
0
def cpd_3d_info():
    energies = [
        CompositionEnergy(Composition("H"), 0.0, ""),
        CompositionEnergy(Composition("O"), 1.0, ""),
        CompositionEnergy(Composition("H4O2"), -4.0, ""),
        CompositionEnergy(Composition("MgH2O"), -10.0, ""),
        CompositionEnergy(Composition("Mg"), 0.0, ""),
        CompositionEnergy(Composition("MgO"), -3.0, "")
    ]
    cpd = ChemPotDiag(energies, target=Composition("MgH2O"))
    return CpdPlotInfo(cpd)
Exemplo n.º 6
0
app = JupyterDash(suppress_callback_exceptions=True,
               assets_folder=SETTINGS.ASSETS_PATH)
from vise.analyzer.band_edge_properties import BandEdge

comp_energies = [
    CompositionEnergy(Composition("Mg"), 0.0, "a"),
    CompositionEnergy(Composition("Ca"), 0.0, "a"),
    CompositionEnergy(Composition("Sr"), 0.0, "a"),
    CompositionEnergy(Composition("O"), 0.0, "a"),
    CompositionEnergy(Composition("H"), 0.0, "a"),
#    CompositionEnergy(Composition("MgCaO3"), -100.0, "a"),
    CompositionEnergy(Composition("MgCaSrO3"), -100.0, "a"),
]
#cpd = ChemPotDiag(comp_energies, target=Composition("MgCaO3"))
cpd = ChemPotDiag(comp_energies, target=Composition("MgCaSrO3"))
cpd_plot_info = CpdPlotInfo(cpd)


# In[2]:


print(cpd.target.elements)
print(cpd.dim)
print(cpd.target_vertices)
print(cpd.all_compounds)
print(cpd.impurity_abs_energy(Element.H, label="A"))


# In[3]:

Exemplo n.º 7
0
def cpd_plot_info_wo_min_range(cpd):
    return CpdPlotInfo(cpd)
Exemplo n.º 8
0
def cpd_plot_info():
    cpd = ChemPotDiag(energies, target=Composition("H2O"))
    return CpdPlotInfo(cpd, min_range=-10)
Exemplo n.º 9
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")
Exemplo n.º 10
0

def remove_higher_energy_comp(comp_energies: List[CompositionEnergy]):
    result = []
    for _, grouped_comp_energies in groupby(
            comp_energies, key=lambda x: x.composition.reduced_formula):
        result.append(min(list(grouped_comp_energies),
                          key=lambda y: y.abs_energy_per_atom))
    return result


def parse_args(args):
    parser = argparse.ArgumentParser(description="")
    parser.add_argument("-e", "--elements", type=str, nargs="+")
    parser.add_argument("-he", "--host_elements", type=Element, nargs="+")
    parser.add_argument("-t", "--target", type=Composition)
    parser.add_argument("-f", "--functional", type=str)
    return parser.parse_args(args)


if __name__ == "__main__":
    x = parse_args(sys.argv[1:])
    cpd = make_chem_pot_diag_from_mp(x.elements, x.target,
                                     x.host_elements, x.functional)
    cpd.to_yaml()
    if cpd.dim == 2:
        plotter = ChemPotDiagPlotly2DMplPlotter(CpdPlotInfo(cpd))
    elif cpd.dim == 3:
        plotter = ChemPotDiagPlotly3DMplPlotter(CpdPlotInfo(cpd))
    plotter.figure.show()