From 9e9c865cf9c6fd212fd7cefd9b311a5b21249f99 Mon Sep 17 00:00:00 2001 From: Sebastian Kloth Date: Wed, 10 Jan 2024 12:41:18 +0100 Subject: [PATCH] Adjusted tests --- test/test_free_energy_landscape.py | 68 +++++++++++++++--------------- test/test_utils.py | 13 ------ 2 files changed, 34 insertions(+), 47 deletions(-) diff --git a/test/test_free_energy_landscape.py b/test/test_free_energy_landscape.py index 44b131f..9835b23 100644 --- a/test/test_free_energy_landscape.py +++ b/test/test_free_energy_landscape.py @@ -4,7 +4,7 @@ import pytest import numpy as np import mdevaluate -from mdevaluate import free_energy_landscape as fel +import mdevaluate.extra.free_energy_landscape as fel @pytest.fixture @@ -15,40 +15,40 @@ def trajectory(request): def test_get_fel(trajectory): test_array = np.array( [ - 0.0, - 12.87438176, - 4.95868203, - 11.02055197, - 5.44195534, - 6.73933442, - 3.30971789, - 6.10424055, - 8.56153733, - 5.45777331, - 5.64545817, - 8.42100423, - 6.28132121, - 7.4777172, - 11.64839354, - 4.52566354, - 40.84730838, - 93.86241602, - 140.3039937, - 173.55970021, + 174.46253634, + 174.60905476, + 178.57658092, + 182.43001192, + 180.57916378, + 176.49886217, + 178.96018547, + 181.13561782, + 178.31026314, + 176.08903996, + 180.71215345, + 181.59703135, + 180.34329368, + 187.02474488, + 197.99167477, + 214.05788031, + 245.58571282, + 287.52457507, + 331.53492965, ] ) - oxygens_water = trajectory.subset(atom_name="OW", residue_name="SOL") - r, energy_differences = fel.get_fel( - oxygens_water, - os.path.join(os.path.dirname(__file__), "data/pore"), - "cylindrical", - 225, - edge=0.05, - radiusmin=0.05, - radiusmax=2.05, - z=[-np.inf, np.inf], - overwrite=True, - ) + OW = trajectory.subset(atom_name="OW") - assert (np.round(energy_differences) == np.round(test_array)).all() + box = np.diag(trajectory[0].box) + box_voxels = (box // [0.05, 0.05, 0.05] + [1, 1, 1]) * [0.05, 0.05, 0.05] + occupation_matrix = fel.occupation_matrix(OW, skip=0, segments=1000) + maxima_matrix = fel.find_maxima(occupation_matrix, box=box_voxels, edge_length=0.05) + maxima_matrix = fel.add_distances(maxima_matrix, "cylindrical", box / 2) + r_bins = np.arange(0, 2, 0.02) + distance_bins = np.arange(0.05, 2.05, 0.1) + energy_df = fel.distance_resolved_energies( + maxima_matrix, distance_bins, r_bins, box, 225 + ) + result = fel.find_energy_maxima(energy_df, r_min=0.05, r_max=0.15) + + assert (np.round(np.array(result["energy"])) == np.round(test_array)).all() diff --git a/test/test_utils.py b/test/test_utils.py index 211e141..9223f9e 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -31,16 +31,3 @@ def test_filon_fourier_transformation(logdata): xdata, xdata, frequencies=freqs, derivative='linear', imag=False ) assert np.isclose(filon_imag.real, filon_real).all() - - -def test_histogram(): - data = np.random.rand(100) - bins = np.linspace(0, 1) - np_hist = np.histogram(data, bins=bins)[0] - ut_hist = utils.histogram(data, bins=bins)[0] - assert (np_hist == ut_hist).all() - - bins = np.linspace(0.3, 1.5) - np_hist = np.histogram(data, bins=bins)[0] - ut_hist = utils.histogram(data, bins=bins)[0] - assert (np_hist == ut_hist).all()