Example #1
0
    def test_k3_peaks_finite(self):
        """Tests the correct peak locations and intensities are found for the
        k=3 term in finite systems.
        """
        desc = LMBTR(
            species=["H", "O"],
            k3={
                "geometry": {"function": "angle"},
                "grid": {"min": -10, "max": 180, "sigma": 5, "n": 2000},
                "weighting": {"function": "unity"},
            },
            normalize_gaussians=False,
            periodic=False,
            flatten=True,
            sparse=False
        )
        features = desc.create(H2O, [0])[0, :]
        x = desc.get_k3_axis()

        # Check the X-H-O peaks
        xho_assumed_locs = np.array([38])
        xho_assumed_ints = np.array([1])
        xho_feat = features[desc.get_location(("X", "H", "O"))]
        xho_peak_indices = find_peaks(xho_feat, prominence=0.5)[0]
        xho_peak_locs = x[xho_peak_indices]
        xho_peak_ints = xho_feat[xho_peak_indices]
        self.assertTrue(np.allclose(xho_peak_locs, xho_assumed_locs, rtol=0, atol=5e-2))
        self.assertTrue(np.allclose(xho_peak_ints, xho_assumed_ints, rtol=0, atol=5e-2))

        # Check the X-O-H peaks
        xoh_assumed_locs = np.array([104])
        xoh_assumed_ints = np.array([1])
        xoh_feat = features[desc.get_location(("X", "O", "H"))]
        xoh_peak_indices = find_peaks(xoh_feat, prominence=0.5)[0]
        xoh_peak_locs = x[xoh_peak_indices]
        xoh_peak_ints = xoh_feat[xoh_peak_indices]
        self.assertTrue(np.allclose(xoh_peak_locs, xoh_assumed_locs, rtol=0, atol=5e-2))
        self.assertTrue(np.allclose(xoh_peak_ints, xoh_assumed_ints, rtol=0, atol=5e-2))

        # Check the H-X-O peaks
        hxo_assumed_locs = np.array([38])
        hxo_assumed_ints = np.array([1])
        hxo_feat = features[desc.get_location(("H", "X", "O"))]
        hxo_peak_indices = find_peaks(hxo_feat, prominence=0.5)[0]
        hxo_peak_locs = x[hxo_peak_indices]
        hxo_peak_ints = hxo_feat[hxo_peak_indices]
        self.assertTrue(np.allclose(hxo_peak_locs, hxo_assumed_locs, rtol=0, atol=5e-2))
        self.assertTrue(np.allclose(hxo_peak_ints, hxo_assumed_ints, rtol=0, atol=5e-2))

        # Check that everything else is zero
        features[desc.get_location(("X", "H", "O"))] = 0
        features[desc.get_location(("X", "O", "H"))] = 0
        features[desc.get_location(("H", "X", "O"))] = 0
        self.assertEqual(features.sum(), 0)
Example #2
0
    def test_k3_peaks_periodic(self):
        """Tests the correct peak locations and intensities are found for the
        k=3 term in periodic systems.
        """
        scale = 0.85
        desc = LMBTR(
            species=["H"],
            k3={
                "geometry": {
                    "function": "angle"
                },
                "grid": {
                    "min": 0,
                    "max": 180,
                    "sigma": 5,
                    "n": 2000
                },
                "weighting": {
                    "function": "exp",
                    "scale": scale,
                    "cutoff": 1e-3
                },
            },
            normalize_gaussians=False,
            periodic=True,
            flatten=True,
            sparse=False,
        )

        atoms = Atoms(
            cell=[
                [10, 0, 0],
                [0, 10, 0],
                [0, 0, 10],
            ],
            symbols=3 * ["H"],
            scaled_positions=[
                [0.05, 0.40, 0.5],
                [0.05, 0.60, 0.5],
                [0.95, 0.5, 0.5],
            ],
            pbc=True,
        )
        features = desc.create(atoms, [0])[0, :]
        x = desc.get_k3_axis()

        # Calculate assumed locations and intensities.
        assumed_locs = np.array([45, 90])
        dist = 2 + 2 * np.sqrt(2)  # The total distance around the three atoms
        weight = np.exp(-scale * dist)
        assumed_ints = np.array([weight, weight])

        # Check the X-H-H peaks
        xhh_feat = features[desc.get_location(("X", "H", "H"))]
        xhh_peak_indices = find_peaks(xhh_feat, prominence=0.01)[0]
        xhh_peak_locs = x[xhh_peak_indices]
        xhh_peak_ints = xhh_feat[xhh_peak_indices]
        self.assertTrue(
            np.allclose(xhh_peak_locs, assumed_locs, rtol=0, atol=1e-1))
        self.assertTrue(
            np.allclose(xhh_peak_ints, assumed_ints, rtol=0, atol=1e-1))

        # Calculate assumed locations and intensities.
        assumed_locs = np.array([45])
        dist = 2 + 2 * np.sqrt(2)  # The total distance around the three atoms
        weight = np.exp(-scale * dist)
        assumed_ints = np.array([weight])

        # Check the H-X-H peaks
        hxh_feat = features[desc.get_location(("H", "X", "H"))]
        hxh_peak_indices = find_peaks(hxh_feat, prominence=0.01)[0]
        hxh_peak_locs = x[hxh_peak_indices]
        hxh_peak_ints = hxh_feat[hxh_peak_indices]
        self.assertTrue(
            np.allclose(hxh_peak_locs, assumed_locs, rtol=0, atol=1e-1))
        self.assertTrue(
            np.allclose(hxh_peak_ints, assumed_ints, rtol=0, atol=1e-1))

        # Check that everything else is zero
        features[desc.get_location(("X", "H", "H"))] = 0
        features[desc.get_location(("H", "X", "H"))] = 0
        self.assertEqual(features.sum(), 0)