Moved files and reformatted some
This commit is contained in:
parent
b4486ff265
commit
62705da6f3
@ -15,10 +15,9 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import shlex
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.abspath('..'))
|
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,
|
# 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
|
# add these directories to sys.path here. If the directory is relative to the
|
||||||
|
@ -21,13 +21,13 @@ calling :func:`~mdevaluate.utils.runningmean` as shown below.
|
|||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import mdevaluate as md
|
from src import mdevaluate as md
|
||||||
import tudplot
|
import tudplot
|
||||||
|
|
||||||
OW = md.open('/data/niels/sim/water/bulk/260K', trajectory='out/*.xtc').subset(atom_name='OW')
|
OW = md.open('/data/niels/sim/water/bulk/260K', trajectory='out/*.xtc').subset(atom_name='OW')
|
||||||
|
|
||||||
t, Fqt = md.correlation.shifted_correlation(
|
t, Fqt = src.mdevaluate.correlation.shifted_correlation(
|
||||||
partial(md.correlation.isf, q=22.7),
|
partial(src.mdevaluate.correlation.isf, q=22.7),
|
||||||
OW,
|
OW,
|
||||||
average=False,
|
average=False,
|
||||||
window=0.2,
|
window=0.2,
|
||||||
|
@ -8,23 +8,23 @@ Additionally a KWW function is fitted to the results.
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from scipy.optimize import curve_fit
|
from scipy.optimize import curve_fit
|
||||||
import mdevaluate as md
|
from src import mdevaluate as md
|
||||||
import tudplot
|
import tudplot
|
||||||
|
|
||||||
OW = md.open('/data/niels/sim/water/bulk/260K', trajectory='out/*.xtc').subset(atom_name='OW')
|
OW = md.open('/data/niels/sim/water/bulk/260K', trajectory='out/*.xtc').subset(atom_name='OW')
|
||||||
t, S = md.correlation.shifted_correlation(
|
t, S = src.mdevaluate.correlation.shifted_correlation(
|
||||||
partial(md.correlation.isf, q=22.7),
|
partial(src.mdevaluate.correlation.isf, q=22.7),
|
||||||
OW,
|
OW,
|
||||||
average=True
|
average=True
|
||||||
)
|
)
|
||||||
# Only include data-points of the alpha-relaxation for the fit
|
# Only include data-points of the alpha-relaxation for the fit
|
||||||
mask = t > 3e-1
|
mask = t > 3e-1
|
||||||
fit, cov = curve_fit(md.functions.kww, t[mask], S[mask])
|
fit, cov = curve_fit(src.mdevaluate.functions.kww, t[mask], S[mask])
|
||||||
tau = md.functions.kww_1e(*fit)
|
tau = src.mdevaluate.functions.kww_1e(*fit)
|
||||||
|
|
||||||
tudplot.activate()
|
tudplot.activate()
|
||||||
plt.figure()
|
plt.figure()
|
||||||
plt.plot(t, S, '.', label='ISF of Bulk Water')
|
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.xscale('log')
|
||||||
plt.legend()
|
plt.legend()
|
||||||
|
@ -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 numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import mdevaluate as md
|
from src import mdevaluate as md
|
||||||
import tudplot
|
import tudplot
|
||||||
from scipy import spatial
|
from scipy import spatial
|
||||||
from scipy.optimize import curve_fit
|
from scipy.optimize import curve_fit
|
||||||
@ -73,7 +73,7 @@ wall_atoms = wall_atoms[dist < 0.35]
|
|||||||
SW = traj.subset(indices = wall_atoms)
|
SW = traj.subset(indices = wall_atoms)
|
||||||
|
|
||||||
from functools import partial
|
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
|
#selector function to choose liquid oxygens with a certain distance to wall atoms
|
||||||
def selector_func(coords, lindices, windices, dmin, dmax):
|
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],
|
selector = partial(selector_func,lindices=LO.atom_subset.indices[0],
|
||||||
windices=SW.atom_subset.indices[0],dmin=bins[i],
|
windices=SW.atom_subset.indices[0],dmin=bins[i],
|
||||||
dmax = bins[i+1])
|
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,
|
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]))
|
description=str(bins[i])+','+str(bins[i+1]))
|
||||||
|
|
||||||
taus = np.zeros(len(S))
|
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')
|
pl = plt.plot(t, s, '.', label='d = ' + str(binpos[i]) + ' nm')
|
||||||
#only includes the relevant data for 1/e fitting
|
#only includes the relevant data for 1/e fitting
|
||||||
mask = s < 0.6
|
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])
|
p0=[1.0,t[t>1/np.e][-1],0.5])
|
||||||
taus[i] = md.functions.kww_1e(*fit)
|
taus[i] = src.mdevaluate.functions.kww_1e(*fit)
|
||||||
plt.plot(t, md.functions.kww(t, *fit), c=pl[0].get_color())
|
plt.plot(t, src.mdevaluate.functions.kww(t, *fit), c=pl[0].get_color())
|
||||||
plt.xscale('log')
|
plt.xscale('log')
|
||||||
plt.legend()
|
plt.legend()
|
||||||
#plt.show()
|
#plt.show()
|
||||||
|
@ -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
|
from matplotlib import pyplot as plt
|
||||||
import mdevaluate as md
|
from src import mdevaluate as md
|
||||||
import tudplot
|
import tudplot
|
||||||
|
|
||||||
tudplot.activate()
|
tudplot.activate()
|
||||||
|
@ -186,9 +186,7 @@ def shifted_correlation(
|
|||||||
correlation = []
|
correlation = []
|
||||||
for index in indices:
|
for index in indices:
|
||||||
correlation.append(
|
correlation.append(
|
||||||
get_correlation(
|
get_correlation(frames, start_frame, index, shifted_idx)
|
||||||
frames, start_frame, index, shifted_idx
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
return correlation
|
return correlation
|
||||||
|
|
||||||
@ -213,9 +211,13 @@ def shifted_correlation(
|
|||||||
if nodes == 1:
|
if nodes == 1:
|
||||||
result = np.array(
|
result = np.array(
|
||||||
[
|
[
|
||||||
apply_selector(start_frame, frames=frames, idx=idx,
|
apply_selector(
|
||||||
|
start_frame,
|
||||||
|
frames=frames,
|
||||||
|
idx=idx,
|
||||||
selector=selector,
|
selector=selector,
|
||||||
multi_selector=multi_selector)
|
multi_selector=multi_selector,
|
||||||
|
)
|
||||||
for start_frame in start_frames
|
for start_frame in start_frames
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -227,11 +229,14 @@ def shifted_correlation(
|
|||||||
try:
|
try:
|
||||||
result = np.array(
|
result = np.array(
|
||||||
pool.map(
|
pool.map(
|
||||||
partial(apply_selector,
|
partial(
|
||||||
|
apply_selector,
|
||||||
frames=frames,
|
frames=frames,
|
||||||
idx=idx,
|
idx=idx,
|
||||||
selector=selector,
|
selector=selector,
|
||||||
multi_selector=multi_selector), start_frames
|
multi_selector=multi_selector,
|
||||||
|
),
|
||||||
|
start_frames,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
@ -2,6 +2,6 @@ from mdevaluate import atoms
|
|||||||
|
|
||||||
|
|
||||||
def test_compare_regex():
|
def test_compare_regex():
|
||||||
assert atoms.compare_regex(['OW', ], 'O')[0] == False
|
assert not atoms.compare_regex(["OW"], "O")[0]
|
||||||
assert atoms.compare_regex(['WO', ], 'O')[0] == False
|
assert not atoms.compare_regex(["WO"], "O")[0]
|
||||||
assert atoms.compare_regex(['O', ], 'O')[0] == True
|
assert atoms.compare_regex(["O"], "O")[0]
|
||||||
|
@ -5,11 +5,11 @@ import numpy as np
|
|||||||
|
|
||||||
def test_checksum():
|
def test_checksum():
|
||||||
salt = checksum.SALT
|
salt = checksum.SALT
|
||||||
checksum.SALT = ''
|
checksum.SALT = ""
|
||||||
assert checksum.checksum(1) == 304942582444936629325699363757435820077590259883
|
assert checksum.checksum(1) == 304942582444936629325699363757435820077590259883
|
||||||
assert checksum.checksum('42') == checksum.checksum(42)
|
assert checksum.checksum("42") == checksum.checksum(42)
|
||||||
cs1 = checksum.checksum(999)
|
cs1 = checksum.checksum(999)
|
||||||
checksum.SALT = '999'
|
checksum.SALT = "999"
|
||||||
assert cs1 != checksum.checksum(999)
|
assert cs1 != checksum.checksum(999)
|
||||||
|
|
||||||
a = np.array([1, 2, 3])
|
a = np.array([1, 2, 3])
|
||||||
@ -19,7 +19,6 @@ def test_checksum():
|
|||||||
|
|
||||||
|
|
||||||
def test_version():
|
def test_version():
|
||||||
|
|
||||||
@checksum.version(1)
|
@checksum.version(1)
|
||||||
def f1():
|
def f1():
|
||||||
pass
|
pass
|
||||||
|
@ -7,7 +7,7 @@ from mdevaluate import coordinates
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def trajectory(request):
|
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):
|
def test_coordinates_getitem(trajectory):
|
||||||
|
@ -9,6 +9,6 @@ def test_pbc_diff():
|
|||||||
y = np.random.rand(10, 3)
|
y = np.random.rand(10, 3)
|
||||||
box = np.ones((3,))
|
box = np.ones((3,))
|
||||||
|
|
||||||
assert (pbc.pbc_diff(x, x, box) == approx(0))
|
assert pbc.pbc_diff(x, x, box) == approx(0)
|
||||||
dxy = (pbc.pbc_diff(x, y, box)**2).sum(axis=1)**0.5
|
dxy = (pbc.pbc_diff(x, y, box) ** 2).sum(axis=1) ** 0.5
|
||||||
assert (dxy <= 0.75**0.5).all()
|
assert (dxy <= 0.75**0.5).all()
|
||||||
|
@ -8,7 +8,7 @@ from mdevaluate import utils
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def logdata(request):
|
def logdata(request):
|
||||||
xdata = np.logspace(-1, 3, 50)
|
xdata = np.logspace(-1, 3, 50)
|
||||||
ydata = np.exp(- (xdata)**0.7)
|
ydata = np.exp(-((xdata) ** 0.7))
|
||||||
return xdata, ydata
|
return xdata, ydata
|
||||||
|
|
||||||
|
|
||||||
@ -18,17 +18,17 @@ def test_filon_fourier_transformation(logdata):
|
|||||||
xdata_zero = copy(xdata)
|
xdata_zero = copy(xdata)
|
||||||
xdata_zero[0] = 0
|
xdata_zero[0] = 0
|
||||||
_, filon = utils.filon_fourier_transformation(xdata_zero, ydata)
|
_, 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)
|
freqs = np.logspace(-4, 1)
|
||||||
filon_freqs, filon_imag = utils.filon_fourier_transformation(
|
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()
|
assert (freqs == filon_freqs).all()
|
||||||
|
|
||||||
freqs, filon_real = utils.filon_fourier_transformation(
|
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()
|
assert np.isclose(filon_imag.real, filon_real).all()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user