Beispiel #1
0
 def get_cebulk(self):
     conc = Concentration(basis_elements=[["Al","Mg"]])
     ceBulk = CEBulk(crystalstructure="fcc", a=4.05, size=[3,3,3], concentration=conc, db_name=db_name,  
                     max_cluster_size=3, max_cluster_dia=4.5)
     ceBulk.reconfigure_settings()
     cf = CorrFunction(ceBulk)
     cf = cf.get_cf(ceBulk.atoms)
     ecis = {key:1.0 for key in cf.keys()}
     atoms = ceBulk.atoms.copy()
     calc = CE( atoms, ceBulk, ecis )
     return atoms
Beispiel #2
0
 def get_cebulk(self):
     conc_args = {
         "conc_ratio_min_1":[[1,0]],
         "conc_ratio_max_1":[[0,1]],
     }
     ceBulk = CEBulk( crystalstructure="fcc", a=4.05, size=[3,3,3], basis_elements=[["Al","Mg"]], conc_args=conc_args, db_name=db_name)
     ceBulk.reconfigure_settings()
     cf = CorrFunction(ceBulk)
     cf = cf.get_cf(ceBulk.atoms)
     ecis = {key:1.0 for key in cf.keys()}
     calc = CE( ceBulk, ecis )
     ceBulk.atoms.set_calculator(calc)
     return ceBulk
Beispiel #3
0
    def test_set_singlets( self ):
        if ( not has_ase_with_ce ):
            self.skipTest( "ASE version does not have CE" )
            return

        system_types = [["Al","Mg"],["Al","Mg","Si"],["Al","Mg","Si","Cu"]]

        db_name = "test_singlets.db"
        n_concs = 4
        no_throw = True
        msg = ""
        try:
            for basis_elems in system_types:
                conc_args = {
                    "conc_ratio_min_1":[[1,0]],
                    "conc_ratio_max_1":[[0,1]],
                }
                a = 4.05
                mx_dia_name = get_max_cluster_dia_name()
                size_arg = {mx_dia_name:a}
                ceBulk = CEBulk( crystalstructure="fcc", a=a, size=[5, 5, 5], basis_elements=[basis_elems], conc_args=conc_args, \
                db_name=db_name, max_cluster_size=2,**size_arg)
                ceBulk.reconfigure_settings()
                cf = CorrFunction(ceBulk)
                corrfuncs = cf.get_cf(ceBulk.atoms)
                eci = {name:1.0 for name in corrfuncs.keys()}
                calc = CE( ceBulk,eci )
                for _ in range(n_concs):
                    conc = np.random.rand(len(basis_elems))*0.97
                    conc /= np.sum(conc)
                    conc_dict = {}
                    for i in range(len(basis_elems)):
                        conc_dict[basis_elems[i]] = conc[i]
                    calc.set_composition(conc_dict)
                    ref_cf = calc.get_cf()

                    singlets = {}
                    for key,value in ref_cf.items():
                        if ( key.startswith("c1") ):
                            singlets[key] = value
                    comp = calc.singlet2comp(singlets)
                    dict_comp = "Ref {}. Computed {}".format(conc_dict,comp)
                    for key in comp.keys():
                        self.assertAlmostEqual( comp[key], conc_dict[key], msg=dict_comp, places=1 )
                calc.set_singlets(singlets)
        except Exception as exc:
            msg = str(exc)
            no_throw = False
        self.assertTrue( no_throw, msg=msg )
