Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viscosity example #72

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
793 changes: 793 additions & 0 deletions examples/06_example_cepstrum_viscosity_h2o.ipynb

Large diffs are not rendered by default.

100,001 changes: 100,001 additions & 0 deletions examples/data/h2o/h2o.dat

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion setup.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"pytest-regressions>=2.4.2",
"pandas>=1.1.0",
"testbook",
"ipykernel"
"ipykernel",
"numba"
],
"doc": [
"sphinx==4.2.0",
Expand Down
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ def data_SiO2(data_SiO2_path):
print('T = {:f} K'.format(TEMPERATURE))
return jfile, DT_FS, TEMPERATURE, VOLUME

@pytest.fixture(scope='session')
def data_h2o(data_h2o_path):
import sportran as st
import numpy as np

jfile = st.i_o.TableFile(data_h2o_path, group_vectors=True)
jfile.read_datalines()
DT_FS = 1.0 # time step [fs]
TEMPERATURE = np.mean(jfile.data['Temp']) # temperature [K] (983.173 K)
VOLUME = 1918.4149658 # volume [A^3]
print('T = {:f} K'.format(TEMPERATURE))
print('V = {:f} A^3'.format(VOLUME))
return jfile, DT_FS, TEMPERATURE, VOLUME


@pytest.fixture
def check_reg(num_regression, data_regression):
Expand Down
12 changes: 12 additions & 0 deletions tests/test_as_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ def test_example_SiO2_fixed_K(data_SiO2, check_reg):
jf.cepstral_analysis(manual_cutoffK=42)
print(jf.cepstral_log)
check_reg(jf)

def test_example_viscosity_h2o(data_h2o, check_reg):
import sportran as st

jfile, DT_FS, TEMPERATURE, VOLUME = data_h2o
j = st.StressCurrent(np.column_stack([jfile.data['s_xy'], jfile.data['s_xz'], jfile.data['s_yz']]),
UNITS='real', DT_FS=DT_FS, TEMPERATURE=TEMPERATURE, VOLUME=VOLUME)
print(j.Nyquist_f_THz)
FSTAR_THZ = 25.0
jf = j.resample(fstar_THz=FSTAR_THZ, plot=False, freq_units='thz')
jf.cepstral_analysis()
print(jf.cepstral_log)


if __name__ == '__main__':
Expand Down
112 changes: 75 additions & 37 deletions tests/test_as_example/regenerate_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sportran as st
import numpy as np
import yaml, pandas as pd
import argparse


def write_results(jf, filename):
Expand All @@ -24,48 +25,85 @@ def write_results(jf, filename):
with open(filename + '.yml', 'w') as f:
f.write(yaml.dump(d))

def main(inputs):
if (inputs == 'all' or inputs == 'NaCl' ):
# NaCl
jfile = st.i_o.TableFile('../data/NaCl/NaCl.dat', group_vectors=True)
jfile.read_datalines(start_step=0, NSTEPS=0, select_ckeys=['Temp', 'flux', 'vcm[1]'])
DT_FS = 5.0 # time step [fs]
TEMPERATURE = np.mean(jfile.data['Temp']) # temperature [K]
VOLUME = 40.21**3 # volume [A^3]
print('T = {:f} K'.format(TEMPERATURE))
print('V = {:f} A^3'.format(VOLUME))

# NaCl
jfile = st.i_o.TableFile('../data/NaCl/NaCl.dat', group_vectors=True)
jfile.read_datalines(start_step=0, NSTEPS=0, select_ckeys=['Temp', 'flux', 'vcm[1]'])
DT_FS = 5.0 # time step [fs]
TEMPERATURE = np.mean(jfile.data['Temp']) # temperature [K]
VOLUME = 40.21**3 # volume [A^3]
print('T = {:f} K'.format(TEMPERATURE))
print('V = {:f} A^3'.format(VOLUME))
j = st.HeatCurrent([jfile.data['flux'], jfile.data['vcm[1]']], DT_FS=DT_FS, UNITS='metal', TEMPERATURE=TEMPERATURE,
VOLUME=VOLUME)
print(j.Nyquist_f_THz)
FSTAR_THZ = 14.0
jf = j.resample(fstar_THz=FSTAR_THZ, plot=False, freq_units='thz')
jf.cepstral_analysis()
print(jf.cepstral_log)

j = st.HeatCurrent([jfile.data['flux'], jfile.data['vcm[1]']], DT_FS=DT_FS, UNITS='metal', TEMPERATURE=TEMPERATURE,
VOLUME=VOLUME)
print(j.Nyquist_f_THz)
FSTAR_THZ = 14.0
jf = j.resample(fstar_THz=FSTAR_THZ, plot=False, freq_units='thz')
jf.cepstral_analysis()
print(jf.cepstral_log)
write_results(jf, 'test_example_NaCl')

if (inputs == 'all' or inputs == 'SiO2' ):
# SiO2
jfile = st.i_o.TableFile('../data/Silica/Silica.dat', group_vectors=True)
jfile.read_datalines(start_step=0, NSTEPS=0, select_ckeys=['flux1', 'Temp'])
DT_FS = 1.0 # time step [fs]
TEMPERATURE = np.mean(jfile.data['Temp']) # temperature [K]
VOLUME = 3130.431110818 # volume [A^3]
print('T = {:f} K'.format(TEMPERATURE))

write_results(jf, 'test_example_NaCl')
j = st.HeatCurrent(jfile.data['flux1'], DT_FS=DT_FS, UNITS='metal', TEMPERATURE=TEMPERATURE, VOLUME=VOLUME)
print(j.Nyquist_f_THz)
FSTAR_THZ = 28.0
jf = j.resample(fstar_THz=FSTAR_THZ, plot=False, freq_units='thz')
jf.cepstral_analysis()
print(jf.cepstral_log)

# SiO2
jfile = st.i_o.TableFile('../data/Silica/Silica.dat', group_vectors=True)
jfile.read_datalines(start_step=0, NSTEPS=0, select_ckeys=['flux1', 'Temp'])
DT_FS = 1.0 # time step [fs]
TEMPERATURE = np.mean(jfile.data['Temp']) # temperature [K]
VOLUME = 3130.431110818 # volume [A^3]
print('T = {:f} K'.format(TEMPERATURE))
write_results(jf, 'test_example_SiO2')

j = st.HeatCurrent(jfile.data['flux1'], DT_FS=DT_FS, UNITS='metal', TEMPERATURE=TEMPERATURE, VOLUME=VOLUME)
print(j.Nyquist_f_THz)
FSTAR_THZ = 28.0
jf = j.resample(fstar_THz=FSTAR_THZ, plot=False, freq_units='thz')
jf.cepstral_analysis()
print(jf.cepstral_log)
j = st.HeatCurrent(jfile.data['flux1'], DT_FS=DT_FS, UNITS='metal', TEMPERATURE=TEMPERATURE, VOLUME=VOLUME)
print(j.Nyquist_f_THz)
FSTAR_THZ = 28.0
jf = j.resample(fstar_THz=FSTAR_THZ, plot=False, freq_units='thz')
jf.cepstral_analysis(manual_cutoffK=42)
print(jf.cepstral_log)

write_results(jf, 'test_example_SiO2')
write_results(jf, 'test_example_SiO2_fixed_K')

if (inputs == 'all' or inputs == 'h2o' ):
# Viscosity H2O
jfile = st.i_o.TableFile('../data/h2o/h2o.dat', group_vectors=True)
jfile.read_datalines()
DT_FS = 1 # time step [fs]
TEMPERATURE = np.mean(jfile.data['Temp']) # temperature [K] (983.173 K)
VOLUME = 1918.4149658 # volume [A^3]
print('T = {:f} K'.format(TEMPERATURE))
print('V = {:f} A^3'.format(VOLUME))

j = st.HeatCurrent(jfile.data['flux1'], DT_FS=DT_FS, UNITS='metal', TEMPERATURE=TEMPERATURE, VOLUME=VOLUME)
print(j.Nyquist_f_THz)
FSTAR_THZ = 28.0
jf = j.resample(fstar_THz=FSTAR_THZ, plot=False, freq_units='thz')
jf.cepstral_analysis(manual_cutoffK=42)
print(jf.cepstral_log)
j = st.StressCurrent(np.column_stack([jfile.data['s_xy'], jfile.data['s_xz'], jfile.data['s_yz']]),
UNITS='real', DT_FS=DT_FS, TEMPERATURE=TEMPERATURE, VOLUME=VOLUME)
print(j.Nyquist_f_THz)
FSTAR_THZ = 25.0
jf = j.resample(fstar_THz=FSTAR_THZ, plot=False, freq_units='thz')
jf.cepstral_analysis()
print(jf.cepstral_log)

write_results(jf, 'test_example_SiO2_fixed_K')
write_results(jf, 'test_example_viscosity_h2o')


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Regenerate data for the test.')
parser.add_argument('-i', type=str,
help='''what data do you want to regenerate?
Valid options "all", "NaCl", "SiO2", "h2o".
Combinations can be done adding "_", e.g. "NaCl_SiO2"''')

inputs = parser.parse_args().i.split('_')
for i in inputs:
if i not in ["all", "NaCl", "SiO2", "h2o"]:
print('input values not valid use "-h" to get help')
else:
main(i)
Loading
Loading