Ejemplo n.º 1
0
def init_BC():
    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]]
    }
    orig_spin_dict = {"Mg": 1.0, "Si": -1.0, "Al": 0.0}

    kwargs = {
        "crystalstructure": "fcc",
        "a": 4.05,
        "size": [4, 4, 4],
        "basis_elements": [["Mg", "Si", "Al"]],
        "conc_args": conc_args,
        "db_name": "data/almgsi.db",
        "max_cluster_size": 4
    }
    ceBulk = BulkCrystal(**kwargs)
    ceBulk.spin_dict = orig_spin_dict
    ceBulk.basis_functions = ceBulk._get_basis_functions()
    ceBulk._get_cluster_information()
    eci_file = "data/almgsi_fcc_eci.json"
    with open(eci_file, 'r') as infile:
        ecis = json.load(infile)
    print(ecis)
    #calc = CE( ceBulk, ecis, size=(3,3,3) )
    calc = get_ce_calc(ceBulk, kwargs, ecis, size=[10, 10, 10])
    ceBulk = calc.BC
    ceBulk.atoms.set_calculator(calc)
    return ceBulk
def run(T, mg_conc, si_conc, precs):
    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]]
    }
    orig_spin_dict = {
        "Mg": 1.0,
        "Si": -1.0,
        "Al": 0.0
    }

    kwargs = {
        "crystalstructure": "fcc",
        "a": 4.05,
        "size": [4, 4, 4],
        "basis_elements": [["Mg", "Si", "Al"]],
        "conc_args": conc_args,
        "db_name": "data/almgsi.db",
        "max_cluster_size": 4
    }
    ceBulk = BulkCrystal(**kwargs)
    ceBulk.spin_dict = orig_spin_dict
    ceBulk.basis_functions = ceBulk._get_basis_functions()
    ceBulk._get_cluster_information()
    eci_file = "data/almgsi_fcc_eci.json"
    with open(eci_file, 'r') as infile:
        ecis = json.load(infile)
    print(ecis)
    #calc = CE( ceBulk, ecis, size=(3,3,3) )
    calc = get_ce_calc(ceBulk, kwargs, ecis, size=[10, 10, 10])
    ceBulk = calc.BC
    ceBulk.atoms.set_calculator(calc)

    comp = {
        "Mg": mg_conc,
        "Si": si_conc,
        "Al": 1.0 - mg_conc - si_conc
    }
    calc.set_composition(comp)
    for temp, prec in zip(T, precs):
        print("Current temperature {}K".format(temp))
        mc_obj = Montecarlo(ceBulk.atoms, temp, mpicomm=comm)
        mode = "prec"
        mc_obj.runMC(mode=mode, prec=prec)
        thermo = mc_obj.get_thermodynamic()
        thermo["temperature"] = temp
        thermo["prec"] = prec
        thermo["internal_energy"] = thermo.pop("energy")
        thermo["converged"] = True
        thermo["prec"] = prec

        if (rank == 0):
            db = dataset.connect("sqlite:///{}".format(mc_db_name))
            tbl = db["results"]
            thermo["sysID"] = sysID
            tbl.insert(thermo)
Ejemplo n.º 3
0
def main():
    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": 4
    }
    ceBulk = BulkCrystal(**kwargs)
    print(ceBulk.basis_functions)

    eci_file = "data/ce_hydrostatic.json"
    with open(eci_file, 'r') as infile:
        ecis = json.load(infile)
    print(ecis)
    #calc = CE( ceBulk, ecis, size=(3,3,3) )
    calc = get_ce_calc(ceBulk,
                       kwargs,
                       ecis,
                       size=[10, 10, 10],
                       free_unused_arrays_BC=True)
    ceBulk = calc.BC
    ceBulk.atoms.set_calculator(calc)

    T = 500
    temps = [200, 300, 400, 500, 600, 700, 800]
    mg_concs = [
        0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4,
        0.45, 0.5, 0.55, 0.6, 0.65, 0.70, 0.75, 0.8, 0.85, 0.9
    ]
    mg_concs = np.linspace(0.005, 0.995, 100)
    act_coeffs = []
    eff_conc = []
    for T in temps:
        for c_mg in mg_concs:
            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=100000)
            thermo = act_sampler.get_thermodynamic()
            act_sampler.save(
                fname="data/effective_concentration_full_range.db")
