Ejemplo n.º 1
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 = 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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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()