Tests that the similarity is correct.
()
| 7 | |
| 8 | |
| 9 | def test_difference(): |
| 10 | """Tests that the similarity is correct.""" |
| 11 | # Create SOAP features for a system |
| 12 | desc = SOAP( |
| 13 | species=[1, 6, 7, 8], |
| 14 | r_cut=5.0, |
| 15 | n_max=2, |
| 16 | l_max=2, |
| 17 | sigma=0.2, |
| 18 | periodic=False, |
| 19 | compression={"mode": "off"}, |
| 20 | sparse=False, |
| 21 | ) |
| 22 | |
| 23 | # Calculate that identical molecules are identical. |
| 24 | a = molecule("H2O") |
| 25 | a_features = desc.create(a) |
| 26 | kernel = AverageKernel(metric="linear") |
| 27 | K = kernel.create([a_features, a_features]) |
| 28 | assert np.all(np.abs(K - 1) < 1e-3) |
| 29 | |
| 30 | # Check that completely different molecules are completely different |
| 31 | a = molecule("N2") |
| 32 | b = molecule("H2O") |
| 33 | a_features = desc.create(a) |
| 34 | b_features = desc.create(b) |
| 35 | K = kernel.create([a_features, b_features]) |
| 36 | assert np.all(np.abs(K - np.eye(2)) < 1e-3) |
| 37 | |
| 38 | # Check that somewhat similar molecules are somewhat similar |
| 39 | a = molecule("H2O") |
| 40 | b = molecule("H2O2") |
| 41 | a_features = desc.create(a) |
| 42 | b_features = desc.create(b) |
| 43 | K = kernel.create([a_features, b_features]) |
| 44 | assert K[0, 1] > 0.9 |
| 45 | |
| 46 | |
| 47 | def test_metrics(): |
nothing calls this directly
no test coverage detected