Skip to content

Commit

Permalink
fixed polarizability transform, added test
Browse files Browse the repository at this point in the history
  • Loading branch information
wolearyc committed Aug 3, 2024
1 parent 15af2f8 commit 8ec70c3
Show file tree
Hide file tree
Showing 14 changed files with 80,430 additions and 34 deletions.
21 changes: 10 additions & 11 deletions ramannoodle/polarizability/interpolation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ class InterpolationPolarizabilityModel(PolarizabilityModel):
2D array with shape (3,3) giving polarizability of system at equilibrium. This
would usually correspond to the minimum energy structure.
Raman spectra calculated using this model do not explicitly depend on this
value. However, specifying the actual value is recommended in order to
compute the correct polarizability magnitudes.
"""

def __init__(
Expand Down Expand Up @@ -80,14 +76,14 @@ def get_polarizability(
:
2D array with shape (3,3)
"""
polarizability: NDArray[np.float64] = np.zeros((3, 3))
delta_polarizability: NDArray[np.float64] = np.zeros((3, 3))
for basis_vector, interpolation in zip(
self._cartesian_basis_vectors, self._interpolations
):
amplitude = np.dot(basis_vector.flatten(), cartesian_displacement.flatten())
polarizability += interpolation(amplitude)
delta_polarizability += interpolation(amplitude)

return polarizability + self._equilibrium_polarizability
return delta_polarizability + self._equilibrium_polarizability

def add_dof( # pylint: disable=too-many-locals
self,
Expand Down Expand Up @@ -149,8 +145,8 @@ def add_dof( # pylint: disable=too-many-locals
for dof_dictionary in displacements_and_transformations:
child_displacement = dof_dictionary["displacements"][0]

interpolation_x = []
interpolation_y = []
interpolation_x = [0.0]
interpolation_y = [np.zeros((3, 3))]
for collinear_displacement, transformation in zip(
dof_dictionary["displacements"], dof_dictionary["transformations"]
):
Expand All @@ -162,9 +158,12 @@ def add_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
)

interpolation_y.append(
(rotation @ polarizability @ np.linalg.inv(rotation))
- self._equilibrium_polarizability
(np.linalg.inv(rotation) @ delta_polarizability @ rotation)
)

# If duplicate amplitudes are generated, too much data has
Expand Down
2 changes: 1 addition & 1 deletion ramannoodle/symmetry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def get_equivalent_displacements(
self._rotations, self._translations, self._permutation_matrices
):

# Transform, permute, then get displacements
# Transform, permute, then get candidate displacement
candidate_positions = symmetry_utils.transform_fractional_positions(
ref_positions, rotation, translation
)
Expand Down
11 changes: 10 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import pytest
from pytest import FixtureRequest

from ramannoodle.symmetry import StructuralSymmetry
from ramannoodle import io


@pytest.fixture
def outcar_path_fixture(request: FixtureRequest) -> Path:
Expand All @@ -16,11 +19,17 @@ def outcar_path_fixture(request: FixtureRequest) -> Path:

@pytest.fixture
def outcar_file_fixture(
request: FixtureRequest, # pylint: disable = redefined-outer-name
request: FixtureRequest,
) -> Generator[TextIO, None, None]:
"""Return an outcar file."""
file = open( # pylint: disable=consider-using-with
Path(request.param), "r", encoding="utf-8"
)
yield file
file.close()


@pytest.fixture
def outcar_symmetry_fixture(request: FixtureRequest) -> StructuralSymmetry:
"""Return a structural symmetry."""
return io.read_structural_symmetry(request.param, file_format="outcar")
Loading

0 comments on commit 8ec70c3

Please sign in to comment.