def test_k2_peaks_periodic(self): """Tests the correct peak locations and intensities are found for the k=2 term in periodic systems. """ atoms = Atoms( cell=[ [10, 0, 0], [10, 10, 0], [10, 0, 10], ], symbols=["H", "C"], scaled_positions=[ [0.1, 0.5, 0.5], [0.9, 0.5, 0.5], ] ) desc = MBTR( species=["H", "C"], k2={ "geometry": {"function": "distance"}, "grid": {"min": 0, "max": 10, "sigma": 0.5, "n": 1000}, "weighting": {"function": "exp", "scale": 0.8, "cutoff": 1e-3}, }, normalize_gaussians=False, periodic=True, flatten=True, sparse=False ) features = desc.create(atoms)[0, :] x = desc.get_k2_axis() # Calculate assumed locations and intensities. assumed_locs = np.array([2, 8]) assumed_ints = np.exp(-0.8*np.array([2, 8])) assumed_ints[0] *= 2 # There are two periodic distances at 2Å assumed_ints[0] /= 2 # The periodic distances ar halved because they belong to different cells # Check the H-C peaks hc_feat = features[desc.get_location(("H", "C"))] hc_peak_indices = find_peaks(hc_feat, prominence=0.001)[0] hc_peak_locs = x[hc_peak_indices] hc_peak_ints = hc_feat[hc_peak_indices] self.assertTrue(np.allclose(hc_peak_locs, assumed_locs, rtol=0, atol=1e-2)) self.assertTrue(np.allclose(hc_peak_ints, assumed_ints, rtol=0, atol=1e-2)) # Check that everything else is zero features[desc.get_location(("H", "C"))] = 0 self.assertEqual(features.sum(), 0)
def test_k2_peaks_finite(self): """Tests the correct peak locations and intensities are found for the k=2 term in finite systems. """ desc = MBTR( species=[1, 8], k2={ "geometry": {"function": "distance"}, "grid": {"min": -1, "max": 3, "sigma": 0.5, "n": 1000}, "weighting": {"function": "unity"}, }, normalize_gaussians=False, periodic=False, flatten=True, sparse=False ) features = desc.create(H2O)[0, :] pos = H2O.get_positions() x = desc.get_k2_axis() # Check the H-H peaks hh_feat = features[desc.get_location(("H", "H"))] hh_peak_indices = find_peaks(hh_feat, prominence=0.5)[0] hh_peak_locs = x[hh_peak_indices] hh_peak_ints = hh_feat[hh_peak_indices] self.assertTrue(np.allclose(hh_peak_locs, [np.linalg.norm(pos[0] - pos[2])], rtol=0, atol=1e-2)) self.assertTrue(np.allclose(hh_peak_ints, [1], rtol=0, atol=1e-2)) # Check the O-H peaks ho_feat = features[desc.get_location(("H", "O"))] ho_peak_indices = find_peaks(ho_feat, prominence=0.5)[0] ho_peak_locs = x[ho_peak_indices] ho_peak_ints = ho_feat[ho_peak_indices] self.assertTrue(np.allclose(ho_peak_locs, np.linalg.norm(pos[0] - pos[1]), rtol=0, atol=1e-2)) self.assertTrue(np.allclose(ho_peak_ints, [2], rtol=0, atol=1e-2)) # Check that everything else is zero features[desc.get_location(("H", "H"))] = 0 features[desc.get_location(("H", "O"))] = 0 self.assertEqual(features.sum(), 0)