Esempio n. 1
0
def main():
    atoms = atoms_with_calc(50)
    # mc = SoluteChainMC(atoms, 350, cluster_elements=["Mg", "Si"], 
    #     cluster_names=["c2_01nn_0"])

    T = [10]
    snapshot = Snapshot(trajfile="data/solute_chain{}_nostrain.traj".format(T[0]), atoms=atoms)
    first = True
    nano_part = get_nanoparticle()
    for temp in T:
        print("Current temperature {}".format(T))
        mc = FixedNucleusMC(
            atoms, temp, network_name=["c2_01nn_0"],
            network_element=["Mg", "Si"],
            max_constraint_attempts=1E6)
        backup = MCBackup(mc, overwrite_db_row=False, db_name="data/mc_solute_no_strain.db")
        mc.attach(backup, interval=20000)
        strain = get_strain_observer(mc)
        mc.add_bias(strain)

        if first:
            first = False
            #mc.grow_cluster({"Mg": 1000, "Si": 1000})
            symbs = insert_nano_particle(atoms.copy(), nano_part)
            mc.set_symbols(symbs)
            tag_by_layer_type(mc.atoms)
            cnst = ConstrainElementByTag(atoms=mc.atoms, element_by_tag=[["Mg", "Al"], ["Si", "Al"]])
            mc.add_constraint(cnst)

        #mc.build_chain({"Mg": 500, "Si": 500})
        fix_layer = FixEdgeLayers(thickness=5.0, atoms=mc.atoms)
        mc.add_constraint(fix_layer)
        mc.attach(snapshot, interval=20000)
        mc.runMC(steps=19000, init_cluster=False)
def run(N, use_bias):
    #network_name=["c2_4p050_3", "c2_2p864_2"]
    bc = init_bc(N)
    mc = FixedNucleusMC(
        bc.atoms, T, network_name=["c2_2p864_2"],
        network_element=["Mg", "Si"], mpicomm=comm,
        max_constraint_attempts=1E6)
    #mc.max_allowed_constraint_pass_attempts = 1
    nanop = get_nanoparticle()
    symbs = insert_nano_particle(bc.atoms.copy(), nanop)
    mc.set_symbols(symbs)
    mc.init_cluster_info()
 
    formula = "(I1+I2)/(2*I3)" # Needle
    #formula = "2*I1/(I2+I3)" # Plate
    inert_init = InertiaCrdInitializer(
        fixed_nucl_mc=mc, matrix_element="Al", cluster_elements=["Mg", "Si"],
        formula=formula)
 
    inert_rng_constraint = InertiaRangeConstraint(
        fixed_nuc_mc=mc, inertia_init=inert_init, verbose=True)

    if use_bias:
        bias = InertiaBiasPotential.load(fname=inertia_bias_file)
        bias.inertia_range = inert_rng_constraint
        mc.add_bias(bias)

    nsteps = 100000

    if rank == 0:
        snap = Snapshot(atoms=bc.atoms, trajfile="{}/inertia.traj".format(workdir))
        mc.attach(snap, interval=100000)
    # reac_path = ReactionPathSampler(
    #     mc_obj=mc, react_crd=[0.05, 0.9], react_crd_init=inert_init,
    #     react_crd_range_constraint=inert_rng_constraint, n_windows=30,
    #     n_bins=10, data_file=h5file)
    # reac_path.run(nsteps=nsteps)
    # reac_path.save()

    inert_rng_constraint.range = [0.0, 0.9]
    fix_layer = FixEdgeLayers(thickness=5.0, atoms=mc.atoms)
    mc.add_constraint(inert_rng_constraint)
    mc.add_constraint(fix_layer)

    reac_path = AdaptiveBiasReactionPathSampler(
        mc_obj=mc, react_crd=[0.0, 0.9], react_crd_init=inert_init, 
        n_bins=100, data_file="{}/adaptive_bias.h5".format(workdir),
        mod_factor=1E-5, delete_db_if_exists=True, mpicomm=None,
        db_struct="{}/adaptive_bias_struct.db".format(workdir))
    reac_path.run()
    reac_path.save()