Skip to content

Commit

Permalink
equilibrium_polarizability -> ref_polarizability
Browse files Browse the repository at this point in the history
  • Loading branch information
wolearyc committed Aug 31, 2024
1 parent 9bb180a commit 70fe3f8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 39 deletions.
8 changes: 4 additions & 4 deletions docs/source/notebooks/Masking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@
"from ramannoodle.polarizability.art import ARTModel\n",
"\n",
"data_dir = \"../../../test/data/TiO2\"\n",
"# phonon_OUTCAR contains phonons (duh) as well as the equilibrium TiO2 structure.\n",
"# phonon_OUTCAR contains phonons (duh) as well as the reference TiO2 structure.\n",
"phonon_outcar = f\"{data_dir}/phonons_OUTCAR\"\n",
"\n",
"# Read the phonons\n",
"phonons = vasp_io.outcar.read_phonons(phonon_outcar)\n",
"# Read the reference structure. This might take a few moments...\n",
"ref_structure = vasp_io.outcar.read_ref_structure(f\"{data_dir}/ref_eps_OUTCAR\")\n",
"\n",
"# We'll need the polarizability of the equilibrium structure. \n",
"_, equilibrium_polarizability = vasp_io.outcar.read_positions_and_polarizability(\n",
"# We'll need the polarizability of the reference structure. \n",
"_, ref_polarizability = vasp_io.outcar.read_positions_and_polarizability(\n",
" f\"{data_dir}/ref_eps_OUTCAR\"\n",
")\n",
"model = ARTModel(ref_structure, equilibrium_polarizability)"
"model = ARTModel(ref_structure, ref_polarizability)"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions docs/source/notebooks/basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@
"source": [
"from ramannoodle.polarizability.interpolation import InterpolationModel\n",
"\n",
"# Read a reference (equilibrium) structure.\n",
"# Read a reference (minimum) structure.\n",
"ref_structure = vasp_io.outcar.read_ref_structure(f\"{data_dir}/ref_eps_OUTCAR\")\n",
"\n",
"# We'll need the polarizability of the equilibrium structure. \n",
"_, equilibrium_polarizability = vasp_io.outcar.read_positions_and_polarizability(\n",
"# We'll need the polarizability of the minimum structure. \n",
"_, ref_polarizability = vasp_io.outcar.read_positions_and_polarizability(\n",
" f\"{data_dir}/ref_eps_OUTCAR\"\n",
")\n",
"model = InterpolationModel(ref_structure, equilibrium_polarizability)\n",
"model = InterpolationModel(ref_structure, ref_polarizability)\n",
"\n",
"# Using __repr__, we can check out model.\n",
"model"
Expand Down
8 changes: 4 additions & 4 deletions docs/source/notebooks/full-workflow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"id": "c6831e95",
"metadata": {},
"source": [
"Now that we have the reference structure, we can initialize the polarizability model. We do this the usual way, but we specify `is_dummy_model = True`. Because this is a dummy model, the value for `equilibrium_polarizability` is completely ignored. We simply set it to ``np.zeros((3,3))``. "
"Now that we have the reference structure, we can initialize the polarizability model. We do this the usual way, but we specify `is_dummy_model = True`. Because this is a dummy model, the value for `ref_polarizability` is completely ignored. We simply set it to ``np.zeros((3,3))``. "
]
},
{
Expand All @@ -92,7 +92,7 @@
"from ramannoodle.polarizability.art import ARTModel\n",
"\n",
"model = ARTModel(ref_structure=ref_structure, \n",
" equilibrium_polarizability = np.zeros((3,3)), \n",
" ref_polarizability = np.zeros((3,3)), \n",
" is_dummy_model=True) \n",
"model"
]
Expand Down Expand Up @@ -251,11 +251,11 @@
"metadata": {},
"outputs": [],
"source": [
"_, equilibrium_polarizability = vasp_io.outcar.read_positions_and_polarizability(\n",
"_, ref_polarizability = vasp_io.outcar.read_positions_and_polarizability(\n",
" f\"{data_dir}/ref_eps_OUTCAR\"\n",
")\n",
"model = ARTModel(ref_structure=ref_structure, \n",
" equilibrium_polarizability = equilibrium_polarizability) \n",
" ref_polarizability = ref_polarizability) \n",
"\n",
"model.add_art_from_files(\n",
" [f\"{data_dir}/Ti5_0.1x_eps_OUTCAR\"], file_format = 'outcar'\n",
Expand Down
6 changes: 3 additions & 3 deletions docs/source/notebooks/molecular-dynamics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@
"data_dir = \"../../../test/data/TiO2\"\n",
"ref_structure = vasp_io.poscar.read_ref_structure(f\"{data_dir}/POSCAR\")\n",
"\n",
"# We'll need the polarizability of the equilibrium structure. \n",
"_, equilibrium_polarizability = vasp_io.outcar.read_positions_and_polarizability(\n",
"# We'll need the polarizability of the reference structure. \n",
"_, ref_polarizability = vasp_io.outcar.read_positions_and_polarizability(\n",
" f\"{data_dir}/ref_eps_OUTCAR\"\n",
")\n",
"model = InterpolationModel(ref_structure, equilibrium_polarizability)\n",
"model = InterpolationModel(ref_structure, ref_polarizability)\n",
"\n",
"# OUTCARS are polarizability calculation where atom 5 (Ti) \n",
"# was displaced +0.1 and +0.2 angstrom in the x direction\n",
Expand Down
8 changes: 4 additions & 4 deletions ramannoodle/polarizability/art.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ class ARTModel(InterpolationModel):
:meth:`add_art_from_files`.
.. warning::
Due to the way ARTModel is implemented, the predicted tensor of the equilibrium
Due to the way ARTModel is implemented, the predicted tensor of the reference
structure may be offset slightly. This is a fixed offset and therefore has no
influence on Raman spectra calculations.
Parameters
----------
ref_structure
| Reference structure on which to base the model.
equilibrium_polarizability
ref_polarizability
| 2D array with shape (3,3) giving polarizability of the reference structure.
is_dummy_model
Expand All @@ -78,7 +78,7 @@ def add_dof( # pylint: disable=too-many-arguments
amplitudes: NDArray[np.float64],
polarizabilities: NDArray[np.float64],
interpolation_order: int,
include_equilibrium_polarizability: bool = True,
include_ref_polarizability: bool = True,
) -> None:
"""Disable add_dof.
Expand Down Expand Up @@ -171,7 +171,7 @@ def add_art(
amplitudes,
polarizabilities,
1,
include_equilibrium_polarizability=False,
include_ref_polarizability=False,
)

def add_art_from_files(
Expand Down
36 changes: 16 additions & 20 deletions ramannoodle/polarizability/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class InterpolationModel(PolarizabilityModel):
----------
ref_structure
| Reference structure on which to base the model.
equilibrium_polarizability
ref_polarizability
| 2D array with shape (3,3) with polarizability of the reference structure.
is_dummy_model
Expand All @@ -91,17 +91,15 @@ class InterpolationModel(PolarizabilityModel):
def __init__(
self,
ref_structure: ReferenceStructure,
equilibrium_polarizability: NDArray[np.float64],
ref_polarizability: NDArray[np.float64],
is_dummy_model: bool = False,
) -> None:
if is_dummy_model:
equilibrium_polarizability = np.zeros((3, 3))
verify_ndarray_shape(
"equilibrium_polarizability", equilibrium_polarizability, (3, 3)
)
ref_polarizability = np.zeros((3, 3))
verify_ndarray_shape("ref_polarizability", ref_polarizability, (3, 3))

self._ref_structure = ref_structure
self._equilibrium_polarizability = equilibrium_polarizability
self._ref_polarizability = ref_polarizability
self._is_dummy_model = is_dummy_model
self._cart_basis_vectors: list[NDArray[np.float64]] = []
self._interpolations: list[BSpline] = []
Expand All @@ -113,15 +111,15 @@ def ref_structure(self) -> ReferenceStructure:
return copy.deepcopy(self._ref_structure)

@property
def equilibrium_polarizability(self) -> NDArray[np.float64]:
"""Get (a copy of) equilibrium polarizability.
def ref_polarizability(self) -> NDArray[np.float64]:
"""Get (a copy of) reference polarizability.
Returns
-------
:
2D array with shape (3,3).
"""
return self._equilibrium_polarizability.copy()
return self._ref_polarizability.copy()

@property
def is_dummy_model(self) -> bool:
Expand Down Expand Up @@ -244,14 +242,14 @@ def calc_polarizabilities(
) from err
raise err

return delta_polarizabilities + self._equilibrium_polarizability
return delta_polarizabilities + self._ref_polarizability

def _get_dof( # pylint: disable=too-many-locals
self,
parent_displacement: NDArray[np.float64],
amplitudes: NDArray[np.float64],
polarizabilities: NDArray[np.float64],
include_equilibrium_polarizability: bool,
include_ref_polarizability: bool,
) -> tuple[
list[NDArray[np.float64]], list[list[float]], list[list[NDArray[np.float64]]]
]:
Expand Down Expand Up @@ -300,7 +298,7 @@ def _get_dof( # pylint: disable=too-many-locals

interpolation_x: list[float] = []
interpolation_y: list[NDArray[np.float64]] = []
if include_equilibrium_polarizability:
if include_ref_polarizability:
interpolation_x.append(0.0)
interpolation_y.append(np.zeros((3, 3)))

Expand All @@ -315,9 +313,7 @@ def _get_dof( # pylint: disable=too-many-locals
for amplitude, polarizability in zip(amplitudes, polarizabilities):
interpolation_x.append(multiplier * amplitude)
rotation = transformation[0]
delta_polarizability = (
polarizability - self._equilibrium_polarizability
)
delta_polarizability = polarizability - self._ref_polarizability

interpolation_y.append(
(np.linalg.inv(rotation) @ delta_polarizability @ rotation)
Expand Down Expand Up @@ -405,7 +401,7 @@ def add_dof( # pylint: disable=too-many-arguments
amplitudes: NDArray[np.float64],
polarizabilities: NDArray[np.float64],
interpolation_order: int,
include_equilibrium_polarizability: bool = True,
include_ref_polarizability: bool = True,
) -> None:
"""Add a degree of freedom (DOF).
Expand Down Expand Up @@ -434,8 +430,8 @@ def add_dof( # pylint: disable=too-many-arguments
interpolation_order
| Must be less than the number of total number of amplitudes after
| symmetry considerations.
include_equilibrium_polarizability
| Whether to include the equilibrium polarizability at 0.0 amplitude in the
include_ref_polarizability
| Whether to include the references polarizability at 0.0 amplitude in the
| interpolation.
Raises
Expand All @@ -462,7 +458,7 @@ def add_dof( # pylint: disable=too-many-arguments
parent_displacement,
amplitudes,
polarizabilities,
include_equilibrium_polarizability,
include_ref_polarizability,
)

# Then append the DOF - checks amplitudes (in form of interpolation_xs)
Expand Down

0 comments on commit 70fe3f8

Please sign in to comment.