Exemplo n.º 1
0
    def test_gs_finder(self):
        if (not has_CE):
            self.skipTest("ASE version does not have CE")
            return
        no_throw = True
        msg = ""
        try:
            db_name = "test_db_gsfinder.db"

            conc_args = {
                "conc_ratio_min_1": [[1, 0]],
                "conc_ratio_max_1": [[0, 1]],
            }
            a = 4.05
            ceBulk = CEBulk( crystalstructure="fcc", a=a, size=[3,3,3], basis_elements=[["Al","Mg"]], conc_args=conc_args, \
            db_name=db_name, max_cluster_size=4)
            cf = CorrFunction(ceBulk)
            cf = cf.get_cf(ceBulk.atoms)
            eci = {key: 1.0 for key in cf.keys()}
            gsfinder = GSFinder()
            comp = {"Al": 0.5, "Mg": 0.5}
            gsfinder.get_gs(ceBulk, eci, composition=comp)
        except Exception as exc:
            msg = str(exc)
            no_throw = False
        self.assertTrue(no_throw, msg=msg)
Exemplo n.º 2
0
def get_eci():
    bc = CEBulk(**bc_kwargs)
    bc.reconfigure_settings()
    cf = CorrFunction(bc)
    cf = cf.get_cf(bc.atoms)
    eci = {key: 0.001 for key in cf.keys()}
    return eci
Exemplo n.º 3
0
def insert_specific_structure(ceBulk, struct_gen, atoms):
    cf = CorrFunction(ceBulk)
    kvp = cf.get_cf(atoms)
    conc = struct_gen.find_concentration(atoms)
    print(conc)
    if (struct_gen.exists_in_db(atoms, conc[0], conc[1])):
        raise RuntimeError(
            "The passed structure already exists in the database")
    kvp = struct_gen.get_kvp(atoms, kvp, conc[0], conc[1])
    struct_gen.setting.db.write(atoms, kvp)
Exemplo n.º 4
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)
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
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]],
            }
            kwargs = {
                "crystalstructure": "fcc",
                "a": 4.05,
                "size": [3, 3, 3],
                "basis_elements": [["Al", "Mg"]],
                "conc_args": conc_args,
                "db_name": "temporary_bcnucleationdb.db",
                "max_cluster_size": 3
            }
            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) )
            calc = get_ce_calc(ceBulk,
                               kwargs,
                               ecis,
                               size=[6, 6, 6],
                               db_name="sc6x6x6.db")
            ceBulk = calc.BC
            ceBulk.atoms.set_calculator(calc)
            chem_pot = {"c1_0": -1.069}

            T = 300
            mc = SGCFreeEnergyBarrier( ceBulk.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(ceBulk.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)
Exemplo n.º 8
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
Exemplo n.º 9
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)
Exemplo n.º 10
0
def get_small_BC_with_ce_calc(lat="fcc"):
    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 )
    ceBulk.atoms.set_calculator(calc)
    return ceBulk
Exemplo n.º 11
0
    def test_no_throw(self):
        no_throw = True
        if not available:
            self.skipTest(reason)
            return
        msg = ""
        # try:
        conc_args = {
            "conc_ratio_min_1": [[1, 0]],
            "conc_ratio_max_1": [[0, 1]],
        }
        kwargs = {
            "crystalstructure": "fcc",
            "a": 4.05,
            "size": [4, 4, 4],
            "basis_elements": [["Al", "Mg"]],
            "conc_args": conc_args,
            "db_name": "data/temporary_bcnucleationdb.db",
            "max_cluster_size": 3
        }
        ceBulk = CEBulk(**kwargs)
        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 = calc.BC
        ceBulk.atoms.set_calculator(calc)

        T = 500
        c_mg = 0.4
        comp = {"Mg": c_mg, "Al": 1.0 - c_mg}
        calc.set_composition(comp)
        act_sampler = ActivitySampler(ceBulk.atoms,
                                      T,
                                      moves=[("Al", "Mg")],
                                      mpicomm=comm)
        act_sampler.runMC(mode="fixed", steps=1000)
        act_sampler.get_thermodynamic()
        # except Exception as exc:
        #     msg = str(exc)
        #     no_throw = False
        self.assertTrue(no_throw, msg=msg)
Exemplo n.º 12
0
def get_example_ecis(bc=None,bc_kwargs=None):
    if ( bc is not None ):
        cf = CorrFunction(bc)
    else:
        bc = CEBulk(**bc_kwargs)
        cf = CorrFunction(bc)
    cf = cf.get_cf(bc.atoms)
    eci = {key: 0.001 for key in cf.keys()}
    return eci
Exemplo n.º 13
0
def get_example_ecis(bc=None):
    cf = CorrFunction(bc)
    cf = cf.get_cf(bc.atoms)
    eci = {key: 0.001 for key in cf.keys()}
    return eci
Exemplo n.º 14
0
def get_example_cf(bc=None, atoms=None):
    cf = CorrFunction(bc)
    cf = cf.get_cf(atoms)
    return cf
Exemplo n.º 15
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)