Ejemplo n.º 1
0
def get_atoms(cubic=False):
    conc = Concentration(basis_elements=[["Al", "Mg", "Si"]])

    kwargs = {
        "crystalstructure": "fcc",
        "a": 4.05,
        "size": [2, 2, 2],
        "concentration": conc,
        "db_name": "data/almgsi_free_eng.db",
        "max_cluster_size": 4,
        "max_cluster_dia": [7.8, 5.0, 5.0],
        "cubic": cubic
    }
    N = 10
    ceBulk = CEBulk(**kwargs)
    print(ceBulk.basis_functions)
    eci_file = "data/almgsi_fcc_eci.json"
    eci_file = "data/eci_almgsi_aicc.json"
    eci_file = "data/eci_bcs.json"
    eci_file = "data/eci_almgsi_loocv.json"
    eci_file = "data/eci_l1.json"
    with open(eci_file, 'r') as infile:
        ecis = json.load(infile)
    db_name = "large_cell_db{}x{}x{}.db".format(N, N, N)
    atoms = get_atoms_with_ce_calc(ceBulk,
                                   kwargs,
                                   ecis,
                                   size=[N, N, N],
                                   db_name=db_name)
    return atoms
Ejemplo n.º 2
0
def get_bulkspacegroup_binary():
    # https://materials.springer.com/isp/crystallographic/docs/sd_0453869
    a = 10.553
    b = 10.553
    c = 10.553
    alpha = 90
    beta = 90
    gamma = 90
    cellpar = [a, b, c, alpha, beta, gamma]
    symbols = ["Al", "Al", "Al", "Al"]
    #symbols = ["Al","Al","Al","Al"]
    basis = [(0, 0, 0), (0.324, 0.324, 0.324), (0.3582, 0.3582, 0.0393),
             (0.0954, 0.0954, 0.2725)]
    db_name = "test_db_binary_almg.db"
    basis_elements = [["Al", "Mg"], ["Al", "Mg"], ["Al", "Mg"], ["Al", "Mg"]]
    max_dia = get_max_cluster_dia_name()
    size_arg = {max_dia: 4.1}
    conc = Concentration(basis_elements=basis_elements,
                         grouped_basis=[[0, 1, 2, 3]])
    bs = CECrystal(concentration=conc,
                   basis=basis,
                   spacegroup=217,
                   cellpar=cellpar,
                   max_cluster_size=3,
                   db_name=db_name,
                   size=[1, 1, 1],
                   **size_arg)
    return bs, db_name
def init_bc(N):
    conc_args = {
        "conc_ratio_min_1": [[64, 0, 0]],
        "conc_ratio_max_1": [[24, 40, 0]],
        "conc_ratio_min_2": [[64, 0, 0]],
        "conc_ratio_max_2": [[22, 21, 21]]
    }
    conc = Concentration(basis_elements=[["Al", "Mg", "Si"]])

    kwargs = {
        "crystalstructure": "fcc",
        "a": 4.05,
        "size": [4, 4, 4],
        "concentration": conc,
        "db_name": "data/almgsi.db",
        "max_cluster_size": 4
    }

    ceBulk = BulkCrystal(**kwargs)
    eci_file = "data/almgsi_fcc_eci_newconfig.json"
    with open(eci_file, 'r') as infile:
        ecis = json.load(infile)
    db_name = "large_cell_db{}x{}x{}.db".format(N, N, N)
    calc = get_ce_calc(ceBulk, kwargs, ecis, size=[N, N, N], db_name=db_name)
    ceBulk = calc.BC
    ceBulk.atoms.set_calculator(calc)
    return ceBulk
