materialsproject / pymatgen

Python Materials Genomics (pymatgen) is a robust materials analysis code that defines classes for structures and molecules with support for many electronic structure codes. It powers the Materials Project.
https://pymatgen.org
Other
1.52k stars 867 forks source link

MaterialsProject2020Compatibility doesn't handle oxidation states #3154

Closed janosh closed 1 year ago

janosh commented 1 year ago

I'm surprised this didn't come up before. Opening this issue rather than quietly fixing to make sure I'm not missing something. It appears MaterialsProject2020Compatibility doesn't currently handle oxidation states.

from pymatgen.entries.compatibility import MaterialsProject2020Compatibility
from pymatgen.entries.computed_entries import ComputedStructureEntry

li_mn_o2 = Structure.from_file("o-LiMnO2_unit.cif")

cse = ComputedStructureEntry(
    li_mn_o2,
    -42,
    parameters={
        "hubbards": {"Mn": 3.9},
        "run_type": "GGA+U"
    }
)

MaterialsProject2020Compatibility(check_potcar=False).process_entries(
    cse, clean=True, inplace=False
)

The above correction fails because this line

https://github.com/materialsproject/pymatgen/blob/edd80a85d61d06ec02c183950c5ed8fb7c0ec0bd/pymatgen/entries/compatibility.py#L175

uses the Element.__str__ (which includes oxidation state e.g. O2-) rather than symbol to match dict keys which are element symbols.

o-LiMnO2_unit.cif ```cif # generated using pymatgen data_LiMnO2 _symmetry_space_group_name_H-M 'P 1' _cell_length_a 2.86877900 _cell_length_b 4.63447500 _cell_length_c 5.83250700 _cell_angle_alpha 90.00000000 _cell_angle_beta 90.00000000 _cell_angle_gamma 90.00000000 _symmetry_Int_Tables_number 1 _chemical_formula_structural LiMnO2 _chemical_formula_sum 'Li2 Mn2 O4' _cell_volume 77.54484024 _cell_formula_units_Z 2 loop_ _symmetry_equiv_pos_site_id _symmetry_equiv_pos_as_xyz 1 'x, y, z' loop_ _atom_type_symbol _atom_type_oxidation_number Li+ 1.0 Mn3+ 3.0 O2- -2.0 loop_ _atom_site_type_symbol _atom_site_label _atom_site_symmetry_multiplicity _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z _atom_site_occupancy Li+ Li0 1 0.50000000 0.50000000 0.37975050 1 Li+ Li1 1 0.00000000 0.00000000 0.62024950 1 Mn3+ Mn2 1 0.50000000 0.50000000 0.86325250 1 Mn3+ Mn3 1 0.00000000 0.00000000 0.13674750 1 O2- O4 1 0.50000000 0.00000000 0.36082450 1 O2- O5 1 0.00000000 0.50000000 0.09851350 1 O2- O6 1 0.50000000 0.00000000 0.90148650 1 O2- O7 1 0.00000000 0.50000000 0.63917550 1 ```
shyuep commented 1 year ago

I think the fix is just to use el.symbol instead? Most of the time the compatibility is operated on MP entries. Most of which don't come with oxidation state decorated.

janosh commented 1 year ago

Yes, the fix is straightforward. Just baffled that it hasn't come up before.