Esempio n. 1
0
    def test_pair_observer(self):
        if not available:
            self.skipTest(skip_msg)

        no_throw = True
        msg = ""

        bc = get_ternary_BC()
        ecis = get_example_ecis(bc=bc)
        atoms = bc.atoms.copy()
        calc = CE(atoms, bc, eci=ecis)
        atoms.set_calculator(calc)

        T = 1000
        nn_names = [name for name in bc.cluster_family_names
                    if int(name[1]) == 2]

        mc = FixedNucleusMC(
            atoms, T, network_name=nn_names,
            network_element=["Mg", "Si"])
        mc.insert_symbol_random_places("Mg", swap_symbs=["Al"])
        elements = {"Mg": 3, "Si": 3}
        mc.grow_cluster(elements)
        obs = PairObserver(mc.atoms, cutoff=4.1, elements=["Mg", "Si"])
        mc.attach(obs)
        mc.runMC(steps=200)
        self.assertEqual(obs.num_pairs, obs.num_pairs_brute_force())
        self.assertTrue(obs.symbols_is_synced())
Esempio n. 2
0
    def test_covariance_observer(self):
        """Test the covariance observer."""
        if not available:
            self.skipTest("ASE version does not have CE!")

        msg = ""
        no_throw = True
        from cemc.mcmc import FixEdgeLayers
        from cemc.mcmc import CovarianceMatrixObserver
        bc, args = get_ternary_BC(ret_args=True)
        ecis = get_example_ecis(bc=bc)
        atoms = get_atoms_with_ce_calc(bc, args, eci=ecis, size=[8, 8, 8], db_name="covariance_obs.db")

        T = 200
        nn_names = [name for name in bc.cluster_family_names
                    if int(name[1]) == 2]

        mc = FixedNucleusMC(
            atoms, T, network_name=nn_names,
            network_element=["Mg", "Si"])

        fixed_layers = FixEdgeLayers(atoms=mc.atoms, thickness=3.0)
        mc.add_constraint(fixed_layers)
        elements = {"Mg": 6, "Si": 6}
        mc.insert_symbol_random_places("Mg", num=1, swap_symbs=["Al"])
        mc.grow_cluster(elements)

        cov_obs = CovarianceMatrixObserver(atoms=mc.atoms, cluster_elements=["Mg", "Si"])
        mc.attach(cov_obs)
        for _ in range(10):
            mc.runMC(steps=100, elements=elements, init_cluster=False)

            obs_I = cov_obs.cov_matrix
            indices = []
            for atom in mc.atoms:
                if atom.symbol in ["Mg", "Si"]:
                    indices.append(atom.index)
            cluster = mc.atoms[indices]
            pos = cluster.get_positions()
            com = np.mean(pos, axis=0)
            pos -= com
            cov_matrix = np.zeros((3, 3))
            for i in range(pos.shape[0]):
                x = pos[i, :]
                cov_matrix += np.outer(x, x)
            self.assertTrue(np.allclose(obs_I, cov_matrix))
        os.remove("covariance_obs.db")
Esempio n. 3
0
    def test_with_covariance_reac_crd(self):
        if not available:
            self.skipTest("ASE version does not have CE!")

        msg = ""
        no_throw = True
        try:
            bc = get_ternary_BC()
            atoms = bc.atoms.copy()
            ecis = get_example_ecis(bc=bc)
            calc = CE(atoms, bc, eci=ecis)
            #bc.atoms.set_calculator(calc)

            T = 200
            nn_names = [name for name in bc.cluster_family_names
                        if int(name[1]) == 2]

            mc = FixedNucleusMC(
                atoms, T, network_name=nn_names,
                network_element=["Mg", "Si"])

            elements = {"Mg": 4, "Si": 4}
            mc.insert_symbol_random_places("Mg", num=1, swap_symbs=["Al"])
            mc.grow_cluster(elements)
            conc_init = CovarianceCrdInitializer(
                fixed_nucl_mc=mc, matrix_element="Al",
                cluster_elements=["Mg", "Si"])
            
            mc.runMC(steps=100, init_cluster=False)

            match, match_msg = self._spherical_nano_particle_matches(conc_init)
            self.assertTrue(match, msg=match_msg)
        except Exception as exc:
            no_throw = False
            msg = str(exc)

        self.assertTrue(no_throw, msg=msg)