Skip to content

Commit

Permalink
fixed freysoldt plotting (#116)
Browse files Browse the repository at this point in the history
* fixed freysoldt plotting

* rename file

* typo
  • Loading branch information
jmmshn authored Apr 5, 2023
1 parent 51ff48f commit fec83bb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
Binary file modified docs/source/_static/img/freysoldt_compare_large_cell.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/source/content/defect-finder.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"id": "22bb4abc-3e14-40c0-92af-6269729a4d3a",
"metadata": {},
"source": [
"# Finding the location of the point defect \n",
"# Defect Finder\n",
"\n",
"As you introduced a defect into a crystalline system, all of the atoms in the system will be subject to displacements\n",
"during the atomic relaxation process. This can be especially problematic for native point defects, since the similar atoms in the simulation cell are technically fungible so split-vacancies and split-interstitials can be created with ill-defined positions.\n",
Expand Down
20 changes: 12 additions & 8 deletions pymatgen/analysis/defects/corrections/freysoldt.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ def perform_pot_corr(

C = np.mean(tmppot)
_logger.debug("C = %f", C)
final_shift = [short[j] + C for j in range(len(v_R))]
v_R = [elmnt - C for elmnt in v_R]
short_range = short
v_R = [elmnt for elmnt in v_R]

_logger.info("C value is averaged to be %f eV ", C)
_logger.info("Potentital alignment energy correction (q * Delta): %f (eV)", q * C)
Expand All @@ -352,7 +352,8 @@ def perform_pot_corr(
"Vr": v_R,
"x": axis_grid,
"dft_diff": np.array(defavg) - np.array(pureavg),
"final_shift": final_shift,
"short_range": short_range,
"shift": C,
"check": [mid - checkdis, mid + checkdis + 1],
}
# log uncertainty:
Expand Down Expand Up @@ -383,23 +384,26 @@ def plot_plnr_avg(plot_data, title=None, saved=False, ax=None):
x = plot_data["pot_plot_data"]["x"]
v_R = plot_data["pot_plot_data"]["Vr"]
dft_diff = plot_data["pot_plot_data"]["dft_diff"]
final_shift = plot_data["pot_plot_data"]["final_shift"]
short_range = plot_data["pot_plot_data"]["short_range"]
check = plot_data["pot_plot_data"]["check"]
C = plot_data["pot_plot_data"]["shift"]

if ax is None:
fig, ax = plt.subplots()
ax.plot(x, v_R, c="green", zorder=1, label="long range from model")
ax.plot(x, v_R, c="black", zorder=1, label="long range from model")
ax.plot(x, dft_diff, c="red", label="DFT locpot diff")
ax.plot(x, final_shift, c="blue", label="short range (aligned)")
ax.plot(x, short_range, c="green", label="short range (not aligned)")
ax.axhline(C, color="k", linestyle="--")
ax.text(4, C, f"C={C:0.3f}", va="bottom")

tmpx = [x[i] for i in range(check[0], check[1])]
ax.fill_between(
tmpx, -100, 100, facecolor="red", alpha=0.15, label="sampling region"
)

ax.set_xlim(round(x[0]), round(x[-1]))
ymin = min(min(v_R), min(dft_diff), min(final_shift))
ymax = max(max(v_R), max(dft_diff), max(final_shift))
ymin = min(min(v_R), min(dft_diff), min(short_range))
ymax = max(max(v_R), max(dft_diff), max(short_range))
ax.set_ylim(-0.2 + ymin, 0.2 + ymax)
ax.set_xlabel(r"distance along axis ($\AA$)", fontsize=15)
ax.set_ylabel("Potential (V)", fontsize=15)
Expand Down
8 changes: 5 additions & 3 deletions pymatgen/analysis/defects/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def _space_group_analyzer(self, structure: Structure) -> SpacegroupAnalyzer:
angle_tolerance=self.angle_tolerance,
)
else: # pragma: no cover
raise ValueError("This generator does not have symprec and angle_tolerance")
raise ValueError(
"This generator is using the `SpaceGroupAnalyzer` and requires `symprec` and `angle_tolerance` to be set."
)

def get_defects(self, *args, **kwargs) -> list[Defect]:
"""Call the generator and convert the results into a list."""
Expand Down Expand Up @@ -291,7 +293,7 @@ def generate(self, structure: Structure, insert_species: set[str] | list[str], *
insert_species: The species to be inserted.
**kwargs: Additional keyword arguments for the ``Interstitial`` constructor.
"""
if len(set(insert_species)) != len(insert_species):
if len(set(insert_species)) != len(insert_species): # pragma: no cover
raise ValueError("Insert species must be unique.")
cand_sites_and_mul = [*self._get_candidate_sites(structure)]
for species in insert_species:
Expand Down Expand Up @@ -368,7 +370,7 @@ def generate(self, chgcar: Chgcar, insert_species: set[str] | list[str], **kwarg
insert_species: The species to be inserted.
**kwargs: Additional keyword arguments for the ``Interstitial`` constructor.
"""
if len(set(insert_species)) != len(insert_species):
if len(set(insert_species)) != len(insert_species): # pragma: no cover
raise ValueError("Insert species must be unique.")
cand_sites_and_mul = [*self._get_candidate_sites(chgcar)]
for species in insert_species:
Expand Down

0 comments on commit fec83bb

Please sign in to comment.