Skip to content

Commit

Permalink
Minor Fixes (#92)
Browse files Browse the repository at this point in the history
* minor updates

* fixed notebook

* fixed notebook

* nocover
  • Loading branch information
jmmshn authored Jan 26, 2023
1 parent 6dc9001 commit ae48c75
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 96 deletions.
2 changes: 1 addition & 1 deletion docs/source/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exclude_patterns : [_build, Thumbs.db, .DS_Store, "**.ipynb_checkpoin
# Cache re-execution of notebooks on each build.
# See https://jupyterbook.org/content/execute.html
execute:
execute_notebooks: cache
execute_notebooks: auto

# Define the name of the latex output file for PDF builds
latex:
Expand Down
5 changes: 0 additions & 5 deletions docs/source/_templates/autosummary/base.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/source/_templates/autosummary/class.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/source/_templates/autosummary/function.rst

This file was deleted.

53 changes: 0 additions & 53 deletions docs/source/_templates/autosummary/module.rst

This file was deleted.

2 changes: 1 addition & 1 deletion docs/source/content/formation-energy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"outputs": [],
"source": [
"from pymatgen.analysis.defects.corrections.freysoldt import plot_plnr_avg\n",
"plot_data = fed.defect_entries[1].correction_metadata\n",
"plot_data = fed.defect_entries[1].correction_metadata[\"freysoldt\"]\n",
"plot_plnr_avg(plot_data[0], title=\"Lattice Direction 1\")\n",
"plot_plnr_avg(plot_data[1], title=\"Lattice Direction 2\")\n",
"plot_plnr_avg(plot_data[2], title=\"Lattice Direction 3\")\n"
Expand Down
2 changes: 1 addition & 1 deletion docs/source/content/nonradiative.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:38:29) [Clang 13.0.1 ]"
"version": "3.10.6"
},
"vscode": {
"interpreter": {
Expand Down
38 changes: 22 additions & 16 deletions pymatgen/analysis/defects/ccd.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class HarmonicDefect(MSONable):
defect_band: Optional[Sequence[tuple]] = None
relaxed_index: Optional[int] = None
relaxed_bandstructure: Optional[BandStructure] = None
wswqs: Optional[dict[float, WSWQ]] = None
wswqs: Optional[list[dict]] = None
waveder: Optional[Waveder] = None

def __repr__(self) -> str:
Expand Down Expand Up @@ -326,9 +326,11 @@ def read_wswqs(
raise ValueError(
f"Number of WSWQ files ({len(wswq_files)}) does not match number of distortions ({len(distortions)})."
)
self.wswqs = {d: WSWQ.from_file(f) for d, f in zip(distortions, wswq_files)}
self.wswqs = [
{"Q": d, "wswq": WSWQ.from_file(f)} for d, f in zip(distortions, wswq_files)
]

def get_elph_me(self, defect_state: tuple[int, int, int]) -> npt.ArrayLike:
def get_elph_me(self, defect_state: tuple) -> npt.ArrayLike:
"""Calculate the electron phonon matrix elements.
Combine the data from the WSWQs to calculate the electron phonon matrix elements.
Expand All @@ -350,8 +352,8 @@ def get_elph_me(self, defect_state: tuple[int, int, int]) -> npt.ArrayLike:
"""
if self.wswqs is None:
raise RuntimeError("WSWQs have not been read. Use `read_wswqs` first.")
distortions = list(self.wswqs.keys())
wswqs = list(self.wswqs.values())
distortions = [wswq["Q"] for wswq in self.wswqs]
wswqs = [wswq["wswq"] for wswq in self.wswqs]
band_index, kpoint_index, spin_index = defect_state
# The second band index is associated with the defect state
# since we are usually interested in capture
Expand All @@ -378,10 +380,6 @@ def _get_ediff(self, output_order="skb") -> npt.NDArray:
The eigenvalue difference to the defect band in the order specified by output_order.
"""
if self.defect_band_index is None:
raise ValueError( # pragma: no cover
"The ``defect_band_index`` must be set before ``ediff`` can be computed."
)
if self.relaxed_bandstructure is None:
raise ValueError( # pragma: no cover
"The ``relaxed_bandstructure`` must be set before ``ediff`` can be computed. "
Expand All @@ -390,7 +388,7 @@ def _get_ediff(self, output_order="skb") -> npt.NDArray:

ediffs_ = _get_ks_ediff(
bandstructure=self.relaxed_bandstructure,
defect_band_index=self.defect_band_index,
defect_band=self.defect_band,
)
ediffs_stack = [
ediffs_[Spin.up].T,
Expand Down Expand Up @@ -735,7 +733,7 @@ def _get_wswq_slope(distortions: list[float], wswqs: list[WSWQ]) -> npt.NDArray:

def _get_ks_ediff(
bandstructure: BandStructure,
defect_band_index: int,
defect_band: Sequence[tuple],
) -> dict[Spin, npt.NDArray]:
"""Calculate the Kohn-Sham energy between the defect state.
Expand All @@ -744,15 +742,23 @@ def _get_ks_ediff(
Args:
bandstructure: A BandStructure object.
defect_band_index: The index of the defect band.
defect_band: The defect band given as a list of tuples (band_index, kpoint_index, spin_index).
Returns:
npt.NDArray: The Kohn-Sham energy difference between the defect state and other states.
Indexed the same way as ``bandstructure.bands``.
"""
res = dict()
for k, kpt_bands in bandstructure.bands.items():
e_at_def_band = kpt_bands[defect_band_index, :]
e_diff = kpt_bands - e_at_def_band
res[k] = e_diff
b_at_kpt_and_spin = {(k, s): b for b, k, s in defect_band}
for ispin, eigs in bandstructure.bands.items():
spin_index = 0 if ispin == Spin.up else 1
res[ispin] = np.zeros_like(eigs)
for ikpt, kpt in enumerate(bandstructure.kpoints):
iband = b_at_kpt_and_spin.get((ikpt, spin_index), None)
# import ipdb; ipdb.set_trace()
if iband is None:
continue
e_at_def_band = eigs[iband, ikpt]
e_diff = eigs[:, ikpt] - e_at_def_band
res[ispin][:, ikpt] = e_diff
return res
14 changes: 7 additions & 7 deletions pymatgen/analysis/defects/corrections/kumagai.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@

# check that pydefect is installed
try:
pass
except ImportError:
raise ImportError("pydefect is not installed. Please install it first.")
from pydefect.analyzer.calc_results import CalcResults
from pydefect.cli.vasp.make_efnv_correction import make_efnv_correction
from vise import user_settings
except ImportError: # pragma: no cover
raise ModuleNotFoundError(
"vise/pydefect is not installed. Please install it first."
)

# Disable messages from pydefect import
from vise import user_settings

user_settings.logger.setLevel(logging.CRITICAL)

from pydefect.analyzer.calc_results import CalcResults
from pydefect.cli.vasp.make_efnv_correction import make_efnv_correction
from pymatgen.core import Structure
from pymatgen.io.vasp import Outcar, Vasprun

Expand Down

0 comments on commit ae48c75

Please sign in to comment.