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))
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
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()
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( feasst.MakeCheckEnergy( feasst.args({ "steps_per": str(steps_per), "tolerance": "1e-8" }))) monte_carlo.attempt(int(1e5))