def test_no_throw(self):
        if not available:
            self.skipTest(skipMsg)

        no_throw = True
        msg = ""
        try:
            bc = get_ternary_BC()
            eci = get_example_ecis(bc)

            atoms = bc.atoms.copy()
            CE(atoms, bc, eci=eci)

            mc = Montecarlo(atoms, 1000)
            mc.insert_symbol_random_places("Mg", num=10, swap_symbs=["Al"])

            # Note: convergence_factor should never be
            # set to a negative value! Here it is done
            # to make the test converged after one step
            bias = AdaptiveBiasReactionPathSampler(
                mc_obj=mc,
                react_crd_init=DummyReacCrdInit(),
                react_crd=[-1.0, 1.0],
                convergence_factor=-1.0)
            bias.run()
        except Exception as exc:
            msg = str(exc)
            no_throw = False
        self.assertTrue(no_throw, msg=msg)
Exemplo n.º 2
0
    def test_with_bias_potential(self):
        if not available:
            self.skipTest(avail_msg)

        msg = ""
        try:
            os.remove("test_db_ternary.db")
        except Exception:
            pass
        no_throw = True
        try:
            bc = get_ternary_BC()
            ecis = get_example_ecis(bc=bc)
            atoms = bc.atoms.copy()
            calc = CE(atoms, bc, eci=ecis)

            groups = [{"Al": 2}, {"Mg": 1, "Si": 1}]
            symbs = ["Al", "Mg", "Si"]
            T = 400
            mc = PseudoBinarySGC(atoms,
                                 T,
                                 chem_pot=-0.2,
                                 symbols=symbs,
                                 groups=groups)
            conc_init = PseudoBinaryConcInitializer(mc)
            reac_crd = np.linspace(0.0, 1.0, 10)
            bias_pot = reac_crd**2
            bias = PseudoBinaryFreeEnergyBias(conc_init, reac_crd, bias_pot)
            mc.add_bias(bias)
            mc.runMC(mode="fixed", steps=100, equil=False)
            os.remove("test_db_ternary.db")
        except Exception as exc:
            msg = "{}: {}".format(type(exc).__name__, str(exc))
            no_throw = False
        self.assertTrue(no_throw, msg)
Exemplo n.º 3
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())
Exemplo n.º 4
0
    def test_no_throw(self):
        if not available:
            self.skipTest(avail_msg)

        msg = ""
        try:
            os.remove("test_db_ternary.db")
        except Exception:
            pass
        no_throw = True
        try:
            bc = get_ternary_BC()
            ecis = get_example_ecis(bc=bc)
            atoms = bc.atoms.copy()
            calc = CE(atoms, bc, eci=ecis)

            groups = [{"Al": 2}, {"Mg": 1, "Si": 1}]
            symbs = ["Al", "Mg", "Si"]
            T = 400
            mc = PseudoBinarySGC(atoms,
                                 T,
                                 chem_pot=-0.2,
                                 symbols=symbs,
                                 groups=groups)
            mc.runMC(mode="fixed", steps=100, equil=False)
            os.remove("test_db_ternary.db")
        except Exception as exc:
            msg = "{}: {}".format(type(exc).__name__, str(exc))
            no_throw = False
        self.assertTrue(no_throw, msg)
Exemplo n.º 5
0
    def test_ignore_atoms(self):
        if not has_ase_with_ce:
            self.skipTest("ASE does not have CE")
        from cemc.mcmc import FixedElement
        no_trow = True
        msg = ""
        try:
            from copy import deepcopy
            conc = Concentration(basis_elements=[['V', 'Li'], ['O']])
            kwargs = {
                "crystalstructure": "rocksalt",
                "concentration": conc,
                "a": 4.12,
                'size': [2, 2, 2],
                'cubic': True,
                "max_cluster_size": 4,
                "max_cluster_dia": 4.12,
                "db_name": 'database.db',
                'basis_function': 'sluiter',
                'ignore_background_atoms': True
            }
            fix_elem = FixedElement(element="O")
            kw_args_cpy = deepcopy(kwargs)
            ceBulk = CEBulk(**kw_args_cpy)
            ecis = get_example_ecis(ceBulk)
            atoms = get_atoms_with_ce_calc(ceBulk,
                                           kwargs,
                                           eci=ecis,
                                           size=[3, 3, 3],
                                           db_name="ignore_test_large.db")
            calc = atoms.get_calculator()

            # Insert some Li atoms
            num_li = 5
            symbols = [atom.symbol for atom in atoms]
            num_inserted = 0
            for i in range(0, len(symbols)):
                if symbols[i] == "V":
                    symbols[i] = "Li"
                    num_inserted += 1
                if num_inserted >= num_li:
                    break
            calc.set_symbols(symbols)

            mc = Montecarlo(atoms, 800)
            mc.add_constraint(fix_elem)
            mc.runMC(steps=100, equil=False, mode="fixed")

            # Clean up files
            os.remove("ignore_test_large.db")
            os.remove("database.db")
        except Exception as exc:
            no_trow = False
            msg = str(exc)
        self.assertTrue(no_trow, msg=msg)
    def test_run(self):
        if not available:
            self.skipTest(reason)

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

        mc = Montecarlo(atoms, 1000000)
        mc.insert_symbol_random_places("Mg", swap_symbs=["Al"], num=3)
        performance_monitor = MultithreadPerformance(4)
        performance_monitor.run(mc, 100)
    def test_adaptive_euler(self):
        if ( not has_ase_with_ce ):
            msg = "ASE version does not have CE"
            self.skipTest( msg )
            return
        no_throw = True
        msg = ""
        try:
                b1, b2, a1, a2 = self.init_bulk_crystal()
                gs1 = {
                    "atoms": a1,
                    "bc":b1,
                    "eci":get_example_ecis(bc=b1),
                    "cf":get_example_cf(bc=b1, atoms=a1)
                }

                gs2 = {
                    "atoms": a2,
                    "bc":b2,
                    "eci":get_example_ecis(bc=b2),
                    "cf":get_example_cf(bc=b2, atoms=a2)
                }
                ground_states = [gs1, gs2]

                boundary = PhaseBoundaryTracker( ground_states )
                T = [10,20]
                mc_args = {
                    "steps":10,
                    "mode":"fixed",
                    "equil":False
                }
                res = boundary.separation_line_adaptive_euler(init_temp=100, min_step=99,stepsize=100, mc_args=mc_args, symbols=["Al","Mg"])
                fname = "test_phase_boundary.h5"
                save_phase_boundary(fname, res)
                process_phase_boundary(fname)
        except Exception as exc:
            no_throw = False
            msg = str(exc)
        self.assertTrue( no_throw, msg=msg )
