From 7fe960b0fb96440ae8b328e88e325995983806a1 Mon Sep 17 00:00:00 2001 From: wolearyc Date: Sat, 10 Aug 2024 16:41:41 -0700 Subject: [PATCH] added DOF warnings --- ramannoodle/exceptions.py | 7 +++++++ ramannoodle/polarizability/interpolation.py | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ramannoodle/exceptions.py b/ramannoodle/exceptions.py index d87a5c6..3a93871 100644 --- a/ramannoodle/exceptions.py +++ b/ramannoodle/exceptions.py @@ -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.""" diff --git a/ramannoodle/polarizability/interpolation.py b/ramannoodle/polarizability/interpolation.py index f4c6ff4..1971679 100644 --- a/ramannoodle/polarizability/interpolation.py +++ b/ramannoodle/polarizability/interpolation.py @@ -6,6 +6,7 @@ from pathlib import Path import copy +from warnings import warn import numpy as np from numpy.typing import NDArray @@ -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( @@ -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 "