Ejemplo n.º 4
0
def main():
    conc_args = {
        "conc_ratio_min_1": [[1, 0]],
        "conc_ratio_max_1": [[0, 1]],
    }
    #with open(bc_filename,'rb') as infile:
    #    ceBulk = pck.load(infile)
    kwargs = {
        "crystalstructure": "fcc",
        "a": 4.05,
        "size": [4, 4, 4],
        "basis_elements": [["Al", "Mg"]],
        "conc_args": conc_args,
        "db_name": "dos-db.db",
        "max_cluster_size": 4
    }
    ceBulk = BulkCrystal(**kwargs)
    print(ceBulk.basis_functions)

    eci_file = "data/ce_hydrostatic.json"
    with open(eci_file, 'r') as infile:
        ecis = json.load(infile)
    print(ecis)
    #calc = CE( ceBulk, ecis, size=(3,3,3) )
    calc = get_ce_calc(ceBulk, kwargs, ecis, size=[10, 10, 10])
    ceBulk = calc.BC
    ceBulk.atoms.set_calculator(calc)
    print("Number of atoms: {}".format(len(ceBulk.atoms)))

    T = 300
    dos = SGCCompositionFreeEnergy(nbins=10000,
                                   hist_limits=[("c1_0", 0.45, 1.0)])
    mc = sgc.SGCMonteCarlo(ceBulk.atoms, T, symbols=["Al", "Mg"])
    mc.chemical_potential = {"c1_0": -1.066}
    if (run_array):
        T = [
            150, 200, 250, 300, 350, 375, 390, 400, 410, 420, 430, 440, 450,
            460, 470
        ]
        mus = np.linspace(-1.064, -1.069, 10)
        mu = [{"c1_0": value} for value in mus]
        array_runner = FreeEnergyMuTempArray(
            T, mu, fname="data/free_energy_al_rich.h5")
        array_runner.run(mc, dos, min_num_steps=100000)
    else:
        comp_free_eng = dos.find_dos(mc,
                                     min_num_steps=500000,
                                     max_rel_unc=0.01)
        comp_free_eng.plot()
        plt.show()
Ejemplo n.º 5
0
def run(maxT, minT, n_temp, mg_conc):
    T = np.linspace(minT, maxT, n_temp)[::-1]
    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_bcdb.db",
        "max_cluster_size": 4
    }
    ceBulk = BulkCrystal(**kwargs)
    print(ceBulk.basis_functions)

    eci_file = "data/ce_hydrostatic.json"
    with open(eci_file, 'r') as infile:
        ecis = json.load(infile)
    print(ecis)
    #calc = CE( ceBulk, ecis, size=(3,3,3) )
    calc = get_ce_calc(ceBulk, kwargs, ecis, size=[10, 10, 10])
    ceBulk = calc.BC
    ceBulk.atoms.set_calculator(calc)
    comp = {"Al": 1.0 - mg_conc, "Mg": mg_conc}
    calc.set_composition(comp)
    print("Number of atoms: {}".format(len(ceBulk.atoms)))
    for temp in T:
        print("Current temperature {}K".format(temp))
        mc_obj = Montecarlo(ceBulk.atoms, temp, mpicomm=comm)
        mode = "prec"
        prec = 1E-5
        mc_obj.runMC(mode=mode, prec=prec)
        thermo = mc_obj.get_thermodynamic()
        thermo["temperature"] = temp
        thermo["prec"] = prec
        thermo["internal_energy"] = thermo.pop("energy")
        thermo["converged"] = True

        if (rank == 0):
            db = connect(mc_db_name)
            db.write(ceBulk.atoms, key_value_pairs=thermo)
def main():
    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": 4
    }
    ceBulk = BulkCrystal(**kwargs)
    print(ceBulk.basis_functions)

    eci_file = "data/ce_hydrostatic.json"
    with open(eci_file, 'r') as infile:
        ecis = json.load(infile)
    print(ecis)
    #calc = CE( ceBulk, ecis, size=(3,3,3) )
    calc = get_ce_calc(ceBulk,
                       kwargs,
                       ecis,
                       size=[10, 10, 10],
                       free_unused_arrays_BC=True)
    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=20, n_bins=10, min_singlet=0.5, max_singlet=1.0, mpicomm=comm )
    mc = SGCFreeEnergyBarrier.load(ceBulk.atoms,
                                   "data/free_energy_barrier_restart.json",
                                   mpicomm=comm)
    #mc.run( nsteps=100000, chem_pot=chem_pot )
    #mc.save( fname="data/free_energy_barrier_restart.json" )
    mc.plot(fname="data/free_energy_barrier_restart.json")
    plt.show()
