Moved files and reformatted some

This commit is contained in:
Sebastian Kloth 2023-12-18 14:47:22 +01:00
parent b4486ff265
commit 62705da6f3
23 changed files with 50 additions and 47 deletions

View File

@ -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

View File

@ -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,

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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:

View File

@ -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]

View File

@ -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

View File

@ -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):

View File

@ -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()

View File

@ -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()