Beispiel #4
0
    def test_double_swaps_ternary( self ):
        if ( not has_ase_with_ce ): # Disable this test
            self.skipTest("ASE version has not cluster expansion")
            return

        db_name = "test_db_ternary.db"
        conc_args = {
            "conc_ratio_min_1":[[4,0,0]],
            "conc_ratio_max_1":[[0,4,0]],
            "conc_ratio_min_1":[[2,2,0]],
            "conc_ratio_max_2":[[1,1,2]]
        }
        max_dia = get_max_cluster_dia_name()
        size_arg = {max_dia:4.05}
        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=3, **size_arg)
        ceBulk.reconfigure_settings()
        corr_func = CorrFunction( ceBulk )
        cf = corr_func.get_cf( ceBulk.atoms )
        #prefixes = [name.rpartition("_")[0] for name in cf.keys()]
        #prefixes.remove("")
        eci = {name:1.0 for name in cf.keys()}
        calc = CE( ceBulk, eci )
        n_tests = 10

        # Insert 25 Mg atoms and 25 Si atoms
        n = 18
        for i in range(n):
            calc.calculate( ceBulk.atoms, ["energy"], [(i,"Al","Mg")])
            calc.calculate( ceBulk.atoms, ["energy"], [(i+n,"Al","Si")])
            updated_cf = calc.get_cf()
            brute_force = corr_func.get_cf_by_cluster_names( ceBulk.atoms, updated_cf.keys() )
            for key in updated_cf.keys():
                self.assertAlmostEqual( brute_force[key], updated_cf[key])

        # Swap atoms
        for i in range(n_tests):
            indx1 = np.random.randint(low=0,high=len(ceBulk.atoms))
            symb1 = ceBulk.atoms[indx1].symbol
            indx2 = indx1
            symb2 = symb1
            while( symb2 == symb1 ):
                indx2 = np.random.randint( low=0, high=len(ceBulk.atoms) )
                symb2 = ceBulk.atoms[indx2].symbol
            calc.calculate( ceBulk.atoms, ["energy"], [(indx1,symb1,symb2),(indx2,symb2,symb1)])
            update_cf = calc.get_cf()
            brute_force = corr_func.get_cf_by_cluster_names( ceBulk.atoms, update_cf.keys() )
            for key,value in brute_force.items():
                self.assertAlmostEqual( value, update_cf[key])
Beispiel #5
0
 def init_bulk_crystal(self):
     max_dia_name = get_max_cluster_dia_name()
     size_arg = {max_dia_name: 4.05}
     conc = Concentration(basis_elements=[["Al", "Mg", "Si"]])
     ceBulk = CEBulk(crystalstructure="fcc",
                     a=4.05,
                     size=[3, 3, 3],
                     concentration=conc,
                     db_name=db_name,
                     max_cluster_size=3,
                     **size_arg)
     ceBulk.reconfigure_settings()
     atoms = ceBulk.atoms.copy()
     calc = CE(atoms, ceBulk, ecis)
     return ceBulk, atoms
Beispiel #6
0
 def init_bulk_crystal(self):
     conc_args = {
         "conc_ratio_min_1": [[2, 1, 1]],
         "conc_ratio_max_1": [[0, 2, 2]],
     }
     max_dia_name = get_max_cluster_dia_name()
     size_arg = {max_dia_name: 4.05}
     ceBulk = CEBulk(crystalstructure="fcc", a=4.05, size=[3, 3, 3],
                          basis_elements=[["Al", "Mg", "Si"]],
                          conc_args=conc_args, db_name=db_name,
                          max_cluster_size=3, **size_arg)
     ceBulk.reconfigure_settings()
     calc = CE(ceBulk, ecis)
     ceBulk.atoms.set_calculator(calc)
     return ceBulk
