-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtest_potential_data.py
More file actions
108 lines (86 loc) · 3.11 KB
/
Copy pathtest_potential_data.py
File metadata and controls
108 lines (86 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""Test the functionality of the lammps potential data object"""
import os
import pytest
import yaml
from aiida_lammps.data.potential import LammpsPotentialData
from aiida_lammps.parsers import inputfile
from .utils import TEST_DIR
@pytest.mark.parametrize(
"potential_type",
["tersoff", "eam_alloy", "meam", "morse"],
)
def test_lammps_potentials_init(
db_test_app, # pylint: disable=unused-argument
get_lammps_potential_data,
potential_type,
):
"""Test the LAMMPS potential data type."""
potential_information = get_lammps_potential_data(potential_type)
node = LammpsPotentialData.get_or_create(
source=potential_information["filename"],
filename=potential_information["filename"],
**potential_information["parameters"],
)
reference_file = os.path.join(
TEST_DIR,
"test_lammps_potential_data",
f"test_init_{potential_type}.yaml",
)
with open(reference_file) as handler:
reference_values = yaml.load(handler, yaml.SafeLoader)
_attributes = ["md5", "pair_style", "species", "atom_style", "default_units"]
for _attribute in _attributes:
_msg = f'attribute "{_attribute}" does not match between reference and current value'
assert reference_values[_attribute] == node.base.attributes.get(_attribute), (
_msg
)
@pytest.mark.parametrize(
"potential_type",
["tersoff", "eam_alloy", "meam", "morse"],
)
def test_lammps_potentials_files(
db_test_app, # pylint: disable=unused-argument
get_lammps_potential_data,
potential_type,
):
"""Test the LAMMPS potential data type."""
potential_information = get_lammps_potential_data(potential_type)
node = LammpsPotentialData.get_or_create(
source=potential_information["filename"],
filename=potential_information["filename"],
**potential_information["parameters"],
)
_msg = "content of the files differ"
assert node.get_content().split("\n") == potential_information[
"potential_data"
].split("\n"), _msg
@pytest.mark.parametrize(
"potential_type",
["tersoff", "eam_alloy", "meam", "morse"],
)
def test_lammps_potentials_input_block(
db_test_app, # pylint: disable=unused-argument
get_lammps_potential_data,
potential_type,
):
"""Test the LAMMPS potential data type."""
potential_information = get_lammps_potential_data(potential_type)
node = LammpsPotentialData.get_or_create(
source=potential_information["filename"],
filename=potential_information["filename"],
**potential_information["parameters"],
)
potential_block = inputfile.write_potential_block(
parameters_potential={},
potential_file="potential.dat",
potential=node,
structure=potential_information["structure"],
)
reference_file = os.path.join(
TEST_DIR,
"test_lammps_potential_data",
f"test_init_{potential_type}_block.txt",
)
with open(reference_file) as handler:
reference_value = handler.read()
assert potential_block == reference_value, "content of the potential blocks differ"