Ejemplo n.º 7
0
def main():
    chem_pots = {"c1_0": -1.067}

    conc_args = {
        "conc_ratio_min_1": [[1, 0]],
        "conc_ratio_max_1": [[0, 1]],
    }
    #with open(bc_filename,'rb') as infile:
    #    ceBulk = pck.load(infile)
    kwargs = {
        "crystalstructure": "fcc",
        "a": 4.05,
        "size": [4, 4, 4],
        "basis_elements": [["Al", "Mg"]],
        "conc_args": conc_args,
        "db_name": "random_test.db",
        "max_cluster_size": 4
    }
    ceBulk = BulkCrystal(**kwargs)
    print(ceBulk.basis_functions)

    eci_file = "../data/ce_hydrostatic.json"
    with open(eci_file, 'r') as infile:
        ecis = json.load(infile)
    print(ecis)
    #calc = CE( ceBulk, ecis, size=(3,3,3) )
    calc = get_ce_calc(ceBulk, kwargs, ecis, size=[10, 10, 10])
    ceBulk = calc.BC
    ceBulk.atoms.set_calculator(calc)
    print("Number of atoms: {}".format(len(ceBulk.atoms)))
    mc = SGCMonteCarlo(ceBulk.atoms, 100000, symbols=["Al", "Mg"])
    mc.chemical_potential = chem_pots
    dn_sampler = DNSampler(mc_sampler=mc)
    dnest4_args = {"max_num_levels": 50, "lam": 10}
    dn_sampler.run(dnest4_args=dnest4_args)
    dn_sampler.make_histograms(bins=100)
    plt.show()
Ejemplo n.º 8
0
def run(T,mg_conc):
    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_bcdb.db",
        "max_cluster_size":4
    }
    ceBulk = BulkCrystal( **kwargs )
    print (ceBulk.basis_functions)

    eci_file = "data/ce_hydrostatic.json"
    with open( eci_file, 'r' ) as infile:
        ecis = json.load( infile )
    print (ecis)
    #calc = CE( ceBulk, ecis, size=(3,3,3) )
    calc = get_ce_calc( ceBulk, kwargs, ecis, size=[10,10,10], free_unused_arrays_BC=True )
    ceBulk = calc.BC
    ceBulk.atoms.set_calculator( calc )
    comp = {
        "Al":1.0-mg_conc,
        "Mg":mg_conc
    }
    calc.set_composition(comp)
    mc_obj = Montecarlo( ceBulk.atoms, T, mpicomm=comm )
    pairs = PairCorrelationObserver( calc )
    network = NetworkObserver( calc=calc, cluster_name="c2_1414_1", element="Mg", nbins=100 )
    mode = "fixed"
    camera = Snapshot( "data/precipitation.traj", atoms=ceBulk.atoms )
    mc_obj.attach( camera, interval=10000 )
    mc_obj.attach( pairs, interval=1 )
    mc_obj.attach( network, interval=500 )
    mc_obj.runMC( mode=mode, steps=10000, equil=True )

    pair_mean = pairs.get_average()
    pair_std = pairs.get_std()

    if ( rank == 0 ):
        data = {
            "pairs":pair_mean,
            "pairs_std":pair_std,
            "mg_conc":mg_conc,
            "temperature":T
        }
        pairfname = "data/precipitation_pairs/precipitation_pairs_{}_{}K.json".format(int(1000*mg_conc),int(T))
        with open(pairfname,'w') as outfile:
            json.dump(data,outfile,indent=2, separators=(",",":"))
        print ( "Thermal averaged pair correlation functions written to {}".format(pairfname) )
        atoms = network.get_atoms_with_largest_cluster()

    data = network.get_statistics() # This collects the histogram data from all processors
    size,occurence = network.get_size_histogram()
    data["histogram"] = {}
    data["histogram"]["size"] = size.tolist()
    data["histogram"]["occurence"] = occurence.tolist()
    data["temperature"] = T
    data["mg_conc"] = mg_conc

    cluster_fname = "data/cluster_statistics_{}_{}K.json".format(int(1000*mg_conc),int(T))
    atoms_fname = "data/largest_cluster_{}_{}K.cif".format( int(1000*mg_conc), int(T) )

    if ( rank == 0 ):
        print (occurence)

    if ( rank == 0 ):
        try:
            with open( cluster_fname,'r') as infile:
                data = json.load(infile)
            old_size = np.array(data["histogram"]["size"])
            old_hist = np.array(data["histogram"]["occurence"])
            if ( np.allclose(old_size,size) ):
                occurence += old_hist
                data["histogram"]["occurence"] = occurence.tolist()
        except Exception as exc:
            print (str(exc))

        with open( cluster_fname, 'w' ) as outfile:
            json.dump( data, outfile, indent=2, separators=(",",":") )
        print ("Cluster statistics written to {}".format(cluster_fname) )
        write( atoms_fname, atoms )
        print ("Atoms with largest cluster written to {}".format(atoms_fname))
    #view(atoms)
    #plt.plot( network.size_histogram, ls="steps")
    #plt.show()
    print ("Proc: {} reached final barrier".format(rank))
    comm.barrier()
