def nvtw(num_particles, num_procs, num_equil, num_prod, num_hours, dccb_begin, temperature, mu, steps_per, model):
    mc = fst.MakeMonteCarlo()
    #mc.set(fst.MakeRandomMT19937(fst.args({"seed": "1633373856"})))
    beta = 1./temperature
    if model == "lj":
        mc.add(fst.MakeConfiguration(fst.args({"cubic_box_length": "8",
            "particle_type0": fst.install_dir() + "/forcefield/lj.fstprt"})))
        mc.add(fst.MakePotential(fst.MakeLennardJones()))
        mc.add(fst.MakePotential(fst.MakeLongRangeCorrections()))
    elif model == "sqw":
        config = fst.MakeConfiguration(fst.args({"cubic_box_length": "8", "particle_type0": fst.install_dir() + "/forcefield/atom.fstprt"}))
        config.set_model_param("cutoff", 0, 1.5)
        mc.add(config)
        mc.add(fst.MakePotential(fst.MakeSquareWell()))
    elif model == "spce":
        mc.add(fst.MakeConfiguration(fst.args({"cubic_box_length": "20",
            "particle_type0": fst.install_dir() + "/forcefield/spce.fstprt"})))
        mc.add(fst.MakePotential(fst.MakeEwald(fst.args({"alpha": str(5.6/20),
            "kmax_squared": "38"}))))
        mc.add(fst.MakePotential(fst.MakeModelTwoBodyFactory(fst.MakeLennardJones(), fst.MakeChargeScreened()),
                                          fst.args({"table_size": "1e6"})))
        mc.add(fst.MakePotential(fst.MakeChargeScreenedIntra(), fst.MakeVisitModelBond()))
        mc.add(fst.MakePotential(fst.MakeChargeSelf()))
        mc.add(fst.MakePotential(fst.MakeLongRangeCorrections()))
        beta = 1./fst.kelvin2kJpermol(temperature, mc.configuration())
    else:
        assert(False) # model not recognized

    # fill box with larger temperature and mu
    mc.set(fst.MakeThermoParams(fst.args({"beta": "0.01", "chemical_potential": "10"})))
    mc.set(fst.MakeMetropolis());
    #trial_args = {"particle_type": "0", "site": "0", "reference_index": ref, "num_steps": num_steps}
    mc.add(fst.MakeTrialTranslate(fst.args({"tunable_param": "0.1"})))
    #mc.add(fst.MakeTrialGrow(fst.ArgsVector([dict({"translate": "true", "tunable_param": "0.1"}, **trial_args)])))
    mc.add(fst.MakeTrialAdd(fst.args({"particle_type": "0", "weight": "4"})))
    mc.add(fst.MakeTune(fst.args({"steps_per": steps_per})))
    mc.add(fst.MakeCheckEnergy(fst.args({"steps_per": steps_per, "tolerance": "0.0001"})))
    mc.add(fst.MakeLogAndMovie(fst.args({"steps_per": steps_per,
                                         "file_name": model + str(num_particles)})))
    mc.set(fst.MakeCheckpoint(fst.args({"file_name": "checkpoint" + str(num_particles) + ".fst",
                                        "num_hours": str(0.1*num_procs*num_hours),
                                        "num_hours_terminate": str(0.9*num_procs*num_hours)})))
    mc.run(fst.MakeRun(fst.args({"until_num_particles": str(num_particles)})))
    mc.run(fst.MakeRemoveTrial(fst.args({"name": "TrialAdd"})))
    # nvt equilibration at desired temperature
    mc.set(fst.MakeThermoParams(fst.args({"beta": str(beta),
                                          "chemical_potential": str(mu)})))
    mc.attempt(int((num_particles+1)*num_equil))
    mc.run(fst.MakeRemoveModify(fst.args({"name": "Tune"})))
    mc.add(fst.MakeTrialTransfer(fst.args({"particle_type": "0", "weight": "4"})))
    #mc.add(fst.MakeTrialGrow(fst.ArgsVector([dict({"transfer": "true", "weight": "4"}, **trial_args)])))
    mc.set(fst.MakeFlatHistogram(fst.args({
        "Macrostate": "MacrostateNumParticles", "width": "1", "max": str(num_particles), "min": str(num_particles),
        "Bias": "TransitionMatrix", "min_sweeps": "1"})))
    mc.add(fst.MakeEnergy(fst.args({"steps_per_write": steps_per,
                                    "file_name": "en" + str(num_particles) + ".txt"})))
    mc.add(fst.MakeCriteriaWriter(fst.args({"steps_per": steps_per,
                                            "file_name": "crit" + str(num_particles) + ".txt"})))
    mc.attempt(int((num_particles+1)*num_prod))
