From 62705da6f349a97799ba9ff9b242dd04ebe7bb6d Mon Sep 17 00:00:00 2001 From: Sebastian Kloth Date: Mon, 18 Dec 2023 14:47:22 +0100 Subject: [PATCH] Moved files and reformatted some --- doc/conf.py | 3 +- examples/plot_chi4.py | 6 ++-- examples/plot_isf.py | 12 ++++---- examples/plot_spatialisf.py | 14 ++++----- examples/plot_temperature.py | 2 +- {mdevaluate => src/mdevaluate}/__init__.py | 0 {mdevaluate => src/mdevaluate}/atoms.py | 0 {mdevaluate => src/mdevaluate}/autosave.py | 0 {mdevaluate => src/mdevaluate}/checksum.py | 0 {mdevaluate => src/mdevaluate}/cli.py | 0 {mdevaluate => src/mdevaluate}/coordinates.py | 0 {mdevaluate => src/mdevaluate}/correlation.py | 29 +++++++++++-------- .../mdevaluate}/distribution.py | 0 {mdevaluate => src/mdevaluate}/functions.py | 0 {mdevaluate => src/mdevaluate}/logging.py | 0 {mdevaluate => src/mdevaluate}/pbc.py | 0 {mdevaluate => src/mdevaluate}/reader.py | 0 {mdevaluate => src/mdevaluate}/utils.py | 0 test/test_atoms.py | 6 ++-- test/test_checksum.py | 7 ++--- test/test_coordinates.py | 2 +- test/test_pbc.py | 4 +-- test/test_utils.py | 12 ++++---- 23 files changed, 50 insertions(+), 47 deletions(-) rename {mdevaluate => src/mdevaluate}/__init__.py (100%) rename {mdevaluate => src/mdevaluate}/atoms.py (100%) rename {mdevaluate => src/mdevaluate}/autosave.py (100%) rename {mdevaluate => src/mdevaluate}/checksum.py (100%) rename {mdevaluate => src/mdevaluate}/cli.py (100%) rename {mdevaluate => src/mdevaluate}/coordinates.py (100%) rename {mdevaluate => src/mdevaluate}/correlation.py (95%) rename {mdevaluate => src/mdevaluate}/distribution.py (100%) rename {mdevaluate => src/mdevaluate}/functions.py (100%) rename {mdevaluate => src/mdevaluate}/logging.py (100%) rename {mdevaluate => src/mdevaluate}/pbc.py (100%) rename {mdevaluate => src/mdevaluate}/reader.py (100%) rename {mdevaluate => src/mdevaluate}/utils.py (100%) diff --git a/doc/conf.py b/doc/conf.py index b3e4666..1d27af8 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -15,10 +15,9 @@ import sys import os -import shlex sys.path.insert(0, os.path.abspath('..')) -import mdevaluate +from src import mdevaluate # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the diff --git a/examples/plot_chi4.py b/examples/plot_chi4.py index 6ef3b22..e91748b 100644 --- a/examples/plot_chi4.py +++ b/examples/plot_chi4.py @@ -21,13 +21,13 @@ calling :func:`~mdevaluate.utils.runningmean` as shown below. from functools import partial import matplotlib.pyplot as plt -import mdevaluate as md +from src import mdevaluate as md import tudplot OW = md.open('/data/niels/sim/water/bulk/260K', trajectory='out/*.xtc').subset(atom_name='OW') -t, Fqt = md.correlation.shifted_correlation( - partial(md.correlation.isf, q=22.7), +t, Fqt = src.mdevaluate.correlation.shifted_correlation( + partial(src.mdevaluate.correlation.isf, q=22.7), OW, average=False, window=0.2, diff --git a/examples/plot_isf.py b/examples/plot_isf.py index 322335f..0ac5f44 100644 --- a/examples/plot_isf.py +++ b/examples/plot_isf.py @@ -8,23 +8,23 @@ Additionally a KWW function is fitted to the results. from functools import partial import matplotlib.pyplot as plt from scipy.optimize import curve_fit -import mdevaluate as md +from src import mdevaluate as md import tudplot OW = md.open('/data/niels/sim/water/bulk/260K', trajectory='out/*.xtc').subset(atom_name='OW') -t, S = md.correlation.shifted_correlation( - partial(md.correlation.isf, q=22.7), +t, S = src.mdevaluate.correlation.shifted_correlation( + partial(src.mdevaluate.correlation.isf, q=22.7), OW, average=True ) # Only include data-points of the alpha-relaxation for the fit mask = t > 3e-1 -fit, cov = curve_fit(md.functions.kww, t[mask], S[mask]) -tau = md.functions.kww_1e(*fit) +fit, cov = curve_fit(src.mdevaluate.functions.kww, t[mask], S[mask]) +tau = src.mdevaluate.functions.kww_1e(*fit) tudplot.activate() plt.figure() plt.plot(t, S, '.', label='ISF of Bulk Water') -plt.plot(t, md.functions.kww(t, *fit), '-', label=r'KWW, $\tau$={:.2f}ps'.format(tau)) +plt.plot(t, src.mdevaluate.functions.kww(t, *fit), '-', label=r'KWW, $\tau$={:.2f}ps'.format(tau)) plt.xscale('log') plt.legend() diff --git a/examples/plot_spatialisf.py b/examples/plot_spatialisf.py index 3f7e6b1..7225915 100644 --- a/examples/plot_spatialisf.py +++ b/examples/plot_spatialisf.py @@ -8,7 +8,7 @@ In this case the bins describe the shortest distance of an oxygen atom to any wa import numpy as np import matplotlib.pyplot as plt -import mdevaluate as md +from src import mdevaluate as md import tudplot from scipy import spatial from scipy.optimize import curve_fit @@ -73,7 +73,7 @@ wall_atoms = wall_atoms[dist < 0.35] SW = traj.subset(indices = wall_atoms) from functools import partial -func = partial(md.correlation.isf, q=22.7) +func = partial(src.mdevaluate.correlation.isf, q=22.7) #selector function to choose liquid oxygens with a certain distance to wall atoms def selector_func(coords, lindices, windices, dmin, dmax): @@ -93,9 +93,9 @@ for i in range(len(bins)-1): selector = partial(selector_func,lindices=LO.atom_subset.indices[0], windices=SW.atom_subset.indices[0],dmin=bins[i], dmax = bins[i+1]) - t, S[i] = md.correlation.shifted_correlation( + t, S[i] = src.mdevaluate.correlation.shifted_correlation( func, traj,segments=50, skip=0.1,average=True, - correlation=md.correlation.subensemble_correlation(selector), + correlation=src.mdevaluate.correlation.subensemble_correlation(selector), description=str(bins[i])+','+str(bins[i+1])) taus = np.zeros(len(S)) @@ -105,10 +105,10 @@ for i,s in enumerate(S): pl = plt.plot(t, s, '.', label='d = ' + str(binpos[i]) + ' nm') #only includes the relevant data for 1/e fitting mask = s < 0.6 - fit, cov = curve_fit(md.functions.kww, t[mask], s[mask], + fit, cov = curve_fit(src.mdevaluate.functions.kww, t[mask], s[mask], p0=[1.0,t[t>1/np.e][-1],0.5]) - taus[i] = md.functions.kww_1e(*fit) - plt.plot(t, md.functions.kww(t, *fit), c=pl[0].get_color()) + taus[i] = src.mdevaluate.functions.kww_1e(*fit) + plt.plot(t, src.mdevaluate.functions.kww(t, *fit), c=pl[0].get_color()) plt.xscale('log') plt.legend() #plt.show() diff --git a/examples/plot_temperature.py b/examples/plot_temperature.py index b675689..528083b 100644 --- a/examples/plot_temperature.py +++ b/examples/plot_temperature.py @@ -6,7 +6,7 @@ This example reads an Gromacs energy file and plots the evolultion and mean of t """ from matplotlib import pyplot as plt -import mdevaluate as md +from src import mdevaluate as md import tudplot tudplot.activate() diff --git a/mdevaluate/__init__.py b/src/mdevaluate/__init__.py similarity index 100% rename from mdevaluate/__init__.py rename to src/mdevaluate/__init__.py diff --git a/mdevaluate/atoms.py b/src/mdevaluate/atoms.py similarity index 100% rename from mdevaluate/atoms.py rename to src/mdevaluate/atoms.py diff --git a/mdevaluate/autosave.py b/src/mdevaluate/autosave.py similarity index 100% rename from mdevaluate/autosave.py rename to src/mdevaluate/autosave.py diff --git a/mdevaluate/checksum.py b/src/mdevaluate/checksum.py similarity index 100% rename from mdevaluate/checksum.py rename to src/mdevaluate/checksum.py diff --git a/mdevaluate/cli.py b/src/mdevaluate/cli.py similarity index 100% rename from mdevaluate/cli.py rename to src/mdevaluate/cli.py diff --git a/mdevaluate/coordinates.py b/src/mdevaluate/coordinates.py similarity index 100% rename from mdevaluate/coordinates.py rename to src/mdevaluate/coordinates.py diff --git a/mdevaluate/correlation.py b/src/mdevaluate/correlation.py similarity index 95% rename from mdevaluate/correlation.py rename to src/mdevaluate/correlation.py index b9fef12..4a808c5 100644 --- a/mdevaluate/correlation.py +++ b/src/mdevaluate/correlation.py @@ -186,9 +186,7 @@ def shifted_correlation( correlation = [] for index in indices: correlation.append( - get_correlation( - frames, start_frame, index, shifted_idx - ) + get_correlation(frames, start_frame, index, shifted_idx) ) return correlation @@ -202,7 +200,7 @@ def shifted_correlation( num=segments, endpoint=False, dtype=int, - ) + ) ) num_frames = int(len(frames) * window) @@ -213,9 +211,13 @@ def shifted_correlation( if nodes == 1: result = np.array( [ - apply_selector(start_frame, frames=frames, idx=idx, - selector=selector, - multi_selector=multi_selector) + apply_selector( + start_frame, + frames=frames, + idx=idx, + selector=selector, + multi_selector=multi_selector, + ) for start_frame in start_frames ] ) @@ -227,11 +229,14 @@ def shifted_correlation( try: result = np.array( pool.map( - partial(apply_selector, - frames=frames, - idx=idx, - selector=selector, - multi_selector=multi_selector), start_frames + partial( + apply_selector, + frames=frames, + idx=idx, + selector=selector, + multi_selector=multi_selector, + ), + start_frames, ) ) finally: diff --git a/mdevaluate/distribution.py b/src/mdevaluate/distribution.py similarity index 100% rename from mdevaluate/distribution.py rename to src/mdevaluate/distribution.py diff --git a/mdevaluate/functions.py b/src/mdevaluate/functions.py similarity index 100% rename from mdevaluate/functions.py rename to src/mdevaluate/functions.py diff --git a/mdevaluate/logging.py b/src/mdevaluate/logging.py similarity index 100% rename from mdevaluate/logging.py rename to src/mdevaluate/logging.py diff --git a/mdevaluate/pbc.py b/src/mdevaluate/pbc.py similarity index 100% rename from mdevaluate/pbc.py rename to src/mdevaluate/pbc.py diff --git a/mdevaluate/reader.py b/src/mdevaluate/reader.py similarity index 100% rename from mdevaluate/reader.py rename to src/mdevaluate/reader.py diff --git a/mdevaluate/utils.py b/src/mdevaluate/utils.py similarity index 100% rename from mdevaluate/utils.py rename to src/mdevaluate/utils.py diff --git a/test/test_atoms.py b/test/test_atoms.py index 498e926..93a6b4b 100644 --- a/test/test_atoms.py +++ b/test/test_atoms.py @@ -2,6 +2,6 @@ from mdevaluate import atoms def test_compare_regex(): - assert atoms.compare_regex(['OW', ], 'O')[0] == False - assert atoms.compare_regex(['WO', ], 'O')[0] == False - assert atoms.compare_regex(['O', ], 'O')[0] == True + assert not atoms.compare_regex(["OW"], "O")[0] + assert not atoms.compare_regex(["WO"], "O")[0] + assert atoms.compare_regex(["O"], "O")[0] diff --git a/test/test_checksum.py b/test/test_checksum.py index 4e5d0fa..4f8eb4a 100644 --- a/test/test_checksum.py +++ b/test/test_checksum.py @@ -5,11 +5,11 @@ import numpy as np def test_checksum(): salt = checksum.SALT - checksum.SALT = '' + checksum.SALT = "" assert checksum.checksum(1) == 304942582444936629325699363757435820077590259883 - assert checksum.checksum('42') == checksum.checksum(42) + assert checksum.checksum("42") == checksum.checksum(42) cs1 = checksum.checksum(999) - checksum.SALT = '999' + checksum.SALT = "999" assert cs1 != checksum.checksum(999) a = np.array([1, 2, 3]) @@ -19,7 +19,6 @@ def test_checksum(): def test_version(): - @checksum.version(1) def f1(): pass diff --git a/test/test_coordinates.py b/test/test_coordinates.py index c32dcfc..fd37412 100644 --- a/test/test_coordinates.py +++ b/test/test_coordinates.py @@ -7,7 +7,7 @@ from mdevaluate import coordinates @pytest.fixture def trajectory(request): - return mdevaluate.open(os.path.join(os.path.dirname(__file__), 'data/water')) + return mdevaluate.open(os.path.join(os.path.dirname(__file__), "data/water")) def test_coordinates_getitem(trajectory): diff --git a/test/test_pbc.py b/test/test_pbc.py index 69aed27..4b25941 100644 --- a/test/test_pbc.py +++ b/test/test_pbc.py @@ -9,6 +9,6 @@ def test_pbc_diff(): y = np.random.rand(10, 3) box = np.ones((3,)) - assert (pbc.pbc_diff(x, x, box) == approx(0)) - dxy = (pbc.pbc_diff(x, y, box)**2).sum(axis=1)**0.5 + assert pbc.pbc_diff(x, x, box) == approx(0) + dxy = (pbc.pbc_diff(x, y, box) ** 2).sum(axis=1) ** 0.5 assert (dxy <= 0.75**0.5).all() diff --git a/test/test_utils.py b/test/test_utils.py index 211e141..84b0fda 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -8,7 +8,7 @@ from mdevaluate import utils @pytest.fixture def logdata(request): xdata = np.logspace(-1, 3, 50) - ydata = np.exp(- (xdata)**0.7) + ydata = np.exp(-((xdata) ** 0.7)) return xdata, ydata @@ -18,18 +18,18 @@ def test_filon_fourier_transformation(logdata): xdata_zero = copy(xdata) xdata_zero[0] = 0 _, filon = utils.filon_fourier_transformation(xdata_zero, ydata) - assert not np.isnan(filon).any(), 'There are NaN values in the filon result!' + assert not np.isnan(filon).any(), "There are NaN values in the filon result!" freqs = np.logspace(-4, 1) filon_freqs, filon_imag = utils.filon_fourier_transformation( - xdata, xdata, frequencies=freqs, derivative='linear', imag=True - ) + xdata, xdata, frequencies=freqs, derivative="linear", imag=True + ) assert (freqs == filon_freqs).all() freqs, filon_real = utils.filon_fourier_transformation( - xdata, xdata, frequencies=freqs, derivative='linear', imag=False - ) + xdata, xdata, frequencies=freqs, derivative="linear", imag=False + ) assert np.isclose(filon_imag.real, filon_real).all()