From 8487d70314d5d3d9a342037e6984f56270195edf Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:23:49 -0700 Subject: [PATCH] update: 1% difference --- src/py/mat3ra/made/tools/utils/perturbation.py | 9 +++------ tests/py/unit/test_tools_build_perturbation.py | 6 +++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/py/mat3ra/made/tools/utils/perturbation.py b/src/py/mat3ra/made/tools/utils/perturbation.py index ebb6f99c..c06a0bb3 100644 --- a/src/py/mat3ra/made/tools/utils/perturbation.py +++ b/src/py/mat3ra/made/tools/utils/perturbation.py @@ -117,7 +117,8 @@ def __init__( axis: str = "x", **data: Any, ): - function = self._create_function(amplitude, wavelength, phase, axis) + w = sp.Symbol(axis) + function = amplitude * sp.sin(2 * sp.pi * w / wavelength + phase) variables = [axis] super().__init__(function=function, variables=variables, **data) self.amplitude = amplitude @@ -125,14 +126,10 @@ def __init__( self.phase = phase self.axis = axis - def _create_function(self, amplitude: float, wavelength: float, phase: float, axis: str) -> sp.Expr: - w = sp.Symbol(axis) - return amplitude * sp.sin(2 * sp.pi * w / wavelength + phase) - def get_json(self) -> dict: return { "type": self.__class__.__name__, - "function": str(self.function), + "function": "sine_wave", "variables": self.variables, "amplitude": self.amplitude, "wavelength": self.wavelength, diff --git a/tests/py/unit/test_tools_build_perturbation.py b/tests/py/unit/test_tools_build_perturbation.py index 86232a5d..7997391d 100644 --- a/tests/py/unit/test_tools_build_perturbation.py +++ b/tests/py/unit/test_tools_build_perturbation.py @@ -39,12 +39,12 @@ def test_distance_preserved_sine_perturbation(): # Check selected atoms to avoid using 100+ atoms fixture assertion_utils.assert_deep_almost_equal([0.0, 0.0, 0.5], perturbed_slab.basis.coordinates.values[0]) assertion_utils.assert_deep_almost_equal( - [0.201132951, 0.1, 0.546942315], perturbed_slab.basis.coordinates.values[42] + [0.197552693, 0.1, 0.546942315], perturbed_slab.basis.coordinates.values[42] ) # Value taken from visually inspected notebook expected_cell = Cell( - vector1=[23.517094, 0.0, 0.0], - vector2=[-11.758818, 21.367367, 0.0], + vector1=[24.087442, 0.0, 0.0], + vector2=[-12.043583, 21.367367, 0.0], vector3=[0.0, 0.0, 20.0], ) assertion_utils.assert_deep_almost_equal(expected_cell.vectors_as_array, perturbed_slab.basis.cell.vectors_as_array)