Skip to content

Commit

Permalink
Add tests for multiple NEP potentials
Browse files Browse the repository at this point in the history
  • Loading branch information
elindgren committed Jan 4, 2023
1 parent 5d562b0 commit a4bcff8
Show file tree
Hide file tree
Showing 13 changed files with 334,136 additions and 0 deletions.
6,974 changes: 6,974 additions & 0 deletions tests/gpumd/carbon_average/C_2022_NEP3_MODIFIED.txt

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions tests/gpumd/carbon_average/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# `dump_observer`: average

Test case for `average` mode of `dump_observer`. The two potentials are the `C_2022_NEP3.txt` potential, and a modified version of the same potential with the two first cutoffs changed.
Two MD runs have been performed with each of the two potentials as the only potential, to generate the files `observer0.xyz` and `observer1.xyz`.
The test runs with the average of the two potentials.
The resulitng `observer.xyz` file shall be compared to the average of the two `observer*.xyz` files.
This comparison is performed by the `compare_results.py` script, which compares the outputs numerically down to a precision of 1e-4.

Definition of pass: For the test of pass, running the `compare_results.py` script shall return all values to be within the tolerance.
66 changes: 66 additions & 0 deletions tests/gpumd/carbon_average/compare_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from math import isclose

def isfloat(num):
try:
float(num)
return True
except ValueError:
return False



def print_justified(val1, val2, close=True):
print(f'{val1}'.ljust(30), end='')
print(f'\t', end='')
print(f'{val2}'.ljust(30), end='')
if not close:
print('!!!!')
else:
print('\n', end='')


def get_floats_in_file(file):
entries = []
with open(file, 'r') as f:
for line in f.readlines():
linem = line.strip()
linem = linem.replace(' ', '=')
linem = linem.replace(':', '=')
linem = linem.replace('"', '=')
split_line = linem.split('=')
entries.extend([float(entry) for entry in split_line if isfloat(entry)])
return entries


entries0 = get_floats_in_file('observer0.xyz')
entries1 = get_floats_in_file('observer1.xyz')
assert len(entries0) == len(entries1)
average_entries = [(entries0[i] + entries1[i])*0.5 for i in range(len(entries0))]
entries_to_test = get_floats_in_file('observer.xyz')
assert len(entries0) == len(entries_to_test)

n_total = len(entries_to_test)
n_close = 0
header_printed = False
for i in range(n_total):
test = entries_to_test[i]
ref = average_entries[i]
close = isclose(test, ref, abs_tol=1e-4, rel_tol=1e-4)
if not close:
if not header_printed:
print_justified('Test', 'Ref')
header_printed = True
print_justified(test, ref, close=close)
raise ValueError(f"`observer.xyz` does not match average of `observer0.xyz` and `observer1.xyz` for value {i}")
n_close += 1 if close else 0

print(f'{n_close}/{n_total} within tolerance')
print("Test passed")








64,002 changes: 64,002 additions & 0 deletions tests/gpumd/carbon_average/model.xyz

Large diffs are not rendered by default.

64,002 changes: 64,002 additions & 0 deletions tests/gpumd/carbon_average/observer0.xyz

Large diffs are not rendered by default.

64,002 changes: 64,002 additions & 0 deletions tests/gpumd/carbon_average/observer1.xyz

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions tests/gpumd/carbon_average/run.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
potential ../../../potentials/nep/C_2022_NEP3.txt
potential C_2022_NEP3_MODIFIED.txt
velocity 300

time_step 1.0

ensemble nve
dump_observer average 1 1 1
run 1







Loading

0 comments on commit a4bcff8

Please sign in to comment.