def test_k2_peaks_finite(self): """Tests the correct peak locations and intensities are found for the k=2 term in finite systems. """ desc = LMBTR( species=["H", "O"], 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])[0, :] pos = H2O.get_positions() x = desc.get_k2_axis() # Check the X-H peaks xh_feat = features[desc.get_location(("X", "H"))] xh_peak_indices = find_peaks(xh_feat, prominence=0.5)[0] xh_peak_locs = x[xh_peak_indices] xh_peak_ints = xh_feat[xh_peak_indices] self.assertTrue( np.allclose(xh_peak_locs, [np.linalg.norm(pos[0] - pos[2])], rtol=0, atol=1e-2)) self.assertTrue(np.allclose(xh_peak_ints, [1], rtol=0, atol=1e-2)) # Check the X-O peaks xo_feat = features[desc.get_location(("X", "O"))] xo_peak_indices = find_peaks(xo_feat, prominence=0.5)[0] xo_peak_locs = x[xo_peak_indices] xo_peak_ints = xo_feat[xo_peak_indices] self.assertTrue( np.allclose(xo_peak_locs, np.linalg.norm(pos[0] - pos[1]), rtol=0, atol=1e-2)) self.assertTrue(np.allclose(xo_peak_ints, [1], rtol=0, atol=1e-2)) # Check that everything else is zero features[desc.get_location(("X", "H"))] = 0 features[desc.get_location(("X", "O"))] = 0 self.assertEqual(features.sum(), 0)
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 = LMBTR(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])[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])) # Check the X-C peaks xc_feat = features[desc.get_location(("X", "C"))] xc_peak_indices = find_peaks(xc_feat, prominence=0.001)[0] xc_peak_locs = x[xc_peak_indices] xc_peak_ints = xc_feat[xc_peak_indices] self.assertTrue( np.allclose(xc_peak_locs, assumed_locs, rtol=0, atol=1e-2)) self.assertTrue( np.allclose(xc_peak_ints, assumed_ints, rtol=0, atol=1e-2)) # Check that everything else is zero features[desc.get_location(("X", "C"))] = 0 self.assertEqual(features.sum(), 0)
"max": 5, "n": 200, "sigma": 0.05 }, "weighting": { "function": "exponential", "scale": 1, "cutoff": 1e-2 }, }, periodic=True, normalization="none", ) # Create output for each site sites = lmbtr.create( slab_pure, positions=[ontop_pos, bridge_pos, hcp_pos, fcc_pos], ) # Plot the site-aluminum distributions for each site al_slice = lmbtr.get_location(("X", "Al")) x = lmbtr.get_k2_axis() mpl.plot(x, sites[0, al_slice], label="top") mpl.plot(x, sites[1, al_slice], label="bridge") mpl.plot(x, sites[2, al_slice], label="hcp") mpl.plot(x, sites[3, al_slice], label="fcc") mpl.xlabel("Site-Al distance (Å)") mpl.legend() mpl.show()