예제 #2
0
def mc(
        target_acceptance=0.25,
        tunable_param=0.1,
        density=0.85,
        cutoff=4,
        temperature=0.88,
        steps_per=int(1e6),
):
    box_length = 2 * cutoff
    file_app = "_a" + str(target_acceptance) + "_r" + str(cutoff)
    num_particles = int(density * box_length**3)
    print('num_particles', num_particles)
    print('target_acceptance', target_acceptance)
    print('tunable_param', tunable_param)

    monte_carlo = feasst.Prefetch(feasst.args({"steps_per_check": "10000000"}))
    monte_carlo.activate_prefetch(False)
    monte_carlo.set(lj_system(box_length=box_length, cutoff=cutoff))
    monte_carlo.set(
        feasst.MakeMetropolis(
            feasst.args({
                "beta": str(1. / temperature),
                "chemical_potential": "1.",
            })))
    monte_carlo.add(
        feasst.MakeTrialTranslate(
            feasst.args({
                "weight": "1.",
                "tunable_param": str(tunable_param),
                "tunable_target_acceptance": str(target_acceptance),
                "tunable_percent_change": "0.01",
                # "num_steps": "4",
                # "reference_index": "0",
            })))
    feasst.SeekNumParticles(num_particles).with_trial_add().run(monte_carlo)
    monte_carlo.add(
        feasst.MakeLog(
            feasst.args({
                "steps_per": str(steps_per),
                "file_name": "log" + file_app + ".txt",
                "clear_file": "true"
            })))
    monte_carlo.add(
        feasst.MakeCheckEnergy(
            feasst.args({
                "steps_per": str(steps_per),
                "tolerance": str(1e-8)
            })))
    monte_carlo.add(feasst.MakeTune(feasst.args({"steps_per":
                                                 str(steps_per)})))

    #equilibrate
    monte_carlo.attempt(int(1e7))

    if not args.nopipe:
        monte_carlo.activate_prefetch(True)
    monte_carlo.add(
        feasst.MakeMeanSquaredDisplacement(
            feasst.args({
                "steps_per_update": "10000",
                "updates_per_origin": "1000",
                "file_name": "msd" + file_app + ".txt",
                "steps_per_write": str(int(1e5))
            })))

    monte_carlo.add(
        feasst.MakeCPUTime(
            feasst.args({
                "steps_per_update": str(steps_per),
                "steps_per_write": str(steps_per),
                "file_name": "cpu" + file_app + ".txt",
            })))

    #h0 = feasst.cpu_hours()
    monte_carlo.attempt(int(1e8))