Ejemplo n.º 9
0
def run(mg_conc):
    bs_kwargs = {
        "conc_args": {
            "conc_ratio_min_1": [[1, 0]],
            "conc_ratio_max_1": [[0, 1]]
        },
        "basis_elements": [["Al", "Mg"], ["Al", "Mg"], ["Al", "Mg"],
                           ["Al", "Mg"]],
        "cellpar": [10.553, 10.553, 10.553, 90, 90, 90],
        "basis": [(0, 0, 0), (0.324, 0.324, 0.324), (0.3582, 0.3582, 0.0393),
                  (0.0954, 0.0954, 0.2725)],
        "spacegroup":
        217,
        "max_cluster_size":
        4,
        "db_name":
        "trial_217.db",
        "size": [1, 1, 1],
        "grouped_basis": [[0, 1, 2, 3]]
    }
    bs = BulkSpacegroup(**bs_kwargs)
    eci_file = "data/almg_217_eci.json"
    with open(eci_file, 'r') as infile:
        ecis = json.load(infile)
    calc = get_ce_calc(bs, bs_kwargs, ecis, size=[3, 3, 3])
    bs = calc.BC
    bs.atoms.set_calculator(calc)
    comp = {"Al": 1.0 - mg_conc, "Mg": mg_conc}

    calc.set_composition(comp)
    print("Number of atoms: {}".format(len(bs.atoms)))
    high_temps = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000]
    low_temps = range(200, 1000, 50)[::-1]
    T = np.array(high_temps + low_temps)
    #T = np.array([10000,9000,8000,7000,6000,5000,4000,3000,2000,1000,800,700,600,500,400,375,350,325,300,275,250,225,200,175,150])
    #T = np.array([1E6,100000])
    precs = np.zeros(len(T)) + 1E-4
    #precs[T<=500] = 1E-5
    print(bs.atoms.get_chemical_formula())
    mc_obj = Montecarlo(bs.atoms, T[0], mpicomm=comm)
    mc_obj.accept_first_trial_move_after_reset = False
    for prec, temp in zip(precs, T):
        mc_obj.T = temp
        mc_obj.reset()
        #if ( temp==T[0] ):
        #    mc_obj.is_first = False # Do not accept the first move

        print("Current temperature {}K".format(temp))
        mode = "fixed"
        mc_obj.runMC(mode=mode, prec=prec, steps=1000000)
        thermo = mc_obj.get_thermodynamic()
        thermo["temperature"] = temp
        thermo["prec"] = prec
        thermo["internal_energy"] = thermo.pop("energy")
        thermo["converged"] = True

        if (rank == 0):
            cf = calc.get_cf()
            db = connect(mc_db_name)
            thermo.update(cf)
            db.write(bs.atoms, key_value_pairs=thermo)

    if (rank == 0 and run_mfa):
        # At this point a ground state should have been reached
        mfa = CanonicalMeanField(atoms=bs.atoms, T=T)
        mfa.relax()
        res = mfa.calculate()
        formula = bs.atoms.get_chemical_formula()
        fname = "data/mfa217/{}mfa.json".format(formula)
        with open(fname, 'w') as outfile:
            json.dump(res, outfile, indent=2, separators=(",", ":"))