Beispiel #7
0
    def test_no_throw(self):
        if (not has_ase_with_ce):
            self.skipTest("The ASE version does not include the CE module!")
            return

        no_throw = True
        msg = ""
        try:
            db_name = "test_db.db"
            conc = Concentration(basis_elements=[["Al", "Mg"]])
            ceBulk = CEBulk(crystalstructure="fcc",
                            a=4.05,
                            size=[3, 3, 3],
                            concentration=conc,
                            db_name=db_name,
                            max_cluster_size=3,
                            max_cluster_dia=4.5)
            ceBulk.reconfigure_settings()
            cf = CorrFunction(ceBulk)
            cf = cf.get_cf(ceBulk.atoms)
            ecis = {key: 0.001 for key in cf.keys()}
            atoms = ceBulk.atoms.copy()
            calc = Clease(ceBulk, cluster_name_eci=ecis)  # Bug in the update
            atoms.set_calculator(calc)
            #ceBulk.atoms.set_calculator( calc )
            mf = MeanFieldApprox(atoms, ceBulk)
            chem_pot = {"c1_0": -1.05}
            betas = np.linspace(1.0 / (kB * 100), 1.0 / (kB * 800), 50)
            G = mf.free_energy(betas, chem_pot=chem_pot)
            G = mf.free_energy(betas)  # Try when chem_pot is not given
            U = mf.internal_energy(betas, chem_pot=chem_pot)
            U = mf.internal_energy(betas)
            Cv = mf.heat_capacity(betas, chem_pot=chem_pot)
            Cv = mf.heat_capacity(betas)

            atoms = ceBulk.atoms.copy()
            atoms[0].symbol = "Mg"
            atoms[1].symbol = "Mg"
            calc = CE(atoms, ceBulk, eci=ecis)
            #ceBulk.atoms.set_calculator(calc)
            # Test the Canonical MFA
            T = [500, 400, 300, 200, 100]
            canonical_mfa = CanonicalMeanField(atoms=atoms, T=T)
            res = canonical_mfa.calculate()
        except Exception as exc:
            no_throw = False
            msg = str(exc)
        self.assertTrue(no_throw, msg=msg)
Beispiel #8
0
    def get_calc(self, lat):
        db_name = "test_db_{}.db".format(lat)

        conc = Concentration(basis_elements=[["Al", "Mg"]])
        a = 4.05
        ceBulk = CEBulk(crystalstructure=lat, a=a, size=[3, 3, 3],
                        concentration=conc, db_name=db_name,
                        max_cluster_size=3, max_cluster_dia=6.0)
        ceBulk.reconfigure_settings()
        cf = CorrFunction(ceBulk)
        corrfuncs = cf.get_cf(ceBulk.atoms)
        eci = {name: 1.0 for name in corrfuncs.keys()}
        atoms = ceBulk.atoms.copy()
        calc = CE(atoms, ceBulk, eci)
        atoms.set_calculator(calc)
        return atoms, ceBulk, eci
Beispiel #9
0
    def get_calc(self, lat):
        db_name = "test_db_{}.db".format(lat)

        conc_args = {
            "conc_ratio_min_1": [[1, 0]],
            "conc_ratio_max_1": [[0, 1]],
        }
        a = 4.05
        ceBulk = CEBulk(crystalstructure=lat, a=a, size=[3, 3, 3],
                             basis_elements=[["Al", "Mg"]],
                             conc_args=conc_args,
                             db_name=db_name, max_cluster_size=3)
        ceBulk.reconfigure_settings()
        cf = CorrFunction(ceBulk)
        corrfuncs = cf.get_cf(ceBulk.atoms)
        eci = {name: 1.0 for name in corrfuncs.keys()}
        calc = CE(ceBulk, eci)
        return calc, ceBulk, eci
Beispiel #10
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 init_bulk_crystal(self):
        conc1 = Concentration(basis_elements=[["Al","Mg"]])
        conc2 = Concentration(basis_elements=[["Al","Mg"]])
        ceBulk1 = CEBulk(crystalstructure="fcc", a=4.05, size=[3,3,3], concentration=conc1, db_name=db_name,
                         max_cluster_dia=4.5)
        ceBulk1.reconfigure_settings()
        ceBulk2 = CEBulk(crystalstructure="fcc", a=4.05, size=[3,3,3], concentration=conc2, db_name=db_name,
                         max_cluster_dia=4.5)
        ceBulk2.reconfigure_settings()

        atoms1 = ceBulk1.atoms.copy()
        atoms2 = ceBulk2.atoms.copy()

        for atom in atoms2:
            atom.symbol = "Mg"
        return ceBulk1, ceBulk2, atoms1, atoms2
