Skip to content

Commit

Permalink
Merge f5235cd into 3855d50
Browse files Browse the repository at this point in the history
  • Loading branch information
kavanase committed Jul 7, 2021
2 parents 3855d50 + f5235cd commit a80ab98
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
16 changes: 11 additions & 5 deletions pymatgen/analysis/defects/corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,11 @@ def get_correction(self, entry):
VBM of bulk calculation (or band structure calculation of bulk);
calculated on same level of theory as the defect
(ex. GGA defects -> requires GGA vbm)
run_metadata["defect_incar"] (dict)
Dictionary of INCAR settings for the defect calculation,
required to check if the calculation included spin-orbit coupling
(to determine the spin factor for occupancies of the electron bands)
Returns:
Bandfilling Correction value as a dictionary
Expand All @@ -837,14 +842,15 @@ def get_correction(self, entry):
potalign = entry.parameters["potalign"]
vbm = entry.parameters["vbm"]
cbm = entry.parameters["cbm"]
soc_calc = entry.parameters["run_metadata"]["defect_incar"].get("LSORBIT")

bf_corr = self.perform_bandfill_corr(eigenvalues, kpoint_weights, potalign, vbm, cbm)
bf_corr = self.perform_bandfill_corr(eigenvalues, kpoint_weights, potalign, vbm, cbm, soc_calc)

entry.parameters["bandfilling_meta"] = dict(self.metadata)

return {"bandfilling_correction": bf_corr}

def perform_bandfill_corr(self, eigenvalues, kpoint_weights, potalign, vbm, cbm):
def perform_bandfill_corr(self, eigenvalues, kpoint_weights, potalign, vbm, cbm, soc_calc=False):
"""
This calculates the band filling correction based on excess of electrons/holes in CB/VB...
Expand All @@ -861,15 +867,15 @@ def perform_bandfill_corr(self, eigenvalues, kpoint_weights, potalign, vbm, cbm)
core_occupation_value = list(eigenvalues.values())[0][0][0][1] # get occupation of a core eigenvalue
if len(eigenvalues.keys()) == 1:
# needed because occupation of non-spin calcs is sometimes still 1... should be 2
spinfctr = 2.0 if core_occupation_value == 1.0 else 1.0
spinfctr = 2.0 if core_occupation_value == 1.0 and not soc_calc else 1.0
elif len(eigenvalues.keys()) == 2:
spinfctr = 1.0
else:
raise ValueError("Eigenvalue keys greater than 2")

# for tracking mid gap states...
shifted_cbm = potalign + cbm # shift cbm with potential alignment
shifted_vbm = potalign + vbm # shift vbm with potential alignment
shifted_cbm = cbm - potalign # shift cbm with potential alignment
shifted_vbm = vbm - potalign # shift vbm with potential alignment

for spinset in eigenvalues.values():
for kptset, weight in zip(spinset, kpoint_weights):
Expand Down
3 changes: 2 additions & 1 deletion pymatgen/analysis/defects/defect_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class DefectCompatibility(MSONable):
"initial_defect_structure", "defect_frac_sc_coords"]
kumagai: [ "dielectric", "bulk_atomic_site_averages", "defect_atomic_site_averages",
"site_matching_indices", "initial_defect_structure", "defect_frac_sc_coords"]
bandfilling: ["eigenvalues", "kpoint_weights", "potalign", "vbm", "cbm"]
bandfilling: ["eigenvalues", "kpoint_weights", "potalign", "vbm", "cbm", "run_metadata"]
bandshifting: ["hybrid_cbm", "hybrid_vbm", "vbm", "cbm"]
defect relaxation/structure analysis: ["final_defect_structure", "initial_defect_structure",
"sampling_radius", "defect_frac_sc_coords"]
Expand Down Expand Up @@ -287,6 +287,7 @@ def perform_all_corrections(self, defect_entry):
"potalign",
"vbm",
"cbm",
"run_metadata",
]
run_bandfilling = len(set(defect_entry.parameters.keys()).intersection(required_bandfilling_params)) == len(
required_bandfilling_params
Expand Down
2 changes: 2 additions & 0 deletions pymatgen/analysis/defects/tests/test_corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,14 @@ def test_bandfilling(self):
potalign = 0.0
vbm = v.eigenvalue_band_properties[2]
cbm = v.eigenvalue_band_properties[1]
defect_incar = v.incar
params = {
"eigenvalues": eigenvalues,
"kpoint_weights": kptweights,
"potalign": potalign,
"vbm": vbm,
"cbm": cbm,
"run_metadata": {"defect_incar": defect_incar},
}
bfc = BandFillingCorrection()
struc = PymatgenTest.get_structure("VO2")
Expand Down
11 changes: 10 additions & 1 deletion pymatgen/analysis/defects/tests/test_defect_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ def setUp(self):
potalign = -0.1
vbm = v.eigenvalue_band_properties[2]
cbm = v.eigenvalue_band_properties[1]
defect_incar = v.incar
self.bandfill_params = {
"eigenvalues": eigenvalues,
"kpoint_weights": kptweights,
"potalign": potalign,
"vbm": vbm,
"cbm": cbm,
"run_metadata": {"defect_incar": defect_incar},
}

self.band_edge_params = {
Expand Down Expand Up @@ -108,6 +110,13 @@ def test_process_entry(self):
self.assertAlmostEqual(dentry.corrections["charge_correction"], 5.44595036)

# test over delocalized free carriers which forces skipping charge correction
params = self.bandfill_params.copy() # No Freysoldt metadata
params.update(
{
"hybrid_cbm": params["cbm"] + 0.2,
"hybrid_vbm": params["vbm"] - 0.4,
}
)
# modify the eigenvalue list to have free holes
hole_eigenvalues = {}
for spinkey, spinset in params["eigenvalues"].items():
Expand All @@ -125,7 +134,7 @@ def test_process_entry(self):
dc = DefectCompatibility(free_chg_cutoff=0.8)
dentry = dc.process_entry(dentry)
self.assertAlmostEqual(dentry.corrections["bandedgeshifting_correction"], 1.19999999)
self.assertAlmostEqual(dentry.corrections["bandfilling_correction"], -1.62202400)
self.assertAlmostEqual(dentry.corrections["bandfilling_correction"], -0.492633372744)
self.assertAlmostEqual(dentry.corrections["charge_correction"], 0.0)

# turn off band filling and band edge shifting
Expand Down
Binary file added test_files/vasprun.xml.int_Te_SOC.gz
Binary file not shown.

0 comments on commit a80ab98

Please sign in to comment.