Beispiel #1
0
    def test_crossover(self):
        """Tests that disabling/enabling crossover works as expected."""
        pos = [[0.1, 0.1, 0.1]]
        species = [1, 8]
        nmax = 5
        lmax = 5

        # GTO
        desc = SOAP(
            species=species,
            rbf="gto",
            crossover=True,
            rcut=3,
            nmax=nmax,
            lmax=lmax,
            periodic=False,
        )
        hh_loc_full = desc.get_location(("H", "H"))
        oo_loc_full = desc.get_location(("O", "O"))
        full_output = desc.create(H2O, positions=pos)
        desc.crossover = False
        hh_loc = desc.get_location(("H", "H"))
        oo_loc = desc.get_location(("O", "O"))
        partial_output = desc.create(H2O, positions=pos)
        self.assertTrue(oo_loc_full != oo_loc)
        self.assertTrue(
            np.array_equal(full_output[:, hh_loc_full], partial_output[:, hh_loc])
        )
        self.assertTrue(
            np.array_equal(full_output[:, oo_loc_full], partial_output[:, oo_loc])
        )

        # Polynomial
        desc = SOAP(
            species=species,
            rbf="polynomial",
            crossover=True,
            rcut=3,
            nmax=lmax,
            lmax=lmax,
            periodic=False,
        )
        hh_loc_full = desc.get_location(("H", "H"))
        oo_loc_full = desc.get_location(("O", "O"))
        full_output = desc.create(H2O, pos)
        desc.crossover = False
        hh_loc = desc.get_location(("H", "H"))
        oo_loc = desc.get_location(("O", "O"))
        partial_output = desc.create(H2O, pos)
        self.assertTrue(oo_loc_full != oo_loc)
        self.assertTrue(
            np.array_equal(full_output[:, hh_loc_full], partial_output[:, hh_loc])
        )
        self.assertTrue(
            np.array_equal(full_output[:, oo_loc_full], partial_output[:, oo_loc])
        )
Beispiel #2
0
    def test_crossover(self):
        """Tests that disabling/enabling crossover works as expected.
        """
        pos = [[0.1, 0.1, 0.1]]

        # GTO
        desc = SOAP(species=[1, 8],
                    rbf="gto",
                    crossover=True,
                    rcut=3,
                    nmax=5,
                    lmax=5,
                    periodic=False)
        n_elem_feat = desc.get_number_of_element_features()
        full_output = desc.create(H2O, positions=pos)
        desc.crossover = False
        partial_output = desc.create(H2O, positions=pos)
        self.assertTrue(
            np.array_equal(full_output[:, 0:n_elem_feat],
                           partial_output[:, 0:n_elem_feat]))
        self.assertTrue(
            np.array_equal(full_output[:, 2 * n_elem_feat:],
                           partial_output[:, n_elem_feat:]))

        # Polynomial
        desc = SOAP(species=[1, 8],
                    rbf="polynomial",
                    crossover=True,
                    rcut=3,
                    nmax=5,
                    lmax=5,
                    periodic=False)
        n_elem_feat = desc.get_number_of_element_features()
        full_output = desc.create(H2O, pos)
        desc.crossover = False
        partial_output = desc.create(H2O, pos)
        self.assertTrue(
            np.array_equal(full_output[:, 0:n_elem_feat],
                           partial_output[:, 0:n_elem_feat]))
        self.assertTrue(
            np.array_equal(full_output[:, 2 * n_elem_feat:],
                           partial_output[:, n_elem_feat:]))