예제 #3
0
def mc(
       trials_per=int(1e6),
       ):
    box_length = 2.*args.cutoff
    file_app = "_a" + str(args.rel_disp_prob) + "_rc" + str(args.cutoff)

    monte_carlo = feasst.Prefetch(feasst.args({"trials_per_check": str(int(1e7))}))
    monte_carlo.activate_prefetch(False)
    # monte_carlo.set(feasst.MakeRandomMT19937(feasst.args({"seed": "1578687129"})))
    monte_carlo.set(lj_system(box_length=box_length))
    monte_carlo.set(feasst.MakeMetropolis(feasst.args({
        "beta": str(1./args.temperature),
        "chemical_potential": str(args.chemical_potential),
    })))
    monte_carlo.add(feasst.MakeTrialTranslate(feasst.args({
        "weight": str(args.rel_disp_prob),
        "tunable_param": str(args.max_move),
        "tunable_target_acceptance": str(args.target_prob),
        "tunable_percent_change": "0.1",
    })))
    num_particles = int(args.density*box_length**3)
    nmin = num_particles - args.window_half_width
    nmax = num_particles + args.window_half_width
    if not args.nofh:
        feasst.SeekNumParticles(nmin).with_trial_add().run(monte_carlo)
    monte_carlo.add(feasst.MakeTrialTransfer(feasst.args({
        "weight": "1",
        "particle_type": "0"})))
    if not args.nofh:
        monte_carlo.set(fh.criteria_flathist(
            temperature=args.temperature,
            chemical_potential=args.chemical_potential,
            macro_max=nmax,
            macro_min=nmin,
            iterations=args.iterations,
            ))
        monte_carlo.add(feasst.MakeCriteriaUpdater(feasst.args({"trials_per": str(trials_per)})))
        monte_carlo.add(feasst.MakeCriteriaWriter(feasst.args(
            {"trials_per": str(trials_per), "file_name": "crit"+file_app+".txt"})))
    else:
        monte_carlo.add(feasst.MakeNumParticles(feasst.args({
            "file_name": "num"+file_app+".txt",
            "trials_per_write": str(trials_per),
        })))
    analyze.add(monte_carlo,
        trials_per,
        proc=file_app,
        log="log"+file_app+".txt",
        )

    if not args.nopara:
        monte_carlo.activate_prefetch(True)

    monte_carlo.add(feasst.MakeCPUTime(feasst.args({
        "trials_per_update": str(trials_per),
        "trials_per_write": str(trials_per),
        "file_name": "cpu" + file_app + ".txt",
    })))

    monte_carlo.add(feasst.MakeEnergy(feasst.args(
        {"file_name": "energy"+file_app+".txt",
         "trials_per_update": "1",
         "trials_per_write": str(trials_per),
         "multistate": "true"})))

    monte_carlo.set(feasst.MakeCheckpoint(feasst.args(
        {"file_name": "checkpoint"+file_app+".txt", "num_hours": "0.1"})))

    # run until complete is not pprefetched correctly
    monte_carlo.run_until_complete()
예제 #4
0
def monte_carlo(
        proc=0,  # processor number
        criteria=criteria_flathist(),  # flat histogram criteria
        steps_per=1e5,  # steps per analysis
        system=lj_system.system(
            lj_system.configuration(box_length=8, forcefield="data.lj")),
        run=True  # run the simulation
):
    """Create, run and return a flat histogram grand canonical Monte Carlo simulation"""
    monte_carlo0 = fst.MonteCarlo()
    monte_carlo0.set(system)

    # add the minimum number of particles
    monte_carlo0.set(
        fst.MakeMetropolis(fst.args({
            "beta": "0.1",
            "chemical_potential": "1"
        })))
    monte_carlo0.add(
        fst.MakeTrialTranslate(
            fst.args({
                "weight": "0.375",
                "tunable_param": "2."
            })))
    if monte_carlo0.system().configuration().particle_type(0).num_sites() > 1:
        monte_carlo0.add(
            fst.MakeTrialRotate(
                fst.args({
                    "weight": "0.375",
                    "tunable_param": "2."
                })))
    fst.add_trial_transfer(monte_carlo0,
                           fst.args({
                               "weight": "0.125",
                               "particle_type": "0"
                           }))

    min_macro = int(criteria.macrostate().histogram().center_of_bin(0))
    # print("seeking", min_macro)
    fst.SeekNumParticles(min_macro).run(monte_carlo0)

    # replace the acceptance criteria with flat histogram
    monte_carlo0.set(criteria)

    analyze.add(monte_carlo0,
                steps_per,
                proc=proc,
                log="log" + str(proc) + ".txt")

    # periodically write the status of the flat histogram criteria
    monte_carlo0.add(
        fst.MakeCriteriaUpdater(fst.args({"steps_per": str(steps_per)})))
    monte_carlo0.add(
        fst.MakeCriteriaWriter(
            fst.args({
                "steps_per": str(steps_per),
                "file_name": "crit" + str(proc) + ".txt"
            })))

    # periodically write a checkpoint file
    monte_carlo0.add(
        fst.MakeCheckpoint(
            fst.args({
                "file_name": "checkpoint" + str(proc) + ".txt",
                "num_hours": "0.01"
            })))

    # periodically write the energy of the macrostates
    monte_carlo0.add(
        fst.MakeEnergy(
            fst.args({
                "file_name": "energy" + str(proc) + ".txt",
                "steps_per_update": "1",
                "steps_per_write": str(steps_per),
                "multistate": "true"
            })))

    if run:
        monte_carlo0.run_until_complete()
    #print(monte_carlo0.criteria().write())
    return monte_carlo0
