Skip to content

Commit

Permalink
added DOF warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
wolearyc committed Aug 10, 2024
1 parent 1c48ca2 commit 7fe960b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ramannoodle/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def __init__(self, reason: str):
pass


class DOFWarning(UserWarning):
"""Used when something may be wrong with a DOF."""

def __init__(self, reason: str):
pass


class SymmetryException(Exception):
"""Raised when something goes wrong with an operation involving symmetry."""

Expand Down
17 changes: 16 additions & 1 deletion ramannoodle/polarizability/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from pathlib import Path
import copy
from warnings import warn

import numpy as np
from numpy.typing import NDArray
Expand All @@ -24,7 +25,7 @@

from .. import io
from ..io.io_utils import pathify_as_list
from ..exceptions import verify_ndarray_shape
from ..exceptions import verify_ndarray_shape, DOFWarning


def get_amplitude(
Expand Down Expand Up @@ -215,6 +216,20 @@ def _construct_and_add_interpolations(
f"due to symmetry, amplitude {duplicate} should not be specified"
)

# Warn user if amplitudes don't span zero
max_amplitude = np.max(interpolation_x)
min_amplitude = np.min(interpolation_x)
if np.isclose(max_amplitude, 0, atol=1e-3).all() or max_amplitude <= 0:
warn(
"max amplitude <= 0, when usually it should be > 0",
DOFWarning,
)
if np.isclose(min_amplitude, 0, atol=1e-3).all() or min_amplitude >= 0:
warn(
"min amplitude >= 0, when usually it should be < 0",
DOFWarning,
)

if len(interpolation_x) <= interpolation_order:
raise InvalidDOFException(
f"insufficient points ({len(interpolation_x)}) available for "
Expand Down

0 comments on commit 7fe960b

Please sign in to comment.