Ejemplo n.º 4
0
def atoms_with_calc(N):
    conc = Concentration(basis_elements=[["Al", "Mg", "Si"]])

    kwargs = {
        "crystalstructure": "fcc",
        "a": 4.05,
        "size": [4, 4, 4],
        "concentration": conc,
        "db_name": "data/almgsi_10dec.db",
        "max_cluster_size": 4
    }

    ceBulk = CEBulk(**kwargs)
    eci_file = "data/almgsi_fcc_eci_newconfig_dec10.json"
    with open(eci_file, 'r') as infile:
        ecis = json.load(infile)
    db_name = "large_cell_db{}x{}x{}_dec10.db".format(N, N, N)
    #ecis = {"c1_0": 1.0}
    atoms = get_atoms_with_ce_calc(ceBulk, kwargs, ecis, size=[N, N, N], db_name=db_name)

    symbs = [atom.symbol for atom in atoms]
    diag = atoms.get_cell().T.dot([0.5, 0.5, 0.5])
    pos = atoms.get_positions() - diag
    lengths = np.sum(pos**2, axis=1)
    indx = np.argmin(lengths)
    symbs[indx] = "Mg"
    atoms.get_calculator().set_symbols(symbs)
    return atoms
    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
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
    def test_network(self):
        if (not available):
            self.skipTest("ASE version does not have CE!")
            return

        msg = ""
        no_throw = True
        try:
            db_name = "test_db_network.db"

            conc = Concentration(basis_elements=[["Al", "Mg"]])
            a = 4.05
            ceBulk = CEBulk(crystalstructure="fcc",
                            a=a,
                            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)
            atoms = ceBulk.atoms.copy()
            cf = cf.get_cf(atoms)
            eci = {key: 0.001 for key in cf.keys()}
            calc = CE(atoms, ceBulk, eci=eci)
            trans_mat = ceBulk.trans_matrix

            for name, info in ceBulk.cluster_info[0].items():
                if info["size"] == 2:
                    net_name = name
                    break
            obs = NetworkObserver(calc=calc,
                                  cluster_name=[net_name],
                                  element=["Mg"])

            # Several hard coded tests
            calc.update_cf((0, "Al", "Mg"))
            size = 2
            clusters = ceBulk.cluster_info[0][net_name]["indices"]
            for sub_clust in clusters:
                calc.update_cf((sub_clust[0], "Al", "Mg"))
                # Call the observer
                obs(None)

                res = obs.fast_cluster_tracker.get_cluster_statistics_python()
                self.assertEqual(res["cluster_sizes"][0], size)
                size += 1
            obs.get_indices_of_largest_cluster_with_neighbours()
            os.remove("test_db_network.db")

        except Exception as exc:
            msg = "{}: {}".format(type(exc).__name__, str(exc))
            no_throw = False
        self.assertTrue(no_throw, msg=msg)
Ejemplo n.º 8
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
Ejemplo n.º 9
0
def get_ternary_BC(ret_args=False):
    db_name = "test_db_ternary.db"
    max_dia = get_max_cluster_dia_name()
    size_arg = {max_dia: 4.05}
    conc = Concentration(basis_elements=[["Al", "Mg", "Si"]])
    args = dict(crystalstructure="fcc", a=4.05, size=[4,4,4], concentration=conc, \
                db_name=db_name, max_cluster_size=3, **size_arg)
    ceBulk = CEBulk(**args)
    ceBulk.reconfigure_settings()
    if ret_args:
        return ceBulk, args
    return ceBulk
Ejemplo n.º 10
0
def get_small_BC_with_ce_calc(lat="fcc"):
    db_name = "test_db_{}.db".format(lat)

    a = 4.05
    conc = Concentration(basis_elements=[["Al", "Mg"]])
    ceBulk = CEBulk( crystalstructure=lat, a=a, 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)
    corrfuncs = cf.get_cf(ceBulk.atoms)
    eci = {name: 1.0 for name in corrfuncs.keys()}
    calc = CE(ceBulk.atoms.copy(), ceBulk, eci)
    #ceBulk.atoms.set_calculator(calc)
    return ceBulk, calc
Ejemplo n.º 11
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
Ejemplo n.º 12
0
    def test_no_throw(self):
        if (not has_CE):
            self.skipTest("ASE version does not have ASE")
            return
        no_throw = True
        msg = ""
        try:
            conc_args = {
                "conc_ratio_min_1": [[1, 0]],
                "conc_ratio_max_1": [[0, 1]],
            }
            conc = Concentration(basis_elements=[["Al", "Mg"]])
            kwargs = {
                "crystalstructure": "fcc",
                "a": 4.05,
                "size": [3, 3, 3],
                "concentration": conc,
                "db_name": "temporary_bcnucleationdb.db",
                "max_cluster_size": 3,
                "max_cluster_dia": 4.5
            }
            ceBulk = CEBulk(**kwargs)
            cf = CorrFunction(ceBulk)
            cf_dict = cf.get_cf(ceBulk.atoms)
            ecis = {key: 1.0 for key, value in cf_dict.items()}

            #calc = CE( ceBulk, ecis, size=(3,3,3) )
            atoms = get_atoms_with_ce_calc(ceBulk,
                                           kwargs,
                                           ecis,
                                           size=[6, 6, 6],
                                           db_name="sc6x6x6.db")
            chem_pot = {"c1_0": -1.069}

            T = 300
            mc = SGCFreeEnergyBarrier( atoms, T, symbols=["Al","Mg"], \
            n_windows=5, n_bins=10, min_singlet=0.5, max_singlet=1.0 )
            mc.run(nsteps=100, chem_pot=chem_pot)
            mc.save(fname="free_energy_barrier.json")

            # Try to load the object stored
            mc = SGCFreeEnergyBarrier.load(atoms, "free_energy_barrier.json")
            mc.run(nsteps=100, chem_pot=chem_pot)
            mc.save(fname="free_energy_barrier.json")
            os.remove("sc6x6x6.db")
        except Exception as exc:
            msg = str(exc)
            no_throw = False
        self.assertTrue(no_throw, msg=msg)