예제 #5
0
def mc(thread, mn, mx):
    mc = fst.MakeMonteCarlo()
    mc.set(fst.MakeRandomMT19937(fst.args({"seed": "123"})))
    mc.add(
        fst.MakeConfiguration(
            fst.args({
                "side_length0": str(args.lx),
                "side_length1": str(args.ly),
                "side_length2": str(args.lz),
                "particle_type0": args.particle
            })))
    for site_type in range(mc.configuration().num_site_types()):
        mc.get_system().get_configuration().set_model_param(
            "cutoff", site_type, args.cutoff)
    mc.add(fst.MakePotential(fst.MakeLennardJones()))
    mc.add(
        fst.MakePotential(fst.MakeLennardJones(),
                          fst.MakeVisitModelIntra(fst.args({"cutoff": "4"}))))
    mc.add(fst.MakePotential(fst.MakeLongRangeCorrections()))
    if mx > args.dccb_begin:
        reference = fst.Potential(
            fst.MakeLennardJones(),
            fst.MakeVisitModelCell(
                fst.args({"min_length": str(args.dccb_cutoff)})))
        reference.set_model_params(mc.configuration())
        for site_type in range(mc.configuration().num_site_types()):
            reference.set_model_param("cutoff", site_type, args.dccb_cutoff)
        mc.add_to_reference(reference)
        #mc.add_to_reference(fst.MakePotential(fst.MakeLennardJones(),
        #                    fst.MakeVisitModelIntra(fst.args({"cutoff": "4"}))))
        stage_args = {"reference_index": "0", "num_steps": "4"}
    else:
        mc.add_to_reference(fst.MakePotential(fst.DontVisitModel()))
        stage_args = {"reference_index": "0", "num_steps": "1"}
    beta = 1. / fst.kelvin2kJpermol(args.temperature)
    mc.set(
        fst.MakeThermoParams(
            fst.args({
                "beta": str(beta),
                "chemical_potential0": str(args.beta_mu / beta)
            })))
    mc.set(fst.MakeMetropolis())
    mc.add(fst.MakeTrialTranslate(fst.args({"weight": "0.5"})))
    mc.add(fst.MakeTrialRotate(fst.args({"weight": "0.5"})))

    print('thread', thread, 'mn', mn, 'mx', mx)
    if thread == 0 and mn > 0:
        mc.add(fst.MakeTrialAdd(fst.args({"particle_type": "0"})))
        mc.run(fst.MakeRun(fst.args({"until_num_particles": str(mn)})))
        mc.run(fst.RemoveTrial(fst.args({"name": "TrialAdd"})))

    mc.set(
        fst.MakeFlatHistogram(
            fst.MakeMacrostateNumParticles(
                fst.Histogram(
                    fst.args({
                        "width": "1",
                        "max": str(mx),
                        "min": str(mn)
                    }))),
            # fst.MakeTransitionMatrix(fst.args({"min_sweeps": str(args.sweeps)})),
            fst.MakeWLTM(
                fst.args({
                    "collect_flatness": str(args.collect_flatness),
                    "min_flatness": str(args.min_flatness),
                    "min_sweeps": "1000"
                }))))
    # configurational bias with TrialGrow: full and partial regrows from 0-site, and reverse
    num_sites = mc.configuration().particle_type(0).num_sites()
    for site in range(num_sites):
        for g in gen_grow(num_sites, reptate=False):
            mc.add(
                fst.MakeTrialGrow(
                    fst.ArgsVector(add_particle_type_weight(
                        site, num_sites, g)), fst.args(stage_args)))

    # reptation
    if num_sites > 3:
        for g in gen_grow(num_sites, reptate=True):
            mc.add(
                fst.MakeTrialGrow(
                    fst.ArgsVector(add_particle_type_weight(0, num_sites, g)),
                    fst.args(stage_args)))

    # these moves may not take bond energies into consideration properly. Instead, should implement a dihedral rotation.
    #mc.add(fst.MakeTrialCrankshaft(fst.args(dict({"weight": "0.25", "tunable_param": "25.", "max_length": "5."}, **stage_args))))
    #mc.add(fst.MakeTrialPivot(fst.args(dict({"weight": "0.25", "tunable_param": "25.", "max_length": "5."}, **stage_args))))

    mc.add(
        fst.MakeCheckEnergy(
            fst.args({
                "steps_per": str(args.steps_per),
                "tolerance": "0.0001"
            })))
    mc.add(
        fst.MakeTune(
            fst.args({
                "steps_per": str(args.steps_per),
                "stop_after_phase": "0"
            })))
    mc.add(
        fst.MakeLogAndMovie(
            fst.args({
                "steps_per": str(args.steps_per),
                "file_name": "clones" + str(thread),
                "file_name_append_phase": "True"
            })))
    mc.add(
        fst.MakeEnergy(
            fst.args({
                "file_name": "en" + str(thread) + '.txt',
                "file_name_append_phase": "True",
                "start_after_phase": "0",
                "steps_per_write": str(args.steps_per),
                "steps_per_update": "1",
                "multistate": "True"
            })))
    mc.add(
        fst.MakeCriteriaUpdater(fst.args({"steps_per": str(args.steps_per)})))
    mc.add(
        fst.MakeCriteriaWriter(
            fst.args({
                "steps_per": str(args.steps_per),
                "file_name": "clones" + str(thread) + "_crit.txt",
                "file_name_append_phase": "True"
            })))
    mc.set(
        fst.MakeCheckpoint(
            fst.args({
                "file_name":
                "checkpoint" + str(thread) + ".fst",
                "num_hours_terminate":
                str(0.9 * args.num_procs * args.num_hours)
            })))
    return mc