Exemplo n.º 8
0
 def init_bulk_crystal(self):
     conc = Concentration(basis_elements=[["Al", "Mg", "Si"]])
     ceBulk = CEBulk(crystalstructure="fcc",
                     a=4.05,
                     size=[4, 4, 4],
                     concentration=conc,
                     db_name=db_name,
                     max_cluster_size=2,
                     max_cluster_dia=4.0)
     ceBulk.reconfigure_settings()
     ecis = get_example_ecis(bc=ceBulk)
     atoms = ceBulk.atoms.copy()
     calc = CE(atoms, ceBulk, ecis)
     return ceBulk, atoms
Exemplo n.º 9
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")
Exemplo n.º 10
0
 def init_bulk_crystal(self):
     conc_args = {
         "conc_ratio_min_1": [[2, 1, 1]],
         "conc_ratio_max_1": [[0, 2, 2]],
     }
     ceBulk = CEBulk(crystalstructure="fcc",
                     a=4.05,
                     size=[4, 4, 4],
                     basis_elements=[["Al", "Mg", "Si"]],
                     conc_args=conc_args,
                     db_name=db_name,
                     max_cluster_size=2,
                     max_cluster_dia=4.0)
     ceBulk.reconfigure_settings()
     ecis = get_example_ecis(bc=ceBulk)
     calc = CE(ceBulk, ecis)
     ceBulk.atoms.set_calculator(calc)
     return ceBulk
Exemplo n.º 11
0
    def test_raise_error_on_invalid_chem_pot(self):
        if not available:
            self.skipTest(avail_msg)

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

        groups = [{"Al": 2}, {"Mg": 1, "Si": 1}]
        symbs = ["Al", "Mg", "Si"]
        T = 400
        with self.assertRaises(InvalidChemicalPotentialError):
            PseudoBinarySGC(atoms,
                            T,
                            chem_pot=-0.2,
                            symbols=symbs,
                            groups=groups)
    def test_with_ternay(self):
        if ( not has_ase_with_ce ):
            msg = "ASE version does not have CE"
            self.skipTest( msg )
            return
        no_throw = True
        msg = ""
        try:
            ground_states = []
            elements = ["Al", "Mg", "Si"]
            for i in range(3):
                ce_bulk = get_ternary_BC()
                eci = get_example_ecis(bc=ce_bulk)
                atoms = ce_bulk.atoms.copy()
                for atom in atoms:
                    atom.symbol = elements[i]
                gs = {
                    "atoms": atoms,
                    "bc":ce_bulk,
                    "eci":eci,
                    "cf":get_example_cf(bc=ce_bulk, atoms=atoms)
                }
                ground_states.append(gs)

            boundary = PhaseBoundaryTracker( ground_states )
            T = [10,20]
            mc_args = {
                "steps":10,
                "mode":"fixed",
                "equil":False
            }
            res = boundary.separation_line_adaptive_euler( init_temp=100,min_step=99,stepsize=100, mc_args=mc_args, symbols=["Al","Mg","Si"] )
            fname = "test_phase_boundary_ternary.h5"
            save_phase_boundary(fname, res)
            process_phase_boundary(fname)
        except Exception as exc:
            no_throw = False
            msg = str(exc)
        self.assertTrue( no_throw, msg=msg )
Exemplo n.º 13
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)