Ejemplo n.º 13
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
Ejemplo n.º 14
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)
Ejemplo n.º 15
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
Ejemplo n.º 16
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:
                a = 4.05
                mx_dia_name = get_max_cluster_dia_name()
                size_arg = {mx_dia_name:a}
                conc = Concentration(basis_elements=[basis_elems])
                ceBulk = CEBulk( crystalstructure="fcc", a=a, size=[5, 5, 5], concentration=conc, \
                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()}
                atoms = ceBulk.atoms.copy()
                calc = CE(atoms, 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 )
Ejemplo n.º 17
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"
        max_dia = get_max_cluster_dia_name()
        size_arg = {max_dia: 4.05}
        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=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()}
        atoms = ceBulk.atoms.copy()
        calc = CE(atoms, ceBulk, eci )
        atoms.set_calculator(calc)
        n_tests = 10

        # Insert 25 Mg atoms and 25 Si atoms
        n = 18
        for i in range(n):
            calc.calculate( atoms, ["energy"], [(i,"Al","Mg")])
            calc.calculate( atoms, ["energy"], [(i+n,"Al","Si")])
            updated_cf = calc.get_cf()
            brute_force = corr_func.get_cf_by_cluster_names( 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(atoms))
            symb1 = atoms[indx1].symbol
            indx2 = indx1
            symb2 = symb1
            while( symb2 == symb1 ):
                indx2 = np.random.randint( low=0, high=len(ceBulk.atoms) )
                symb2 = atoms[indx2].symbol
            calc.calculate( atoms, ["energy"], [(indx1,symb1,symb2),(indx2,symb2,symb1)])
            update_cf = calc.get_cf()
            brute_force = corr_func.get_cf_by_cluster_names( atoms, update_cf.keys() )
            for key,value in brute_force.items():
                self.assertAlmostEqual( value, update_cf[key])
Ejemplo n.º 18
0
def sa_fcc(au_comp):
    basis_elements = basis_elements = [['Cu', 'Au']]
    conc = Concentration(basis_elements=basis_elements)

    kwargs_fcc = {
        "crystalstructure": 'fcc',
        "a": 3.8,
        "size": [3, 3, 3],
        "concentration": conc,
        "db_name": 'cu-au_quad.db',
        "max_cluster_size": 4,
        "max_cluster_dia": 6.0,
        "cubic": False
        }
        
    with open("data/cluster_eci.json") as infile:
        eci = json.load(infile)
    print(eci)
    db_name = "data/cu-au3_lowstep.db"
    sa(au_comp, kwargs_fcc, eci, db_name, [10, 10, 10])
Ejemplo n.º 19
0
    def test_supercell(self):
        if not has_ase_with_ce:
            self.skipTest("ASE version does not have CE")
            return

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

        conc = Concentration(basis_elements=[["Al", "Mg"]])
        kwargs = {
            "crystalstructure": "fcc",
            "a": 4.05,
            "size":[3, 3, 3],
            "concentration": conc,
            "db_name": db_name,
            "max_cluster_size": 3,
            "max_cluster_dia": 6.0
        }

        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()
        atoms_sc = get_atoms_with_ce_calc(ceBulk, kwargs, eci, size=[4, 4, 4],
                                          db_name="sc4x4x.db")
        calc_sc = atoms_sc.get_calculator()
        corr_func = CorrFunction(template_supercell_bc)
        for i in range(10):
            calc_sc.calculate(atoms_sc, ["energy"], [(i, "Al", "Mg")])
            updated_cf = calc_sc.get_cf()
            brute_force = corr_func.get_cf_by_cluster_names(
                atoms_sc, list(updated_cf.keys()))

            for key, value in brute_force.items():
                self.assertAlmostEqual(value, updated_cf[key])
        os.remove("sc4x4x.db")
Ejemplo n.º 20
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)
Ejemplo n.º 21
0
def get_ce_with_calc():
    conc = Concentration(basis_elements=[["Al", "Mg", "Si"]])
    kwargs = {
        "crystalstructure": "fcc",
        "a": 4.05,
        "size": [4, 4, 4],
        "concentration": conc,
        "db_name": DB_NAME,
        "max_cluster_size": 4
    }
    ceBulk = BulkCrystal(**kwargs)

    with open(ECI_FILE, 'r') as infile:
        ecis = json.load(infile)

    db_name = "large_cell_db10x10x10.db"
    calc = get_ce_calc(ceBulk,
                       kwargs,
                       ecis,
                       size=[10, 10, 10],
                       db_name=db_name)
    ceBulk = calc.BC
    ceBulk.atoms.set_calculator(calc)
    return ceBulk
