|
1 | 1 | import numpy as np
|
2 | 2 | import pytest
|
3 | 3 |
|
| 4 | +from rascaline import SphericalExpansion |
4 | 5 | from rascaline.systems import AseSystem
|
5 | 6 |
|
6 | 7 |
|
@@ -145,3 +146,56 @@ def test_no_pbc_cell():
|
145 | 146 | )
|
146 | 147 | with pytest.warns(Warning, match=message):
|
147 | 148 | AseSystem(atoms)
|
| 149 | + |
| 150 | + |
| 151 | +def test_same_spherical_expansion(): |
| 152 | + system = ase.Atoms( |
| 153 | + "CaC6", |
| 154 | + positions=[ |
| 155 | + (0.0, 0.0, 0.0), |
| 156 | + (1.88597, 1.92706, 0.0113749), |
| 157 | + (2.66157, 3.55479, 7.7372), |
| 158 | + (2.35488, 3.36661, 3.88), |
| 159 | + (2.19266, 2.11524, 3.86858), |
| 160 | + (2.52936, 4.62777, 3.87771), |
| 161 | + (2.01817, 0.85408, 3.87087), |
| 162 | + ], |
| 163 | + cell=[[3.57941, 0, 0], [0.682558, 5.02733, 0], [0.285565, 0.454525, 7.74858]], |
| 164 | + pbc=True, |
| 165 | + ) |
| 166 | + |
| 167 | + calculator = SphericalExpansion( |
| 168 | + # make sure to choose a cutoff larger then the cell to test for pairs crossing |
| 169 | + # multiple periodic boundaries |
| 170 | + cutoff=9, |
| 171 | + max_radial=5, |
| 172 | + max_angular=5, |
| 173 | + atomic_gaussian_width=0.3, |
| 174 | + radial_basis={"Gto": {}}, |
| 175 | + center_atom_weight=1.0, |
| 176 | + cutoff_function={"Step": {}}, |
| 177 | + ) |
| 178 | + |
| 179 | + rascaline_nl = calculator.compute( |
| 180 | + system, gradients=["positions", "cell"], use_native_system=True |
| 181 | + ) |
| 182 | + |
| 183 | + ase_nl = calculator.compute( |
| 184 | + system, gradients=["positions", "cell"], use_native_system=False |
| 185 | + ) |
| 186 | + |
| 187 | + for key, block in rascaline_nl.items(): |
| 188 | + ase_block = ase_nl.block(key) |
| 189 | + |
| 190 | + assert ase_block.samples == block.samples |
| 191 | + # Since the pairs are in a different order, the values are slightly different |
| 192 | + assert np.allclose(ase_block.values, block.values, atol=1e-16, rtol=1e-9) |
| 193 | + |
| 194 | + for parameter in ["cell", "positions"]: |
| 195 | + gradient = block.gradient(parameter) |
| 196 | + ase_gradient = ase_block.gradient(parameter) |
| 197 | + |
| 198 | + assert gradient.samples == ase_gradient.samples |
| 199 | + assert np.allclose( |
| 200 | + ase_gradient.values, gradient.values, atol=1e-16, rtol=1e-6 |
| 201 | + ) |
0 commit comments