Skip to content

Commit

Permalink
update: 1% difference
Browse files Browse the repository at this point in the history
  • Loading branch information
VsevolodX committed Aug 13, 2024
1 parent 714c988 commit 8487d70
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
9 changes: 3 additions & 6 deletions src/py/mat3ra/made/tools/utils/perturbation.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,19 @@ 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
self.wavelength = wavelength
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,
Expand Down
6 changes: 3 additions & 3 deletions tests/py/unit/test_tools_build_perturbation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 8487d70

Please sign in to comment.