Ejemplo n.º 22
0
    def test_no_throw(self):
        if not available:
            self.skipTest("ASE version does not have CE!")
            return
        no_throw = True
        msg = ""
        try:
            db_name = "temp_nuc_db.db"
            if os.path.exists(db_name):
                os.remove(db_name)
            conc = Concentration(basis_elements=[["Al", "Mg"]])
            kwargs = {
                "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 = CEBulk(**kwargs)
            ceBulk.reconfigure_settings()
            cf = CorrFunction(ceBulk)
            cf = cf.get_cf(ceBulk.atoms)

            ecis = {key: 0.001 for key in cf.keys()}
            atoms = get_atoms_with_ce_calc(ceBulk, kwargs, ecis, size=[5, 5, 5],
                               db_name="sc5x5x5.db")

            chem_pot = {"c1_0": -1.0651526881167124}
            sampler = NucleationSampler(
                size_window_width=10,
                chemical_potential=chem_pot, max_cluster_size=20,
                merge_strategy="normalize_overlap")

            nn_name = get_network_name(ceBulk.cluster_family_names_by_size)
            mc = SGCNucleation(
                atoms, 30000, nucleation_sampler=sampler,
                network_name=[nn_name],  network_element=["Mg"],
                symbols=["Al", "Mg"], chem_pot=chem_pot)
            mc.runMC(steps=2, equil=False)
            sampler.save(fname="test_nucl.h5")

            mc = CanonicalNucleationMC(
                atoms, 300, nucleation_sampler=sampler,
                network_name=[nn_name],  network_element=["Mg"],
                concentration={"Al": 0.8, "Mg": 0.2}
                )
            symbs = [atom.symbol for atom in atoms]
            symbs[0] = "Mg"
            symbs[1] = "Mg"
            mc.set_symbols(symbs)
            #mc.runMC(steps=2)
            sampler.save(fname="test_nucl_canonical.h5")
            elements = {"Mg": 6}
            calc = atoms.get_calculator()
            calc.set_composition({"Al": 1.0, "Mg": 0.0})
            mc = FixedNucleusMC(atoms, 300,
                                network_name=[nn_name], network_element=["Mg"])
            mc.insert_symbol_random_places("Mg", num=1, swap_symbs=["Al"])
            mc.runMC(steps=2, elements=elements, init_cluster=True)
            os.remove("sc5x5x5.db")
        except Exception as exc:
            msg = str(exc)
            msg += "\n" + traceback.format_exc()
            no_throw = False
        self.assertTrue(no_throw, msg=msg)
Ejemplo n.º 23
0
    from cemc.wanglandau import WangLandauInit, WangLandau, WangLandauDBManager
    from cemc.wanglandau import AtomExistsError
    has_CE = True
except Exception as exc:
    print(exc)
    has_CE = False

    # Define a dummy class in case of import error
    class Concentration(object):
        def __init__(self, basis_elements=None):
            pass


db_name = "temp_db_wanglandau.db"
wl_db_name = "wanglandau_test_init.db"
conc = Concentration(basis_elements=[["Al", "Mg"]])
bc_kwargs = {
    "crystalstructure": "fcc",
    "size": [3, 3, 3],
    "concentration": conc,
    "db_name": db_name,
    "max_cluster_size": 3,
    "a": 4.05,
    "max_cluster_dia": 4.5
}


def get_eci():
    bc = CEBulk(**bc_kwargs)
    bc.reconfigure_settings()
    cf = CorrFunction(bc)
Ejemplo n.º 24
0
Features
1. Initialize a CEBulk object
2. Initialize a Cluster Expansion calculator
3. Initialize a the Monte Carlo object
4. Simple use of Monte Carlo observers
"""

# First we import the CEBulk object from ASE
from ase.clease import CEBulk
from ase.clease import Concentration
from util import get_example_ecis

# Initialize the CEBulk object for a 4x4x4 expansion of a
# primitive FCC unitcell
conc = Concentration([["Al", "Mg"]])
bc = CEBulk(crystalstructure="fcc",
            a=4.05,
            db_name="test_gs_db.db",
            size=[3, 3, 3],
            concentration=conc,
            max_cluster_size=3,
            max_cluster_dia=4.5)
bc.reconfigure_settings()  # Nessecary for unittests to pass

# Just use some example ECIs
eci = get_example_ecis(bc=bc)

# Initialize a Cluster Expansion calculator (C++ version is required)
from cemc import CE
atoms = bc.atoms.copy()