Skip to content

Commit

Permalink
notebook testing (#161)
Browse files Browse the repository at this point in the history
* plotting in tutorials

plotting in tutorials

* nbmake
  • Loading branch information
jmmshn authored Dec 12, 2023
1 parent fe55a5c commit 2622c96
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 32 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ jobs:
pip install -e .[tests]
- name: Test
run: pytest --cov=pymatgen --cov-report=xml
run: |
pytest --cov=pymatgen --cov-report=xml
pytest --nbmake ./docs/source/content
- uses: codecov/codecov-action@v1
if: matrix.python-version == 3.10
Expand Down
17 changes: 6 additions & 11 deletions docs/source/content/formation-energy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"# Formation Energy Diagrams\n",
"\n",
"The formation energy diagram is perhaps the most important tool in analyzing the defect properties.\n",
"It informs both the likelihood of a defect to form and transition level where the charge state of the defect changes.\n",
"It informs both the likelihood of a defect forming and the transition level where the charge state of the defect changes.\n",
"\n",
"The formation energy of a defect is determined by the chemical potential of everything that goes into forming the defect.\n",
"While all of the different chemical potentials are interconnected, it is conceptually easier to separate them into two groups: the chemical potential of the elements and the chemical potential of the electron.\n",
"The chemical potential of the electron, often called the *Fermi level*, accounts for how all of the external conditions, including the presence of other defects, affect the thermodynamics of adding or removing an electron from the defect.\n",
"The chemical potential of the electron often called the *Fermi level*, accounts for how all of the external conditions, including the presence of other defects, affect the thermodynamics of adding or removing an electron from the defect.\n",
"Since the electrons in the system can be manipulated after the defect is formed, the *Fermi level* is often considered a free variable and is shown as the x-axis in the formation energy diagram.\n",
"The chemical potentials of the different atoms added or removed to form the defect are less dynamic and assumed to be fixed after the defect is formed.\n",
"\n",
Expand Down Expand Up @@ -104,7 +104,7 @@
"source": [
"## Getting the Elemental Chemical Potentials\n",
"\n",
"All of the chemical potentials are, in principle, free variables that indicates the conditions of the surrounding environment while the defect is formed.\n",
"All of the chemical potentials are, in principle, free variables that indicate the conditions of the surrounding environment while the defect is formed.\n",
"These free variables are bound by the enthalpies of formation of the various compounds that share the same elements as the defect and bulk material.\n",
"These competing compounds essentially establish the boundaries of the allowed chemical potentials, while the VBM and CBM of the bulk material determine the allowed range of the Fermi level.\n",
"As such, first-principles calculations can be used to determine the limits of the various chemical potentials. \n",
Expand All @@ -118,7 +118,7 @@
"\\end{aligned}\n",
"$$\n",
"\n",
"Here since the defect must for in GaN the chemical potentials are pinned by the plane defined by the enthalpy of formation of GaN.\n",
"Here since the defect must form in GaN the chemical potentials are pinned by the plane defined by the enthalpy of formation of GaN.\n",
"The limits imposed by the competing compounds are shown by the additional inequalities.\n",
"The points of interest are usually vertex points in the constrained chemical potential space so we report the full set of vertex points in `FormationEnergyDiagram.chempot_limits`."
]
Expand Down 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[\"freysoldt\"]\n",
"plot_data = fed.defect_entries[1].corrections_metadata[\"freysoldt\"][\"plot_data\"]\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 All @@ -182,12 +182,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
},
"vscode": {
"interpreter": {
"hash": "68485e4e4f6ba0276341f7d764a6dd3a7d31473cb629faa542bbbd38a80276a6"
}
"version": "3.9.16"
}
},
"nbformat": 4,
Expand Down
20 changes: 7 additions & 13 deletions docs/source/content/nonradiative.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"\n",
"Shockley-Read-Hall (SRH) recombination is the dominant recombination mechanism at lower carrier concentrations.\n",
"First-principles calculations of the SRH recombination rate were pioneered in the Van de Walle group at the University of California, Santa Barbara by Prof. Audrius Alisauskas {cite:p}`Alkauskas2014Aug`.\n",
"Additional development have been made to better integrate the methodology with existing projector-augmented wave methods in `VASP` to enable much faster calculations of the SRH recombination rate. For a more detailed account of the methodology, please see the following reference: {cite:p}`Shen2018`.\n"
"Additional developments have been made to better integrate the methodology with existing projector-augmented wave methods in `VASP` to enable much faster calculations of the SRH recombination rate. For a more detailed account of the methodology, please see the following reference: {cite:p}`Shen2018`.\n"
]
},
{
Expand Down Expand Up @@ -154,25 +154,24 @@
"\n",
"Methods for evaluating electron-phonon interactions in solids from ab initio calculations are well established.\n",
"We use the frozen-phonon method, whereby all the atoms in a supercell are displaced according to the eigenmode of the special phonon. \n",
"The coupling between of the atomic displacements and the electronic properties of the system is represented by the electron-phonon matrix element (epME). \n",
"The coupling between the atomic displacements and the electronic properties of the system is represented by the electron-phonon matrix element (epME). \n",
"The epME of the special phonon (parameterized by Q) is given by:\n",
"\n",
"$$ W_{if} = \\left< \\psi_i \\left| \\frac{\\partial \\hat h}{\\partial Q} \\right| \\psi_f \\right> \n",
"= (\\varepsilon_i - \\varepsilon_f) \\frac{\\left<\\psi_f | \\psi_i({\\delta Q}) \\right>}{\\delta Q}$$\n",
"\n",
"Note the the initial and final states here are determined by the process you are studying.\n",
"Note that the initial and final states here are determined by the process you are studying.\n",
"If you are looking at defect capture, the initial state will be the band edge state and the final state will be the defect state.\n",
"The overlap above is for the all-electron wavefunction, under the PAW formalism in VASP the overlap in the expression above can be expressed using the psuedo-wavefunctions $\\tilde \\psi_{i,f}$ and the overlap operator $\\hat S$:\n",
"\n",
"$$ W_{if} = (\\varepsilon_i - \\varepsilon_f) \\frac{\\left<\\tilde \\psi_f |\\hat S |\\tilde \\psi_i({\\delta Q}) \\right>}{\\delta Q}$$\n",
"\n",
"This expression above can be calculated VASP version 6 and above by copying the `WAVECAR` file from the displaced (δQ) structure into the directory that already contains the relaxed calculations directory as `WAVECAR.QQQ` and then running VASP with `LWSWQ = .TRUE.`.\n",
"This expression above can be calculated with VASP version 6.0 and above by copying the `WAVECAR` file from the displaced (δQ) structure into the directory that already contains the relaxed calculations directory as `WAVECAR.QQQ` and then running VASP with `LWSWQ = .TRUE.`.\n",
"This will calculate the overlap part in the expression above and write it into the `WSWQ` file.\n",
"Automatic parsing of the `WSWQ` file has been implmented in `pymatgen.io.vasp.outputs`.\n",
"The `HarmonicDefect.get_elph_me` method will read a list of `WSWQ` objects and compute the epME via finite difference by calculating the overlap for a series of displacements.\n",
"\n",
"To compute the electron phonon matrix element, we must first populate the `wswq` attribute of the `HarmonicDefect` object by reading the `WSWQ` files from a directory where they have been labeled in `WSWQ.i` where the index `i` is used to sort the `WSWQ` files to help compute the epME via finite difference.\n",
"As an example, we will use the three `WSWQ` files in the generated by the three displaces in `hd0`\n"
"To compute the electron-phonon matrix element, we must first populate the `wswq` attribute of the `HarmonicDefect` object by reading the `WSWQ` files from a directory where they have been labeled in `WSWQ.i` where the index `i` is used to sort the `WSWQ` files to help compute the epME via finite difference.\n",
"As an example, we will use the three `WSWQ` files generated by the three displaces in `hd0`\n"
]
},
{
Expand Down Expand Up @@ -269,12 +268,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
},
"vscode": {
"interpreter": {
"hash": "68485e4e4f6ba0276341f7d764a6dd3a7d31473cb629faa542bbbd38a80276a6"
}
"version": "3.9.16"
}
},
"nbformat": 4,
Expand Down
12 changes: 6 additions & 6 deletions docs/source/content/photo-conduct.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"# Photo Conductivity\n",
"\n",
"When the electronic state of the defect interacts with radiation, carriers can be excited to the conduction band. This is called photoconductivity. To help elucidate how likely a defect is to cause photoconductivity, we can look at the band-decomposed contribution to the frequency-dependent dielectric function.\n",
"Here we have replicated `VASP`'s density-density optical response calculated in the independent-particle picture in the `pymatgen.io.vasp.optics` module, and a allowed users to control which dipole matrix elements are accounted for by masking the dipole matrix elements stored in the `WAVEDER` file and manipulate the Fermi level to populate or depopulate the defect state.\n",
"Here we have replicated `VASP`'s density-density optical response calculated in the independent-particle picture in the `pymatgen.io.vasp.optics` module and allowed users to control which dipole matrix elements are accounted for by masking the dipole matrix elements stored in the `WAVEDER` file and manipulate the Fermi level to populate or depopulate the defect state.\n",
"This essentially allows us to calculate the optical response for (defect)→(conduction band) and (valence band)→(defect) transitions in isolation.\n",
"\n",
"For more information on how `VASP` handles optical response, see the [VASP documentation](https://www.vasp.at/wiki/index.php/LOPTICS).\n",
"\n",
"For more details on how the python code works, please see the documentation for the `pymatgen.io.vasp.optics` module.\n"
"For more details on how the Python code works, please see the documentation for the `pymatgen.io.vasp.optics` module.\n"
]
},
{
Expand Down Expand Up @@ -57,7 +57,7 @@
"metadata": {},
"source": [
"To compute the optical response of a defect we can use the `HarmonicDefect` object again.\n",
"Although this time, since we don't need to consider the vibrational modes of the defect, we only need to pass in the directory containing the relaxed structure and the `WAVEDER` file.\n",
"However, this time, since we don't need to consider the vibrational modes of the defect, we only need to pass in the directory containing the relaxed structure and the `WAVEDER` file.\n",
"Since the `PROCAR` file is also present in the directory, the `(band, kpoint, spin)` indices representing the singular, most localized, state will be automatically determined."
]
},
Expand Down Expand Up @@ -136,7 +136,7 @@
"id": "0f68957d",
"metadata": {},
"source": [
"From the eigenvalues above, we can see that isolated defect band is `[(138, 0, 1), (138, 1, 1)]` which matches with starred values determined by the data from inverse participation ratio (IPR) analysis."
"From the eigenvalues above, we can see that the isolated defect band is `[(138, 0, 1), (138, 1, 1)]` which matches with starred values determined by the data from the inverse participation ratio (IPR) analysis."
]
},
{
Expand Down Expand Up @@ -195,7 +195,7 @@
"source": [
"From the dielectric function above we see that this particular defect (the Ga vacancy in the neutral `q=0` state) is much better at capturing electrons from the valence band via dipole transitions than it is at emitting electrons to the conduction band via dipole transitions.\n",
"\n",
"Of course for a complete picture of photoconductivity, the Frank-Condon type ofr vibrational state transition should also be considered, but we are already pushing the limits of what is acceptable in the independent-particle picture so we will leave that for another time.\n"
"Of course for a complete picture of photoconductivity, the Frank-Condon type of vibrational state transition should also be considered, but we are already pushing the limits of what is acceptable in the independent-particle picture so we will leave that for another time.\n"
]
},
{
Expand All @@ -206,7 +206,7 @@
"## Dipole Matrix Elements\n",
"\n",
"We can also check the dipole matrix elements for the (VBM)→(defect) and (defect)→(CBM) transitions explicitly by calling the `plot_optical_transitions` method as shown below.\n",
"The function returns a summary `pandas.DataFrame` object with the dipole matrix elements as well as the `ListedColormap` and `Normalize` objects for plotting the colorbar. These objects can then be passed to other instances of the plotting function to ensure that the colorbar is consistent."
"The function returns a summary `pandas.DataFrame` object with the dipole matrix elements as well as the `ListedColormap` and `Normalize` objects for plotting the color bar. These objects can then be passed to other instances of the plotting function to ensure that the color bar is consistent."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ strict = [
"scikit-image==0.21.0",
]

tests = ["pytest==7.4.2", "pytest-cov==4.1.0"]
tests = ["pytest==7.4.2", "pytest-cov==4.1.0", "nbmake==1.4.6"]


[tool.setuptools.dynamic]
Expand Down

0 comments on commit 2622c96

Please sign in to comment.