Ejemplo n.º 10
0
def run(mu, temps, save=False):
    chem_pots = {"c1_0": mu}
    linvib = LinearVibCorrection(vib_eci)

    conc_args = {
        "conc_ratio_min_1": [[1, 0]],
        "conc_ratio_max_1": [[0, 1]],
    }
    #with open(bc_filename,'rb') as infile:
    #    ceBulk = pck.load(infile)
    kwargs = {
        "crystalstructure": "fcc",
        "a": 4.05,
        "size": [4, 4, 4],
        "basis_elements": [["Al", "Mg"]],
        "conc_args": conc_args,
        "db_name": "random_test.db",
        "max_cluster_size": 4
    }
    ceBulk = BulkCrystal(**kwargs)
    print(ceBulk.basis_functions)

    eci_file = "data/ce_hydrostatic.json"
    with open(eci_file, 'r') as infile:
        ecis = json.load(infile)
    print(ecis)
    #calc = CE( ceBulk, ecis, size=(3,3,3) )
    calc = get_ce_calc(ceBulk, kwargs, ecis, size=[10, 10, 10])
    ceBulk = calc.BC
    ceBulk.atoms.set_calculator(calc)
    print("Number of atoms: {}".format(len(ceBulk.atoms)))
    #view(ceBulk.atoms)
    #exit()

    n_burn = 40000
    n_sample = 10000
    thermo = []
    #size = comm.Get_size()
    #n_per_proc = int( len(temps)/size )
    #if ( rank == comm.Get_size()-1 ):
    #    my_temps = temps[n_per_proc*rank:]
    #else:
    #    my_temps = temps[n_per_proc*rank:n_per_proc*(rank+1)]

    for T in temps:
        if (rank == 0):
            print("{}: Current temperature {}".format(rank, T))
        mc = sgc.SGCMonteCarlo(ceBulk.atoms,
                               T,
                               symbols=["Al", "Mg"],
                               mpicomm=comm)
        #mc.linear_vib_correction = linvib
        mc.runMC(steps=2000000, chem_potential=chem_pots, equil=False)
        exit()
        mc.runMC(mode="prec", chem_potential=chem_pots, prec=1E-4)
        if (rank == 0):
            print(mc.atoms._calc.eci["c1_0"])
        thermo_properties = mc.get_thermodynamic()
        thermo.append(thermo_properties)
        mc.reset()
        n_unreachable = gc.collect()
        print("GC number of unreachable: {}".format(n_unreachable))

    #all_thermos = []
    #all_thermos = comm.gather( thermo, root=0 )

    if ((rank == 0) and save):
        #thermo = []
        #for sublist in all_thermos:
        #    thermo += sublist
        name = "mu%d" % (int(abs(mu) * 10000))
        if (mu < 0.0):
            name += "m"
        data_written_to_file = False
        data = {}
        try:
            with open(OUTFILE, 'r') as infile:
                data = json.load(infile)

            if (name in data.keys()):
                for i, entry in enumerate(thermo):
                    for key, value in entry.iteritems():
                        data[name][key].append(value)
                    #data[name]["singlets"].append( entry["singlets"][0] )
                    #data[name]["energy"].append( entry["energy"] )
                    #data[name]["heat_capacity"].append( entry["heat_capacity"] )
                    #data[name]["temperature"].append( entry["temperature"] )
                    data_written_to_file = True
        except Exception as exc:
            print(str(exc))
            print("Could not load file! Creating a new one!")

        if (not data_written_to_file):
            data[name] = {}
            for key in thermo[0].keys():
                for entry in thermo:
                    data[name][key] = [entry[key] for entry in thermo]
            #data[name]["singlets"] = [entry["singlets"][0] for entry in thermo]
            #data[name]["temperature"] = list(temps)
            #data[name]["energy"] = [entry["energy"] for entry in thermo]
            #data[name]["heat_capacity"] = [entry["heat_capacity"] for entry in thermo]
            #data[name]["mu"] = mu
        with open(OUTFILE, 'w') as outfile:
            json.dump(data,
                      outfile,
                      sort_keys=True,
                      indent=2,
                      separators=(",", ":"))
        print("Data written to {}".format(OUTFILE))

    if (comm.Get_rank() == 0):
        print(ceBulk.atoms.get_chemical_formula())
        #view( ceBulk.atoms )

    ceBulk.atoms.set_calculator(None)
    if (rank == 0):
        with open(pck_file, 'wb') as outfile:
            pck.dump((ceBulk, calc.get_cf(), calc.eci), outfile)
            print("Bulk crystal object pickled to {}".format(pck_file))