Defect charge correction compatibility

I’m trying to use the DefectCompatibility class in pymatgen.analysis.defect_compatibility, which requires the DefectEntry object to have a parameters dict entry called ‘freysoldt_meta’ in order for DefectEntry.delocalization_analysis() to work correctly. Moving upstream, ‘freysoldt_meta’ is supposed to be added by DefectCompatibility.run_freysoldt(), but only if the DefectEntry.parameters already has the required_frey_params. The documentation for DefectEntry indicates that these parameters are passed as an argument during initialization - does anyone know how I could get those parameters in the first place?

If the defect calculation parsing has been incorporated into Pymatgen, I haven’t found it yet. Until now, I’ve been running the old PyCDT parse_output and compute_corrections from the command line and using their json files to initialize my DefectEntryies, but they don’t produce the parameters necessary for compatibility checking.

Hey Steven. The best way to deal with the DefectCompatibility is the following:

defect_entry = DefectEntry(defect, uncorrected_energy, parameters, entry_id)
DefectCompatibility().process_entry(defect_entry, perform_corrections=True)

This will do all corrections for which you have all necessary parameters. Each defect correction scheme, i.e. freysoldt, has different required parameters that you can see in their class docstrings. For freysoldt you would need the following:

  • axis_grid
  • bulk_planar_averages
  • defect_planar_averages
  • initial_defect_structure
  • final_defect_structure
  • vbm
  • cbm

If you need details about these parameters, let me know.


That’s approximately what I’m doing, although I’m currently using the DictEntry.from_dict() method because I already have the dicts. However, I don’t have the parameters that I would need to check the freysoldt compatibility, such as axis_grid and the averages. How do I get those parameters?

Freysoldt correction is based on taking planar averages of the electrostatic energy for the defect and bulk cells, taking their difference, and using that to subtract the contribution that comes from the defect. This is what the planar averages are referring to. The axis grids are arrays of the same length indicating the cartesian distance from the origin to a particular electrostatic potential value.

If you are using VASP, as I will assume since that’s what pycdt is for, then you use:

from import Locpot

locpot = Locpot.from_file('LOCPOT')
planar_averages = [locpot.get_average_along_axis(i) for i in range(3)]
axis_grids = [locpot.get_axis_grid(i) for i in range(3)]

Since you already have dictionaries, you can just modify them after the fact:

my_defect_entry = DefectEntry.from_dict('defect_entry.json')
my_defect_entry.parameters['bulk_planar_averages'] = bulk_planar_averages

Let me know if you need more info.

1 Like

This is what I needed.