Skip to content

Commit

Permalink
added black notebook formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
wolearyc committed Oct 11, 2024
1 parent 6eb2960 commit 3b4145c
Show file tree
Hide file tree
Showing 9 changed files with 875 additions and 309 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ repos:
rev: 24.8.0
hooks:
- id: black
- id: black-jupyter
- repo: local
hooks:
- id: pylint
Expand Down
493 changes: 493 additions & 0 deletions basics.ipynb

Large diffs are not rendered by default.

43 changes: 22 additions & 21 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Sphinx conf.py."""

# pylint: skip-file
# flake-8: noqa
# cspell: disable
Expand All @@ -13,52 +14,52 @@
import sys
import os

project = 'ramannoodle'
project = "ramannoodle"
copyright = "2023-present, Willis O'Leary"
author = "Willis O'Leary"
release = '0.5.0'
release = "0.5.0"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.intersphinx',
'sphinx.ext.napoleon',
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
"sphinx_autodoc_typehints",
'nbsphinx',
'IPython.sphinxext.ipython_console_highlighting',
"nbsphinx",
"IPython.sphinxext.ipython_console_highlighting",
]
autodoc_typehints = 'description'
autodoc_typehints = "description"
nbsphinx_allow_errors = True

intersphinx_mapping = {
'python': ('https://docs.python.org/3/', None),
'numpy': ('http://docs.scipy.org/doc/numpy', None),
'scipy': ('http://docs.scipy.org/doc/scipy/reference', None),
'torch': ('https://pytorch.org/docs/stable/', None),
'pymatgen': ('https://pymatgen.org', None),
"python": ("https://docs.python.org/3/", None),
"numpy": ("http://docs.scipy.org/doc/numpy", None),
"scipy": ("http://docs.scipy.org/doc/scipy/reference", None),
"torch": ("https://pytorch.org/docs/stable/", None),
"pymatgen": ("https://pymatgen.org", None),
}

intersphinx_disabled_domains = ['std']
intersphinx_disabled_domains = ["std"]

templates_path = ['_templates']
templates_path = ["_templates"]
exclude_patterns = []

autodoc_member_order = 'groupwise'
autodoc_member_order = "groupwise"

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'furo'
html_title = 'ramannoodle'
html_static_path = ['_static']
html_theme = "furo"
html_title = "ramannoodle"
html_static_path = ["_static"]
html_theme_options = {
"light_logo": "logo.png",
"dark_logo": "logo_dark.png",
"sidebar_hide_name": True,
}
html_extra_path = ["robots.txt"]

sys.path.insert(0, os.path.abspath('../../'))
sys.path.insert(0, os.path.abspath("../../"))
135 changes: 77 additions & 58 deletions docs/source/notebooks/basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
"from matplotlib import pyplot as plt\n",
"import matplotlib_inline\n",
"\n",
"matplotlib_inline.backend_inline.set_matplotlib_formats('png')\n",
"plt.rcParams['figure.dpi'] = 300\n",
"plt.rcParams['font.family'] = 'sans-serif'\n",
"plt.rcParams[\"mathtext.default\"] = 'regular'\n",
"plt.rcParams['axes.linewidth'] = 0.5\n",
"plt.rcParams['xtick.major.width'] = 0.5\n",
"plt.rcParams['xtick.minor.width'] = 0.5\n",
"plt.rcParams['lines.linewidth'] = 1.5\n",
"matplotlib_inline.backend_inline.set_matplotlib_formats(\"png\")\n",
"plt.rcParams[\"figure.dpi\"] = 300\n",
"plt.rcParams[\"font.family\"] = \"sans-serif\"\n",
"plt.rcParams[\"mathtext.default\"] = \"regular\"\n",
"plt.rcParams[\"axes.linewidth\"] = 0.5\n",
"plt.rcParams[\"xtick.major.width\"] = 0.5\n",
"plt.rcParams[\"xtick.minor.width\"] = 0.5\n",
"plt.rcParams[\"lines.linewidth\"] = 1.5\n",
"\n",
"import ramannoodle as rn"
]
Expand Down Expand Up @@ -93,13 +93,12 @@
}
],
"source": [
"\n",
"# Read a reference (minimum) structure.\n",
"ref_structure = rn.io.vasp.outcar.read_ref_structure(f\"{data_dir}/ref_eps_OUTCAR\")\n",
"\n",
"# We'll need the polarizability of the minimum structure. \n",
"# We'll need the polarizability of the minimum structure.\n",
"_, ref_polarizability = rn.io.vasp.outcar.read_positions_and_polarizability(\n",
" f\"{data_dir}/ref_eps_OUTCAR\"\n",
" f\"{data_dir}/ref_eps_OUTCAR\"\n",
")\n",
"model = rn.pmodel.InterpolationModel(ref_structure, ref_polarizability)\n",
"\n",
Expand Down Expand Up @@ -143,11 +142,12 @@
}
],
"source": [
"# OUTCARS are polarizability calculation where atom 5 (Ti) \n",
"# OUTCARS are polarizability calculation where atom 5 (Ti)\n",
"# was displaced +0.1 and +0.2 angstrom in the x direction\n",
"model.add_dof_from_files(\n",
" [f\"{data_dir}/Ti5_0.1x_eps_OUTCAR\", f\"{data_dir}/Ti5_0.2x_eps_OUTCAR\"],\n",
" file_format = 'outcar', interpolation_order=2\n",
" file_format=\"outcar\",\n",
" interpolation_order=2,\n",
")\n",
"\n",
"# (36 equivalent Ti atoms) * (2 equivalent directions) --> 72 dofs should be added\n",
Expand Down Expand Up @@ -181,9 +181,11 @@
],
"source": [
"# atom 5 moving +0.1 and +0.2 angstroms in the z direction\n",
"model.add_dof_from_files([f\"{data_dir}/Ti5_0.1z_eps_OUTCAR\",\n",
" f\"{data_dir}/Ti5_0.2z_eps_OUTCAR\"],\n",
" file_format = 'outcar', interpolation_order=2)\n",
"model.add_dof_from_files(\n",
" [f\"{data_dir}/Ti5_0.1z_eps_OUTCAR\", f\"{data_dir}/Ti5_0.2z_eps_OUTCAR\"],\n",
" file_format=\"outcar\",\n",
" interpolation_order=2,\n",
")\n",
"\n",
"# (36 equivalent Ti atoms) * (1 equivalent direction) --> another 36 DOFs\n",
"model"
Expand Down Expand Up @@ -216,11 +218,17 @@
],
"source": [
"# atom 43 moving in the z direction\n",
"# Convince yourself that we need all of these displacements. \n",
"model.add_dof_from_files([f\"{data_dir}/O43_0.2z_eps_OUTCAR\",\n",
" f\"{data_dir}/O43_0.1z_eps_OUTCAR\", \n",
" f\"{data_dir}/O43_m0.1z_eps_OUTCAR\", \n",
" f\"{data_dir}/O43_m0.2z_eps_OUTCAR\"], file_format= 'outcar', interpolation_order=2)\n",
"# Convince yourself that we need all of these displacements.\n",
"model.add_dof_from_files(\n",
" [\n",
" f\"{data_dir}/O43_0.2z_eps_OUTCAR\",\n",
" f\"{data_dir}/O43_0.1z_eps_OUTCAR\",\n",
" f\"{data_dir}/O43_m0.1z_eps_OUTCAR\",\n",
" f\"{data_dir}/O43_m0.2z_eps_OUTCAR\",\n",
" ],\n",
" file_format=\"outcar\",\n",
" interpolation_order=2,\n",
")\n",
"\n",
"model"
]
Expand All @@ -243,9 +251,11 @@
}
],
"source": [
"model.add_dof_from_files([f\"{data_dir}/O43_0.1x_eps_OUTCAR\",\n",
" f\"{data_dir}/O43_0.2x_eps_OUTCAR\"], \n",
" file_format = 'outcar', interpolation_order=2)\n",
"model.add_dof_from_files(\n",
" [f\"{data_dir}/O43_0.1x_eps_OUTCAR\", f\"{data_dir}/O43_0.2x_eps_OUTCAR\"],\n",
" file_format=\"outcar\",\n",
" interpolation_order=2,\n",
")\n",
"\n",
"model"
]
Expand All @@ -268,9 +278,11 @@
}
],
"source": [
"model.add_dof_from_files([f\"{data_dir}/O43_0.1y_eps_OUTCAR\",\n",
" f\"{data_dir}/O43_0.2y_eps_OUTCAR\"],\n",
" file_format = 'outcar', interpolation_order=2)\n",
"model.add_dof_from_files(\n",
" [f\"{data_dir}/O43_0.1y_eps_OUTCAR\", f\"{data_dir}/O43_0.2y_eps_OUTCAR\"],\n",
" file_format=\"outcar\",\n",
" interpolation_order=2,\n",
")\n",
"\n",
"# We should now have specified all 324 DOFs\n",
"model"
Expand Down Expand Up @@ -306,19 +318,19 @@
}
],
"source": [
"atom_number = 5 # Feel free to change this!\n",
"atom_number = 5 # Feel free to change this!\n",
"\n",
"fig = plt.figure(constrained_layout = True, figsize = (8, 2))\n",
"gs = fig.add_gridspec(1,6, wspace=0)\n",
"fig = plt.figure(constrained_layout=True, figsize=(8, 2))\n",
"gs = fig.add_gridspec(1, 6, wspace=0)\n",
"axes = gs.subplots(sharex=True, sharey=True)\n",
"interp_displacements = np.linspace(-0.21,0.21,50)\n",
"interp_displacements = np.linspace(-0.21, 0.21, 50)\n",
"\n",
"target_interps = []\n",
"signs = []\n",
"for direction_i in [0,1,2]:\n",
"for direction_i in [0, 1, 2]:\n",
" basis_vector = model.cart_basis_vectors[0] * 0\n",
" basis_vector[atom_number-1][direction_i] = 1\n",
" for basis, interp in zip(model.cart_basis_vectors,model._interpolations):\n",
" basis_vector[atom_number - 1][direction_i] = 1\n",
" for basis, interp in zip(model.cart_basis_vectors, model._interpolations):\n",
" if np.dot(basis.flatten(), basis_vector.flatten()) < -0.9:\n",
" target_interps.append(interp)\n",
" signs.append(-1)\n",
Expand All @@ -327,23 +339,26 @@
" signs.append(1)\n",
"\n",
"\n",
"for axis_i, (i,j) in enumerate([(0,0),(1,1),(2,2),(0,1),(0,2),(1,2)]):\n",
" axis = axes[axis_i] # type: ignore\n",
" colors = ['purple', 'red', 'orange']\n",
" labels = ['x','y','z']\n",
"for axis_i, (i, j) in enumerate([(0, 0), (1, 1), (2, 2), (0, 1), (0, 2), (1, 2)]):\n",
" axis = axes[axis_i] # type: ignore\n",
" colors = [\"purple\", \"red\", \"orange\"]\n",
" labels = [\"x\", \"y\", \"z\"]\n",
"\n",
" for interp,sign,color,label in zip(target_interps,signs,colors,labels):\n",
" axis.plot(interp_displacements, \n",
" interp(sign*interp_displacements)[:,i,j], color = color, label = label)\n",
" for interp, sign, color, label in zip(target_interps, signs, colors, labels):\n",
" axis.plot(\n",
" interp_displacements,\n",
" interp(sign * interp_displacements)[:, i, j],\n",
" color=color,\n",
" label=label,\n",
" )\n",
" axis.set_xlabel(r\"$\\delta$ (Å)\")\n",
" subscripts = ['x','y','z']\n",
" subscripts = [\"x\", \"y\", \"z\"]\n",
" alpha_string = r\"$\\alpha_{\" + subscripts[i] + subscripts[j] + \"}$\"\n",
" axis.set_title(alpha_string)\n",
" if axis_i == 0:\n",
" l = axis.legend(fontsize = \"small\", frameon = False)\n",
" \n",
"l = axes[0].set_ylabel(r\"$\\Delta\\alpha$\")\n",
" "
" l = axis.legend(fontsize=\"small\", frameon=False)\n",
"\n",
"l = axes[0].set_ylabel(r\"$\\Delta\\alpha$\")"
]
},
{
Expand Down Expand Up @@ -382,11 +397,13 @@
"source": [
"# Compute and plot spectrum\n",
"spectrum = phonons.get_raman_spectrum(model)\n",
"wavenumbers, intensities = spectrum.measure(laser_correction = True, \n",
" laser_wavelength = 532, \n",
" bose_einstein_correction = True, \n",
" temperature = 300)\n",
"fig = plt.figure(constrained_layout = True, figsize = (8, 3))\n",
"wavenumbers, intensities = spectrum.measure(\n",
" laser_correction=True,\n",
" laser_wavelength=532,\n",
" bose_einstein_correction=True,\n",
" temperature=300,\n",
")\n",
"fig = plt.figure(constrained_layout=True, figsize=(8, 3))\n",
"axis = fig.add_subplot(111)\n",
"axis.plot(wavenumbers, intensities)\n",
"axis.set_ylabel(\"Intensity (a.u.)\")\n",
Expand Down Expand Up @@ -419,18 +436,20 @@
}
],
"source": [
"# Let's make it prettier. \n",
"wavenumbers, intensities = spectrum.measure(laser_correction = True, \n",
" laser_wavelength = 532, \n",
" bose_einstein_correction = True, \n",
" temperature = 300)\n",
"# Let's make it prettier.\n",
"wavenumbers, intensities = spectrum.measure(\n",
" laser_correction=True,\n",
" laser_wavelength=532,\n",
" bose_einstein_correction=True,\n",
" temperature=300,\n",
")\n",
"wavenumbers, intensities = rn.spectrum.utils.convolve_spectrum(wavenumbers, intensities)\n",
"\n",
"fig = plt.figure(constrained_layout = True, figsize = (8, 3))\n",
"fig = plt.figure(constrained_layout=True, figsize=(8, 3))\n",
"axis = fig.add_subplot(111)\n",
"axis.plot(wavenumbers, intensities)\n",
"axis.set_ylabel(\"Intensity (a.u.)\")\n",
"l = axis.set_xlabel(r\"Raman shift ($\\mathregular{cm^{-1}}$)\")\n"
"l = axis.set_xlabel(r\"Raman shift ($\\mathregular{cm^{-1}}$)\")"
]
},
{
Expand Down
Loading

0 comments on commit 3b4145c

Please sign in to comment.