Exemple #1
0
    def test_chemical_potential(self):
        if not available:
            self.skipTest(avail_msg)

        bc = get_ternary_BC()
        ecis = {"c1_0": 0.0, "c1_1": 0.0}
        atoms = bc.atoms.copy()
        bf = bc.basis_functions
        calc = CE(atoms, bc, eci=ecis)

        groups = [{"Al": 2}, {"Mg": 1, "Si": 1}]
        symbs = ["Al", "Mg", "Si"]
        T = 400
        chem_pots = [-0.2, -0.1, 0.0, 0.1, 0.2, 1.0]
        all_al = ["Al" for _ in range(len(atoms))]
        num_atom_per_fu = 2
        for mu in chem_pots:
            calc.set_symbols(all_al)
            mc = PseudoBinarySGC(atoms,
                                 T,
                                 chem_pot=mu,
                                 symbols=symbs,
                                 groups=groups)

            # At this point the chemical potentials should
            # be updated
            changes = [(0, "Al", "Mg"), (1, "Al", "Si")]
            energy = calc.get_energy()
            for change in changes:
                calc.update_cf(change)

            new_energy = calc.get_energy()
            self.assertAlmostEqual(new_energy - energy, mu)
            mc.reset_ecis()
def thermodynamic_integration(phase):
    alat = 3.8
    conc_args = {}
    conc_args['conc_ratio_min_1'] = [[1, 0]]
    conc_args['conc_ratio_max_1'] = [[0, 1]]
    kwargs = {
        "crystalstructure": 'fcc',
        "a": 3.8,
        "size": [10, 10, 10],
        "basis_elements": [['Cu', 'Au']],
        "conc_args": conc_args,
        "db_name": 'temp_sgc.db',
        "max_cluster_size": 3,
        "max_cluster_dist": 1.5 * alat
    }
    bc1 = BulkCrystal(**kwargs)
    bf = bc1._get_basis_functions()[0]

    with open("data/eci_aucu.json", 'r') as infile:
        eci = json.load(infile)

    db = dataset.connect("sqlite:///{}".format(canonical_db))
    tbl = db["corrfunc"]
    if phase == "Au" or phase == "Cu":
        atoms1 = bc1.atoms
        for atom in atoms1:
            atom.symbol = phase
        cf1 = get_pure_cf(eci, bf[phase])
    else:
        atoms = read(phase)
        row = tbl.find_one(runID=gs[phase])
        row.pop("id")
        row.pop("runID")
        cf1 = row
    # TODO: Fix this when running with a pure phase
    symbs = [atom.symbol for atom in atoms]

    cf1 = get_pure_cf(eci, bf[bc1.atoms[0].symbol])
    atoms = bc1.atoms
    calc = CE(bc1, eci=eci, initial_cf=cf1)
    calc.set_symbols(symbs)
    atoms.set_calculator(calc)

    sgc_db = dataset.connect("sqlite:///{}".format(sgc_db_name))
    tbl = sgc_db["results"]
    tbl_cf = sgc_db["corr_func"]
    mu = 0.223
    nsteps = 100 * len(atoms)
    equil_param = {"mode": "fixed", "maxiter": 10 * len(atoms)}
    order_param = SiteOrderParameter(atoms)
    T = np.linspace(100, 600, 40)
    # mu = np.linspace(0.223, 0.19, 20).tolist()
    mu = [0.223]
    for temp in T:
        for m in mu:
            chemical_potential = {"c1_0": m}
            # mc = SGCMonteCarlo(atoms, temp, mpicomm=comm, symbols=["Au", "Cu"])
            mc = Montecarlo(atoms, temp)
            mc.attach(order_param)
            init_formula = atoms.get_chemical_formula()
            # mc.runMC(steps=nsteps, equil_params=equil_param,
            #          chem_potential=chemical_potential)
            mc.runMC(steps=nsteps, equil_params=equil_param)
            # thermo = mc.get_thermodynamic(reset_ecis=True)
            thermo = mc.get_thermodynamic()
            thermo["init_formula"] = init_formula
            thermo["final_formula"] = atoms.get_chemical_formula()
            avg, std = order_param.get_average()
            thermo["order_avg"] = avg
            thermo["order_std"] = std
            thermo["valid"] = True
            thermo["integration_path"] = "NN"
            if rank == 0:
                uid = tbl.insert(thermo)
                cf = calc.get_cf()
                cf["runID"] = uid
                tbl_cf.insert(cf)