예제 #6
0
if args.task > 0:
    mc = fst.MakeMonteCarlo("checkpoint.fst")
    mc.attempt(args.trials - mc.trials().num_attempts())
    quit()
mc.set(fst.MakeRandomMT19937(fst.args({"seed": args.seed})))
mc.add(
    fst.Configuration(
        fst.MakeDomain(
            fst.args({
                "cubic_box_length":
                str((args.num / args.density)**(1. / 3.))
            })), fst.args({"particle_type": args.data})))
mc.add(fst.MakePotential(fst.MakeLennardJones()))
mc.add(fst.MakePotential(fst.MakeLongRangeCorrections()))
mc.set(fst.MakeThermoParams(fst.args({"beta": str(args.beta)})))
mc.set(fst.MakeMetropolis())
mc.add(
    fst.MakeTrialTranslate(
        fst.args({
            "tunable_param": "0.2",
            "tunable_target_acceptance": "0.2"
        })))
mc.add(fst.MakeTrialAdd(fst.args({"particle_type": "0"})))
mc.run(fst.MakeRun(fst.args({"until_num_particles": str(args.num)})))
mc.run(fst.MakeRemoveTrial(fst.args({"name": "TrialAdd"})))
steps_per = str(int(1e5))
mc.add(
    fst.MakeCheckEnergyAndTune(
        fst.args({
            "steps_per": steps_per,
            "tolerance": "1e-8"
예제 #7
0
import feasst

monte_carlo = feasst.MonteCarlo()
monte_carlo.set(feasst.MakeRandomMT19937(feasst.args({"seed": "time"})))
monte_carlo.add(
    feasst.Configuration(
        feasst.MakeDomain(feasst.args({"cubic_box_length": "8"})),
        feasst.args(
            {"particle_type": feasst.install_dir() + "/forcefield/data.lj"})))
monte_carlo.add(feasst.Potential(feasst.MakeLennardJones()))
monte_carlo.add(feasst.Potential(feasst.MakeLongRangeCorrections()))
monte_carlo.add(feasst.MakeMetropolis(feasst.args({"beta": "1.5"})))
monte_carlo.add(
    feasst.MakeTrialTranslate(
        feasst.args({
            "tunable_param": "2.",
            "tunable_target_acceptance": "0.2"
        })))
steps_per = int(1e3)
monte_carlo.add(feasst.MakeTuner(feasst.args({"steps_per": str(steps_per)})))
feasst.SeekNumParticles(50)\
    .with_metropolis(feasst.args({"beta": "0.1", "chemical_potential": "10"}))\
    .with_trial_add().run(monte_carlo)
monte_carlo.add(feasst.MakeLog(feasst.args({"steps_per": str(steps_per)})))
monte_carlo.add(
    feasst.MakeMovie(
        feasst.args({
            "steps_per": str(steps_per),
            "file_name": "movie.xyz"
        })))
monte_carlo.add(