Tests that the correct features are present in the descriptor.
()
| 162 | |
| 163 | |
| 164 | def test_features(): |
| 165 | """Tests that the correct features are present in the descriptor.""" |
| 166 | system = get_simple_finite() |
| 167 | rs = math.sqrt(2) |
| 168 | kappa = math.sqrt(3) |
| 169 | eta = math.sqrt(5) |
| 170 | lmbd = 1 |
| 171 | zeta = math.sqrt(7) |
| 172 | |
| 173 | # Test against assumed values |
| 174 | dist_oh = system.get_distance(0, 1) |
| 175 | dist_hh = system.get_distance(0, 2) |
| 176 | ang_hoh = system.get_angle(0, 1, 2) * np.pi / 180.0 |
| 177 | ang_hho = system.get_angle(1, 0, 2) * np.pi / 180.0 |
| 178 | ang_ohh = -system.get_angle(2, 0, 1) * np.pi / 180.0 |
| 179 | rc = 6.0 |
| 180 | |
| 181 | # G1 |
| 182 | desc = ACSF(r_cut=rc, species=[1, 8]) |
| 183 | acsfg1 = desc.create(system) |
| 184 | g1_ho = cutoff(dist_oh, rc) |
| 185 | g1_hh = cutoff(dist_hh, rc) |
| 186 | g1_oh = 2 * cutoff(dist_oh, rc) |
| 187 | assert acsfg1[0, 0] == pytest.approx(g1_hh) |
| 188 | assert acsfg1[0, 1] == pytest.approx(g1_ho) |
| 189 | assert acsfg1[1, 0] == pytest.approx(g1_oh) |
| 190 | |
| 191 | # G2 |
| 192 | desc = ACSF(r_cut=6.0, species=[1, 8], g2_params=[[eta, rs]]) |
| 193 | acsfg2 = desc.create(system) |
| 194 | g2_hh = np.exp(-eta * np.power((dist_hh - rs), 2)) * g1_hh |
| 195 | g2_ho = np.exp(-eta * np.power((dist_oh - rs), 2)) * g1_ho |
| 196 | g2_oh = np.exp(-eta * np.power((dist_oh - rs), 2)) * g1_oh |
| 197 | assert acsfg2[0, 1] == pytest.approx(g2_hh) |
| 198 | assert acsfg2[0, 3] == pytest.approx(g2_ho) |
| 199 | assert acsfg2[1, 1] == pytest.approx(g2_oh) |
| 200 | |
| 201 | # G3 |
| 202 | desc = ACSF(r_cut=6.0, species=[1, 8], g3_params=[kappa]) |
| 203 | acsfg3 = desc.create(system) |
| 204 | g3_hh = np.cos(dist_hh * kappa) * g1_hh |
| 205 | g3_ho = np.cos(dist_oh * kappa) * g1_ho |
| 206 | g3_oh = np.cos(dist_oh * kappa) * g1_oh |
| 207 | assert acsfg3[0, 1] == pytest.approx(g3_hh) |
| 208 | assert acsfg3[0, 3] == pytest.approx(g3_ho) |
| 209 | assert acsfg3[1, 1] == pytest.approx(g3_oh) |
| 210 | |
| 211 | # G4 |
| 212 | desc = ACSF(r_cut=6.0, species=[1, 8], g4_params=[[eta, zeta, lmbd]]) |
| 213 | acsfg4 = desc.create(system) |
| 214 | gauss = ( |
| 215 | np.exp(-eta * (2 * dist_oh * dist_oh + dist_hh * dist_hh)) |
| 216 | * g1_ho |
| 217 | * g1_hh |
| 218 | * g1_ho |
| 219 | ) |
| 220 | g4_h_ho = ( |
| 221 | np.power(2, 1 - zeta) * np.power((1 + lmbd * np.cos(ang_hho)), zeta) * gauss |
nothing calls this directly
no test coverage detected