pymatgen-analysis-defects icon indicating copy to clipboard operation
pymatgen-analysis-defects copied to clipboard

[Feature Request]: Customizing pd_entries in FormationEnergyDiagram

Open misaraty opened this issue 1 year ago • 2 comments

Problem

I'd like to customize pd_entries in the FormationEnergyDiagram setup as shown below:

ents = MPR.get_entries_in_chemsys(['Mg', 'Ga', 'N']) or ents = loadfn("Ga_Mg_N.json")
sc_dir = "Mg_Ga/"
fed = FormationEnergyDiagram.with_directories(
    directory_map={
        "bulk": sc_dir + "bulk_sc",
        0: sc_dir + "q=0",
        -1: sc_dir + "q=-1",
        1: sc_dir + "q=1",
    },
    defect=ens,
    pd_entries=ents,
    dielectric=10,
)

I have locally calculated the decomposition phases and competing phases (e.g., mp-1095013 MgGa, mp-844 POSCAR_Ca3N2, mp-1184449 POSCAR_CaMg149, mp-25 POSCAR_N2). I'm wondering if I should modify the pd_entries similar to this:

pd_entries = [
    {"Data": {"run_type": "GGA", "mp-1095013-GGA ComputedStructureEntry": "Mg2 Ga2 (MgGa)", "Energy (Final)": "-8.1302 eV (-2.0325 eV/atom)"}},
    {"Data": {"run_type": "GGA", "mp-1094626-GGA ComputedStructureEntry": "Mg5 Ga1 (Mg5Ga)", "Energy (Final)": "-11.1926 eV (-1.8654 eV/atom)"}}
]

or

pd_entries = [
    {"Mg2 Ga2 (MgGa)", "-8.1302 eV"},
    {"Mg5 Ga1 (Mg5Ga)", "-11.1926 eV"}
]

Thank you!

Proposed Solution

What would be the simplest way to write pd_entries for locally calculated competing phases? Thank you once again!

Alternatives

No response

misaraty avatar Aug 07 '24 12:08 misaraty

If I understand correctly. I would recommend and you write a function that takes the dictionaries from your local calculations and convert it to ComputedEntry's from pymatgen I think that will make the subsequent steps the same.

jmmshn avatar Sep 27 '24 21:09 jmmshn

Reply to a request for more details:

The following is AI generated but seems to be fine.

def parse_vasprun_to_entry(vasprun_path):
    """
    Parse a vasprun.xml file to create a ComputedStructureEntry.
    
    Args:
        vasprun_path (str): Path to vasprun.xml file
        
    Returns:
        ComputedStructureEntry: A computed entry with structure and energy data
    """
    # Parse vasprun.xml
    try:
        vasprun = Vasprun(vasprun_path, parse_dos=False, parse_eigen=False)
    except Exception as e:
        print(f"Error parsing {vasprun_path}: {str(e)}")
        return None
    
    # Get the final structure and energy
    structure = vasprun.final_structure
    energy = vasprun.final_energy
    
    # Create basic parameters dictionary
    parameters = {
        "potcar_symbols": vasprun.potcar_symbols,
        "functional": vasprun.get_xc_functional(),
        "is_spin_polarized": vasprun.is_spin,
    }
    
    # Create the computed entry
    entry = ComputedStructureEntry( # may be replace with ComputedEntry
        structure,
        energy,
        parameters=parameters,
        entry_id=os.path.dirname(vasprun_path)
    )
   
    return entry

jmmshn avatar Feb 25 '25 19:02 jmmshn