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

Adding smaller test data #55

Merged
merged 12 commits into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 2 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[run]
omit =
pyedr/pyedr/tests/data/*
pyedr/pyedr/tests/*


[report]
exclude_lines =
Expand Down
35 changes: 0 additions & 35 deletions panedr/panedr/tests/test_edr.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,41 +117,6 @@ def test_verbosity(self):
print(ref_content - content)
assert_allclose(ref_content, content, atol=prec/2)

def test_progress(self):
"""
Test the progress meter displays what is expected.
"""
output = StringIO()
with redirect_stderr(output):
df = panedr.edr_to_df(EDR, verbose=True)
progress = output.getvalue().split('\n')[0].split('\r')
print(progress)
dt = 2000.0
# We can already iterate on `progress`, but I want to keep the cursor
# position from one for loop to the other.
progress_iter = iter(progress)
assert '' == next(progress_iter)
self._assert_progress_range(progress_iter, dt, 0, 21, 1)
self._assert_progress_range(progress_iter, dt, 30, 201, 10)
self._assert_progress_range(progress_iter, dt, 300, 2001, 100)
self._assert_progress_range(progress_iter, dt, 3000, 14101, 1000)
# Check the last line
print(df.iloc[-1, 0])
ref_line = 'Last Frame read : 14099, time : 28198000.0 ps'
last_line = next(progress_iter)
assert ref_line == last_line
# Did we leave stderr clean with a nice new line at the end?
assert output.getvalue().endswith('\n'), \
'New line missing at the end of output.'

def _assert_progress_range(self, progress, dt, start, stop, step):
for frame_idx in range(start, stop, step):
ref_line = 'Read frame : {}, time : {} ps'.format(frame_idx,
dt * frame_idx)
progress_line = next(progress)
print(frame_idx, progress_line)
assert ref_line == progress_line

def test_edr_dict_to_df_match(self, edr):
array_df = pandas.DataFrame.from_dict(edr.edr_dict).set_index(
"Time", drop=False)
Expand Down
1 change: 1 addition & 0 deletions panedr/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pandas
pyedr
pbr
tqdm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI here - @BFedder and I had a chat about this a week or so ago and I told him to go ahead with this, tqdm is a reasonably small dependency, and it will make life a lot easier imho.

@jbarnoud as the original code author, do you have any issues with this?

BFedder marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions panedr/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ install_requires =
pyedr
pandas
pbr
tqdm
BFedder marked this conversation as resolved.
Show resolved Hide resolved

[options.extras_require]
test =
Expand Down
27 changes: 15 additions & 12 deletions pyedr/pyedr/pyedr.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import sys
import itertools
import time
from tqdm import tqdm
from typing import List, Tuple, Dict

import numpy as np
Expand Down Expand Up @@ -444,24 +445,26 @@ def read_edr(path: str, verbose: bool = False) -> read_edr_return_type:
all_energies = []
all_names = [u'Time'] + [nm.name for nm in edr_file.nms]
times = []
for ifr, frame in enumerate(edr_file):
if verbose:
if ((ifr < 20 or ifr % 10 == 0) and
(ifr < 200 or ifr % 100 == 0) and
(ifr < 2000 or ifr % 1000 == 0)):
print('\rRead frame : {}, time : {} ps'.format(ifr, frame.t),
end='', file=sys.stderr)
if frame.ener:
# Export only frames that contain energies
times.append(frame.t)
all_energies.append([frame.t] + [ener.e for ener in frame.ener])
if verbose:
for ifr, frame in tqdm(enumerate(edr_file)):
if frame.ener:
# Export only frames that contain energies
times.append(frame.t)
all_energies.append([frame.t] + [ener.e for ener in frame.ener])

else:
for ifr, frame in enumerate(edr_file):
if frame.ener:
# Export only frames that contain energies
times.append(frame.t)
all_energies.append([frame.t] + [ener.e for ener in frame.ener])
BFedder marked this conversation as resolved.
Show resolved Hide resolved

end = time.time()
if verbose:
print('\rLast Frame read : {}, time : {} ps'
.format(ifr, frame.t),
end='', file=sys.stderr)
print('\n{} frame read in {:.2f} seconds'.format(ifr, end - begin),
print('\n{} frames read in {:.2f} seconds'.format(ifr, end - begin),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just get rid of timing altogether? You get iterations per second out of the standard tqdm output, otherwise if we really want total time, we could do something like bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}]" or some variation of the tqdm barformat parameter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there isn't really a need for timing as a default or even verbose option. IMO TQDM has enough timing info.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you'll still need the verbose flag to turn tqdm on/off?

file=sys.stderr)
return all_energies, all_names, times

Expand Down
Binary file added pyedr/pyedr/tests/data/cat_small.edr
Binary file not shown.
78 changes: 78 additions & 0 deletions pyedr/pyedr/tests/data/cat_small.xvg
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# This file was created Tue Aug 2 10:36:39 2022
# Created by:
# :-) GROMACS - gmx energy, 2021.5 (-:
#
# Executable: /biggin/b149/mert4328/gromacs2021.5/bin/gmx
# Data prefix: /biggin/b149/mert4328/gromacs2021.5
# Working dir: /biggin/b149/mert4328/Downloads/panedr/pyedr/pyedr/tests/data
# Command line:
# gmx energy -f cat.edr -o cat.xvg
# gmx energy is part of G R O M A C S:
#
# Green Red Orange Magenta Azure Cyan Skyblue
#
@ title "GROMACS Energies"
@ xaxis label "Time (ps)"
@ yaxis label "(kJ/mol), (K), (bar), (), (nm), (nm^3), (kg/m^3), (bar nm), (nm/ps)"
@TYPE xy
@ view 0.15, 0.15, 0.75, 0.85
@ legend on
@ legend box on
@ legend loctype view
@ legend 0.78, 0.8
@ legend length 2
@ s0 legend "Bond"
@ s1 legend "Angle"
@ s2 legend "Proper Dih."
@ s3 legend "Ryckaert-Bell."
@ s4 legend "LJ-14"
@ s5 legend "Coulomb-14"
@ s6 legend "LJ (SR)"
@ s7 legend "Disper. corr."
@ s8 legend "Coulomb (SR)"
@ s9 legend "Coul. recip."
@ s10 legend "Potential"
@ s11 legend "Kinetic En."
@ s12 legend "Total Energy"
@ s13 legend "Conserved En."
@ s14 legend "Temperature"
@ s15 legend "Pres. DC"
@ s16 legend "Pressure"
@ s17 legend "Constr. rmsd"
@ s18 legend "Box-X"
@ s19 legend "Box-Y"
@ s20 legend "Box-Z"
@ s21 legend "Volume"
@ s22 legend "Density"
@ s23 legend "pV"
@ s24 legend "Enthalpy"
@ s25 legend "Vir-XX"
@ s26 legend "Vir-XY"
@ s27 legend "Vir-XZ"
@ s28 legend "Vir-YX"
@ s29 legend "Vir-YY"
@ s30 legend "Vir-YZ"
@ s31 legend "Vir-ZX"
@ s32 legend "Vir-ZY"
@ s33 legend "Vir-ZZ"
@ s34 legend "Pres-XX"
@ s35 legend "Pres-XY"
@ s36 legend "Pres-XZ"
@ s37 legend "Pres-YX"
@ s38 legend "Pres-YY"
@ s39 legend "Pres-YZ"
@ s40 legend "Pres-ZX"
@ s41 legend "Pres-ZY"
@ s42 legend "Pres-ZZ"
@ s43 legend "#Surf*SurfTen"
@ s44 legend "Box-Vel-XX"
@ s45 legend "Box-Vel-YY"
@ s46 legend "Box-Vel-ZZ"
@ s47 legend "T-Protein"
@ s48 legend "T-non-Protein"
@ s49 legend "Lamb-Protein"
@ s50 legend "Lamb-non-Protein"
0.000000 1374.823242 3764.527344 231.283890 1769.977173 2654.552490 7772.819824 93403.531250 -4571.847656 -634643.937500 3080.209717 -525164.062500 86616.812500 -438547.250000 -438527.062500 303.022461 -226.715179 120.662346 0.000003 6.946903 6.946903 6.946903 335.253754 1021.368042 20.189453 -438527.062500 26742.484375 -1014.244263 -428.990967 -1014.437500 27074.781250 -1649.407959 -428.967163 -1649.536377 29145.390625 204.548508 99.160240 16.660902 99.179382 215.034927 138.859970 16.658545 138.872696 -57.596401 -1857.519287 0.000000 0.000000 0.000000 305.216461 302.853333 1.000000 1.000000
0.020000 1426.225220 3752.830322 263.692535 1819.986816 2681.986084 7719.875977 93969.390625 -4571.750488 -634577.250000 2922.847168 -524592.125000 86058.304688 -438533.812500 -438520.187500 301.068573 -226.705521 127.012749 0.000003 6.946952 6.946952 6.946952 335.260864 1021.346375 20.189880 -438513.625000 29358.015625 404.244843 1123.673584 404.736359 24486.328125 -524.118896 1123.208862 -525.036743 28367.406250 -77.379997 -34.419483 -122.969460 -34.468178 436.573883 42.815838 -122.923424 42.906754 21.844366 -1095.899536 0.002461 0.002461 0.002461 302.409576 300.965179 1.000000 1.000000
0.040000 1482.009888 3731.591797 261.267670 1802.421021 2664.599365 7685.277344 94167.468750 -4571.551758 -634705.562500 3063.695312 -524418.812500 86040.515625 -438378.312500 -438527.031250 301.006317 -226.685791 172.537247 0.000003 6.947053 6.947053 6.947053 335.275482 1021.301880 20.190762 -438358.125000 26755.218750 -1644.403564 1042.608276 -1644.735718 24932.406250 -618.195557 1041.680420 -618.909668 29127.406250 216.510681 150.174057 -84.276016 150.206955 373.560364 47.772625 -84.184113 47.843361 -72.459267 -2553.005859 0.005053 0.005053 0.005053 299.224762 301.143646 1.000000 1.000000
0.060000 1470.337524 3683.409424 237.611053 1862.587646 2639.180664 7770.815430 93807.351562 -4571.210938 -634513.875000 2964.734863 -524649.062500 86426.179688 -438222.875000 -438543.031250 302.355530 -226.652084 40.944675 0.000003 6.947225 6.947225 6.947225 335.300385 1021.226013 20.192261 -438202.687500 27163.343750 -2570.930908 1478.509766 -2571.069824 30978.859375 -990.745056 1477.574463 -991.381042 27043.828125 160.203705 262.667664 -130.225845 262.681427 -189.501358 113.234261 -130.133194 113.297256 152.131683 1158.661621 0.008582 0.008582 0.008582 299.770569 302.554779 1.000000 1.000000
Binary file added pyedr/pyedr/tests/data/cat_small_units.p
Binary file not shown.
6 changes: 3 additions & 3 deletions pyedr/pyedr/tests/datafiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
from pkg_resources import resource_filename


EDR = resource_filename(__name__, 'data/cat.edr')
EDR_XVG = resource_filename(__name__, 'data/cat.xvg')
EDR_UNITS = resource_filename(__name__, 'data/cat_units.p')
EDR = resource_filename(__name__, 'data/cat_small.edr')
EDR_XVG = resource_filename(__name__, 'data/cat_small.xvg')
EDR_UNITS = resource_filename(__name__, 'data/cat_small_units.p')

EDR_IRREG = resource_filename(__name__, 'data/irregular.edr')
EDR_IRREG_XVG = resource_filename(__name__, 'data/irregular.xvg')
Expand Down
35 changes: 0 additions & 35 deletions pyedr/pyedr/tests/test_edr.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def test_columns(self, edr):

for ref, val in zip(edr.xvgcols, edr.edr_dict.keys()):
assert ref == val, "mismatching column entries"

def test_times(self, edr):
"""
Test that the time is read correctly when dt is regular.
Expand Down Expand Up @@ -110,40 +109,6 @@ def test_verbosity(self):
assert_allclose(ref_content[:, i], edr_dict[key],
atol=prec/2)

def test_progress(self):
"""
Test the progress meter displays what is expected.
"""
output = StringIO()
with redirect_stderr(output):
edr_dict = pyedr.edr_to_dict(EDR, verbose=True)
progress = output.getvalue().split('\n')[0].split('\r')
print(progress)
dt = 2000.0
# We can already iterate on `progress`, but I want to keep the cursor
# position from one for loop to the other.
progress_iter = iter(progress)
assert '' == next(progress_iter)
self._assert_progress_range(progress_iter, dt, 0, 21, 1)
self._assert_progress_range(progress_iter, dt, 30, 201, 10)
self._assert_progress_range(progress_iter, dt, 300, 2001, 100)
self._assert_progress_range(progress_iter, dt, 3000, 14101, 1000)
# Check the last line
ref_line = 'Last Frame read : 14099, time : 28198000.0 ps'
last_line = next(progress_iter)
assert ref_line == last_line
# Did we leave stderr clean with a nice new line at the end?
assert output.getvalue().endswith('\n'), \
'New line missing at the end of output.'

def _assert_progress_range(self, progress, dt, start, stop, step):
for frame_idx in range(start, stop, step):
ref_line = 'Read frame : {}, time : {} ps'.format(frame_idx,
dt * frame_idx)
progress_line = next(progress)
print(frame_idx, progress_line)
assert ref_line == progress_line


def read_xvg(path):
"""
Expand Down
1 change: 1 addition & 0 deletions pyedr/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
numpy>=1.19.0
pbr
tqdm
1 change: 1 addition & 0 deletions pyedr/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ python_requires = >= 3.6
install_requires =
numpy
pbr
tqdm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to also say, can you add tqdm to the gh actions CI yaml file?


[options.extras_require]
test =
Expand Down