-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for multiple NEP potentials
- Loading branch information
Showing
13 changed files
with
334,136 additions
and
0 deletions.
There are no files selected for viewing
6,974 changes: 6,974 additions & 0 deletions
6,974
tests/gpumd/carbon_average/C_2022_NEP3_MODIFIED.txt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.