Beispiel #12
0
    def test_supercell( self ):
        if ( not has_ase_with_ce ):
            self.skipTest("ASE version does not have CE")
            return

        calc, ceBulk, eci = self.get_calc("fcc")
        db_name = "test_db_fcc_super.db"

        conc_args = {
            "conc_ratio_min_1":[[1,0]],
            "conc_ratio_max_1":[[0,1]],
        }

        kwargs = {
            "crystalstructure": "fcc",
            "a": 4.05,
            "size":[3, 3, 3],
            "basis_elements":[["Al","Mg"]],
            "conc_args": conc_args,
            "db_name": db_name,
            "max_cluster_size": 3,
            "max_cluster_dia": 4.05
        }

        kwargs_template = copy.deepcopy(kwargs)
        kwargs_template["size"] = [4, 4, 4]
        kwargs_template["db_name"] = "template_bc.db"
        template_supercell_bc = CEBulk(**kwargs_template)
        template_supercell_bc.reconfigure_settings()

        ceBulk = CEBulk(**kwargs)
        ceBulk.reconfigure_settings()
        calc = get_ce_calc(ceBulk, kwargs, eci, size=[4, 4, 4],
                           db_name="sc4x4x.db")
        ceBulk = calc.BC
        ceBulk.atoms.set_calculator(calc)
        corr_func = CorrFunction(template_supercell_bc)
        for i in range(10):
            calc.calculate(ceBulk.atoms, ["energy"], [(i, "Al", "Mg")])
            updated_cf = calc.get_cf()
            brute_force = corr_func.get_cf_by_cluster_names(
                ceBulk.atoms, list(updated_cf.keys()))

            for key, value in brute_force.items():
                self.assertAlmostEqual(value, updated_cf[key])
        os.remove("sc4x4x.db")
Beispiel #13
0
    def test_self_interactions(self):
        if not has_ase_with_ce:
            self.skipTest("ASE does not have CE")

        from cemc.ce_calculator import SelfInteractionError

        a = 4.05
        conc = Concentration(basis_elements=[["Au", "Cu", "Ti"]])
        db_name = "test_self_interactoins.db"
        kwargs = dict(crystalstructure="fcc", a=a, size=[3, 3, 3],
                      concentration=conc, db_name=db_name,
                      max_cluster_size=2, max_cluster_dia=5.0)

        ceBulk = CEBulk(**kwargs)
        atoms = get_atoms_with_ce_calc(ceBulk, kwargs, eci={'c0': 1.0},
                                       size=[8, 8, 8], db_name=db_name)

        with self.assertRaises(SelfInteractionError):
            atoms = get_atoms_with_ce_calc(ceBulk, kwargs, eci={'c0': 1.0},
                                           size=[1, 1, 1], db_name=db_name)
        os.remove(db_name)
    def init_bulk_crystal(self):
        conc_args = {
            "conc_ratio_min_1": [[1, 0]],
            "conc_ratio_max_1": [[0, 1]],
        }
        ceBulk1 = CEBulk(crystalstructure="fcc",
                         a=4.05,
                         size=[3, 3, 3],
                         basis_elements=[["Al", "Mg"]],
                         conc_args=conc_args,
                         db_name=db_name)
        ceBulk1.reconfigure_settings()
        ceBulk2 = CEBulk(crystalstructure="fcc",
                         a=4.05,
                         size=[3, 3, 3],
                         basis_elements=[["Al", "Mg"]],
                         conc_args=conc_args,
                         db_name=db_name)
        ceBulk2.reconfigure_settings()

        for atom in ceBulk2.atoms:
            atom.symbol = "Mg"
        return ceBulk1, ceBulk2