Skip to content

Commit

Permalink
format notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmshn committed Dec 17, 2022
1 parent c388389 commit bddd014
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 39 deletions.
42 changes: 24 additions & 18 deletions tutorials/2-defining-defects.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"outputs": [],
"source": [
"from pathlib import Path\n",
"\n",
"TEST_FILES = Path(\"../tests/test_files\")"
]
},
Expand All @@ -46,11 +47,13 @@
"metadata": {},
"outputs": [],
"source": [
"from pymatgen.analysis.defects.core import Substitution, Vacancy, DefectComplex\n",
"from pymatgen.core import Structure, PeriodicSite, Species\n",
"from pymatgen.analysis.defects.core import DefectComplex, Substitution, Vacancy\n",
"from pymatgen.core import PeriodicSite, Species, Structure\n",
"\n",
"bulk = Structure.from_file(TEST_FILES / \"GaN.vasp\")\n",
"if bulk.lattice == bulk.get_primitive_structure().lattice: # check that you have the primitive structure\n",
"if (\n",
" bulk.lattice == bulk.get_primitive_structure().lattice\n",
"): # check that you have the primitive structure\n",
" print(\"The bulk unit cell is the unique primitive WS cell\")"
]
},
Expand Down Expand Up @@ -119,10 +122,14 @@
"vac_defect1 = Vacancy(structure=bulk, site=n_site0)\n",
"vac_defect2 = Vacancy(structure=bulk, site=n_site1)\n",
"if vac_defect0 != vac_defect1:\n",
" print(f\"The two vacancies {vac_defect0.name} and {vac_defect1.name} are not equivalent.\")\n",
" \n",
" print(\n",
" f\"The two vacancies {vac_defect0.name} and {vac_defect1.name} are not equivalent.\"\n",
" )\n",
"\n",
"if vac_defect2 == vac_defect1:\n",
" print(f\"The two vacancies {vac_defect2.name} and {vac_defect1.name} are equivalent.\")"
" print(\n",
" f\"The two vacancies {vac_defect2.name} and {vac_defect1.name} are equivalent.\"\n",
" )"
]
},
{
Expand All @@ -140,15 +147,9 @@
"metadata": {},
"outputs": [],
"source": [
"def_comp0 = DefectComplex(\n",
" defects=[mg_ga_defect0, vac_defect1]\n",
")\n",
"def_comp1 = DefectComplex(\n",
" defects=[mg_ga_defect1, vac_defect1]\n",
")\n",
"def_comp2 = DefectComplex(\n",
" defects=[mg_ga_defect1, vac_defect2]\n",
")"
"def_comp0 = DefectComplex(defects=[mg_ga_defect0, vac_defect1])\n",
"def_comp1 = DefectComplex(defects=[mg_ga_defect1, vac_defect1])\n",
"def_comp2 = DefectComplex(defects=[mg_ga_defect1, vac_defect2])"
]
},
{
Expand Down Expand Up @@ -202,7 +203,7 @@
"outputs": [],
"source": [
"sc_struct = mg_ga_defect0.get_supercell_structure()\n",
"sc_struct.num_sites\n"
"sc_struct.num_sites"
]
},
{
Expand All @@ -223,11 +224,16 @@
"outputs": [],
"source": [
"sc_struct_smaller = mg_ga_defect0.get_supercell_structure(max_atoms=100)\n",
"sc_struct_smaller.num_sites\n"
"sc_struct_smaller.num_sites"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
Expand All @@ -238,7 +244,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.10.4"
},
"vscode": {
"interpreter": {
Expand Down
55 changes: 34 additions & 21 deletions tutorials/3-nonradiative-capture.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
"outputs": [],
"source": [
"from pathlib import Path\n",
"from pymatgen.analysis.defects.ccd import HarmonicDefect, SRHCapture\n",
"\n",
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"import numpy as np\n"
"from pymatgen.analysis.defects.ccd import HarmonicDefect, SRHCapture"
]
},
{
Expand All @@ -28,7 +29,7 @@
"metadata": {},
"outputs": [],
"source": [
"TEST_FILES = Path(\"../tests/test_files/v_Ga/\")\n"
"TEST_FILES = Path(\"../tests/test_files/v_Ga/\")"
]
},
{
Expand All @@ -52,15 +53,17 @@
"metadata": {},
"outputs": [],
"source": [
"dirs01 = [TEST_FILES / \"ccd_0_-1\" / str(i) for i in [0,1,2]]\n",
"dirs01 = [TEST_FILES / \"ccd_0_-1\" / str(i) for i in [0, 1, 2]]\n",
"hd0 = HarmonicDefect.from_directories(\n",
" directories=dirs01,\n",
" store_bandstructure=True,\n",
")\n",
"print(f\"The relaxed structure is in dirs01[{hd0.relaxed_index}]\")\n",
"print(hd0)\n",
"print(f\"The spin channel ({hd0.spin}) is also automaticalliy determined by the \"\n",
" \"IPR, by taking the spin channel with the lowest average IPR.\")\n"
"print(\n",
" f\"The spin channel ({hd0.spin}) is also automaticalliy determined by the \"\n",
" \"IPR, by taking the spin channel with the lowest average IPR.\"\n",
")"
]
},
{
Expand Down Expand Up @@ -96,12 +99,17 @@
"metadata": {},
"outputs": [],
"source": [
"plt.plot(hd0.distortions, (np.array(hd0.energies) - hd0.energies[hd0.relaxed_index]) * 1000, \"o\", ms=10)\n",
"plt.plot(\n",
" hd0.distortions,\n",
" (np.array(hd0.energies) - hd0.energies[hd0.relaxed_index]) * 1000,\n",
" \"o\",\n",
" ms=10,\n",
")\n",
"xx = np.linspace(-0.2, 0.2, 20)\n",
"yy = 0.5 * hd0.omega**2 * xx ** 2\n",
"plt.plot(xx,yy*1000)\n",
"plt.xlabel(\"Q [amu$^{1/2}$Å]\");\n",
"plt.ylabel(\"Energy [meV]\");\n"
"yy = 0.5 * hd0.omega**2 * xx**2\n",
"plt.plot(xx, yy * 1000)\n",
"plt.xlabel(\"Q [amu$^{1/2}$Å]\")\n",
"plt.ylabel(\"Energy [meV]\");"
]
},
{
Expand All @@ -114,13 +122,13 @@
"outputs": [],
"source": [
"bs = hd0.relaxed_bandstructure\n",
"eigs = bs.bands[hd0.spin][:,1]\n",
"eigs = bs.bands[hd0.spin][:, 1]\n",
"eigs_ref_efermi = eigs\n",
"plt.hlines([eigs_ref_efermi], 0,1)\n",
"plt.hlines(eigs_ref_efermi[hd0.defect_band_index], 0,1, colors=\"red\")\n",
"plt.ylim(bs.efermi-0.1,bs.efermi+2.5)\n",
"plt.xticks([]);\n",
"plt.ylabel(f\"Energy Level Spin:{hd0.spin}\");\n"
"plt.hlines([eigs_ref_efermi], 0, 1)\n",
"plt.hlines(eigs_ref_efermi[hd0.defect_band_index], 0, 1, colors=\"red\")\n",
"plt.ylim(bs.efermi - 0.1, bs.efermi + 2.5)\n",
"plt.xticks([])\n",
"plt.ylabel(f\"Energy Level Spin:{hd0.spin}\");"
]
},
{
Expand Down Expand Up @@ -160,11 +168,11 @@
"outputs": [],
"source": [
"srh = SRHCapture.from_directories(\n",
" initial_dirs=[TEST_FILES / \"ccd_0_-1\" / str(i) for i in [0,1,2]],\n",
" final_dirs=[TEST_FILES / \"ccd_-1_0\" / str(i) for i in [0,1,2]],\n",
" wswq_dir = TEST_FILES / \"ccd_0_-1\" / \"wswqs\",\n",
" initial_dirs=[TEST_FILES / \"ccd_0_-1\" / str(i) for i in [0, 1, 2]],\n",
" final_dirs=[TEST_FILES / \"ccd_-1_0\" / str(i) for i in [0, 1, 2]],\n",
" wswq_dir=TEST_FILES / \"ccd_0_-1\" / \"wswqs\",\n",
" store_bandstructure=True,\n",
")\n"
")"
]
},
{
Expand All @@ -190,6 +198,11 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "mp",
"language": "python",
"name": "mp"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
Expand Down

0 comments on commit bddd014

Please sign in to comment.