2
2
3
3
import numpy as np
4
4
import pytest
5
+ from ase import io
5
6
6
7
from kliff .dataset import Dataset
7
8
8
9
9
- def test_ase_parser ():
10
- """Test ASE parser. """
10
+ def test_dataset_from_ase ():
11
+ """Test ASE parser reading from file using ASE parser """
11
12
12
13
# training set
13
14
filename = Path (__file__ ).parents [1 ].joinpath ("test_data/configs/Si_4.xyz" )
@@ -34,6 +35,54 @@ def test_ase_parser():
34
35
assert np .allclose (configs [1 ].stress , np .array ([9.9 , 5.5 , 1.1 , 8.8 , 7.7 , 4.4 ]))
35
36
36
37
38
+ def test_dataset_add_from_ase ():
39
+ """Test adding configurations to dataset using ASE parser."""
40
+ filename = Path (__file__ ).parents [1 ].joinpath ("test_data/configs/Si_4.xyz" )
41
+ data = Dataset ()
42
+ data .add_from_ase (filename , energy_key = "Energy" , forces_key = "force" )
43
+ configs = data .get_configs ()
44
+
45
+ assert len (configs ) == 4
46
+ assert configs [0 ].species == ["Si" for _ in range (4 )]
47
+ assert configs [0 ].coords .shape == (4 , 3 )
48
+ assert configs [0 ].energy == 123.45
49
+ assert np .allclose (configs [0 ].stress , np .array ([1.1 , 5.5 , 9.9 , 8.8 , 7.7 , 4.4 ]))
50
+ assert configs [1 ].forces .shape == (8 , 3 )
51
+
52
+
53
+ def test_dataset_from_ase_atoms_list ():
54
+ """Test ASE parser reading from file using ASE atoms list."""
55
+ filename = Path (__file__ ).parents [1 ].joinpath ("test_data/configs/Si_4.xyz" )
56
+ atoms = io .read (filename , index = ":" )
57
+ data = Dataset .from_ase (
58
+ ase_atoms_list = atoms , energy_key = "Energy" , forces_key = "force"
59
+ )
60
+ configs = data .get_configs ()
61
+
62
+ assert len (configs ) == 4
63
+ assert configs [0 ].species == ["Si" for _ in range (4 )]
64
+ assert configs [0 ].coords .shape == (4 , 3 )
65
+ assert configs [0 ].energy == 123.45
66
+ assert np .allclose (configs [0 ].stress , np .array ([1.1 , 5.5 , 9.9 , 8.8 , 7.7 , 4.4 ]))
67
+ assert configs [1 ].forces .shape == (8 , 3 )
68
+
69
+
70
+ def test_dataset_add_from_ase_atoms_list ():
71
+ """Test adding configurations to dataset using ASE atoms list."""
72
+ filename = Path (__file__ ).parents [1 ].joinpath ("test_data/configs/Si_4.xyz" )
73
+ atoms = io .read (filename , index = ":" )
74
+ data = Dataset ()
75
+ data .add_from_ase (ase_atoms_list = atoms , energy_key = "Energy" , forces_key = "force" )
76
+ configs = data .get_configs ()
77
+
78
+ assert len (configs ) == 4
79
+ assert configs [0 ].species == ["Si" for _ in range (4 )]
80
+ assert configs [0 ].coords .shape == (4 , 3 )
81
+ assert configs [0 ].energy == 123.45
82
+ assert np .allclose (configs [0 ].stress , np .array ([1.1 , 5.5 , 9.9 , 8.8 , 7.7 , 4.4 ]))
83
+ assert configs [1 ].forces .shape == (8 , 3 )
84
+
85
+
37
86
# def test_colabfit_parser():
38
87
# TODO: figure minimal colabfit example to run tests on
39
88
# pass
0 commit comments