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))
def test(self): #return serial = False serial = True if serial: criteria = feasst.MakeFlatHistogram(feasst.args( {"beta": str(1./1.5), "chemical_potential": "-2.35231"} )) criteria.set(feasst.MakeMacrostateGrowthExpanded( feasst.Histogram(feasst.args({"width": "0.5", "max": "10"})), #feasst.args({"soft_max": "10"}) )) criteria.set(feasst.MakeTransitionMatrix(feasst.args({"min_sweeps": "10"}))) , "num_steps_to_update": str(int(1e6))} mc2 = fh.monte_carlo(criteria=criteria, forcefield='data.dimer', run=False) mc2.add(feasst.MakeCriteriaWriter(feasst.args({"steps_per": str(int(1e6))}))) mc2.run_until_complete()
def mc(thread, mn, mx): steps_per = str(int(1e6)) mc = fst.MakeMonteCarlo() 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())) trial_args = {"particle_type": "0", "site": "0"} if mx >= args.dccb_begin: mc.run( fst.MakeAddReference(fst.args({ "cutoff": "1", "use_cell": "true" }))) trial_args["reference_index"] = "0" trial_args["num_steps"] = "4" mc.set( fst.MakeThermoParams( fst.args({ "beta": str(1. / args.temperature), "chemical_potential": str(args.mu) }))) 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.min_sweeps)})), fst.MakeWLTM( fst.args({ "collect_flatness": "18", "min_flatness": "22", "min_sweeps": str(args.min_sweeps) })))) #mc.add(fst.MakeTrialTranslate(fst.args({"weight": "1.", "tunable_param": "1."}))) #mc.add(fst.MakeTrialTransfer(fst.args({"weight": "4", "particle_type": "0", mc.add( fst.MakeTrialGrow( fst.ArgsVector([ dict({ "translate": "true", "tunable_param": "1" }, **trial_args) ]))) mc.add( fst.MakeTrialGrow( fst.ArgsVector( [dict({ "transfer": "true", "weight": "4" }, **trial_args)]))) mc.add( fst.MakeCheckEnergy( fst.args({ "steps_per": steps_per, "tolerance": "0.0001" }))) mc.add( fst.MakeTune( fst.args({ "steps_per": steps_per, "stop_after_phase": "0" }))) mc.add( fst.MakeLogAndMovie( fst.args({ "steps_per": steps_per, "file_name": "clones" + str(thread), "file_name_append_phase": "True" }))) mc.add( fst.MakeEnergy( fst.args({ "steps_per_write": steps_per, "file_name": "en" + str(thread) + ".txt", "file_name_append_phase": "True", "start_after_phase": "0", "multistate": "True" }))) mc.add(fst.MakeCriteriaUpdater(fst.args({"steps_per": steps_per}))) mc.add( fst.MakeCriteriaWriter( fst.args({ "steps_per": 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": str(0.1 * args.num_procs * args.num_hours), "num_hours_terminate": str(0.9 * args.num_procs * args.num_hours) }))) return mc
def mc(thread, mn, mx, trials_per=str(int(1e6))): mc = fst.MakeMonteCarlo() mc.add(config()) mc.add(fst.MakePotential(fst.MakeLennardJonesForceShift())) mc.set( fst.MakeThermoParams( fst.args({ "beta": str(1. / args.temperature), "chemical_potential": str(args.mu) }))) 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.min_sweeps)})), fst.MakeWLTM( fst.args({ "collect_flatness": "18", "min_flatness": "22", "min_sweeps": str(args.min_sweeps) })))) mc.add( fst.MakeTrialTranslate( fst.args({ "weight": "1.", "tunable_param": "1." }))) mc.add( fst.MakeTrialRotate(fst.args({ "weight": "1.", "tunable_param": "20." }))) mc.add( fst.MakeTrialTransfer(fst.args({ "weight": "4", "particle_type": "0" }))) mc.add( fst.MakeCheckEnergy( fst.args({ "trials_per": trials_per, "tolerance": "0.0001" }))) mc.add(fst.MakeTune(fst.args({"stop_after_phase": "0"}))) mc.add( fst.MakeLogAndMovie( fst.args({ "trials_per": trials_per, "file_name": "clones" + str(thread), "file_name_append_phase": "True" }))) mc.add( fst.MakeEnergy( fst.args({ "trials_per_write": trials_per, "file_name": "en" + str(thread) + ".txt", "file_name_append_phase": "True", "start_after_phase": "0", "multistate": "True" }))) mc.add(fst.MakeCriteriaUpdater(fst.args({"trials_per": trials_per}))) mc.add( fst.MakeCriteriaWriter( fst.args({ "trials_per": trials_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": str(0.1 * args.num_procs * args.num_hours), "num_hours_terminate": str(0.9 * args.num_procs * args.num_hours) }))) return mc
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()
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(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
def mc(thread, mn, mx): steps_per = int(1e5) avb, dccb = avb_or_dccb(mx) mc = fst.MakeMonteCarlo() mc.add( fst.MakeConfiguration( fst.args({ "cubic_box_length": "20", "physical_constants": "CODATA2010", "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())) if dccb or avb: mc.run( fst.MakeAddReference( fst.args({ "potential_index": "1", "cutoff": "3.16555789", "use_cell": "true" }))) if avb: initialize_neighbor_list(mc) beta = 1. / fst.kelvin2kJpermol(525, mc.configuration()) mc.set( fst.MakeThermoParams( fst.args({ "beta": str(beta), "chemical_potential": str(-8.14 / beta) }))) mc.set( fst.MakeFlatHistogram( fst.MakeMacrostateNumParticles( fst.Histogram( fst.args({ "width": "1", "max": str(mx), "min": str(mn) }))), fst.MakeTransitionMatrix(fst.args({"min_sweeps": "10"})))) mc.add( fst.MakeTrialTranslate( fst.args({ "weight": "1.", "tunable_param": "1.", }))) mc.add( fst.MakeTrialRotate(fst.args({ "weight": "1.", "tunable_param": "1." }))) mc.add( fst.MakeTrialTransfer(fst.args({ "particle_type": "0", "weight": "4" }))) regrow1 = [{ "angle": "true", "mobile_site": "1", "anchor_site": "0", "anchor_site2": "2" }] regrow2 = [{ "angle": "true", "mobile_site": "2", "anchor_site": "0", "anchor_site2": "1" }] regrow12 = [{ "bond": "true", "mobile_site": "1", "anchor_site": "0" }] + copy.deepcopy(regrow2) regrow21 = [{ "bond": "true", "mobile_site": "2", "anchor_site": "0" }] + copy.deepcopy(regrow1) if dccb: grow012 = [{ "transfer": "true", "site": "0", "weight": "4" }] + copy.deepcopy(regrow12) grow021 = [{ "transfer": "true", "site": "0", "weight": "4" }] + copy.deepcopy(regrow21) for grow in [regrow1, regrow2]: grow[0]["weight"] = "0.3" for grow in [regrow12, regrow21]: grow[0]["weight"] = "0.2" for grow in [grow012, grow021, regrow12, regrow21, regrow1, regrow2]: grow[0]["particle_type"] = "0" mc.add( fst.MakeTrialGrow( fst.ArgsVector(grow), fst.args({ "reference_index": "0", "num_steps": "4" }))) if avb: for avbtype in ["transfer_avb", "regrow_avb2", "regrow_avb4"]: avb = [{ avbtype: "true", "site": "0", "neighbor_index": "0", "target_particle_type": "0", "target_site": "0" }] avb_012 = copy.deepcopy(avb) + copy.deepcopy(regrow12) avb_021 = copy.deepcopy(avb) + copy.deepcopy(regrow21) for grow in [avb_012, avb_021]: grow[0]["weight"] = "0.5" grow[0]["particle_type"] = "0" mc.add( fst.MakeTrialGrow( fst.ArgsVector(grow), fst.args({ "num_steps": "4", "reference_index": "0" }))) mc.add( fst.MakeCheckEnergyAndTune( fst.args({ "steps_per": str(steps_per), "tolerance": "0.0001" }))) mc.add( fst.MakeLogAndMovie( fst.args({ "steps_per": str(steps_per), "file_name": "clones" + str(thread) }))) mc.add(fst.MakeCriteriaUpdater(fst.args({"steps_per": str(steps_per)}))) mc.add( fst.MakeCriteriaWriter( fst.args({ "steps_per": str(steps_per), "file_name": "clones" + str(thread) + "_crit.txt" }))) mc.add( fst.MakeEnergy( fst.args({ "steps_per_write": str(steps_per), "file_name": "en" + str(thread), "multistate": "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
def mc(thread, mn, mx): steps_per = str(int(1e6)) mc = fst.MakeMonteCarlo() mc.add( fst.MakeConfiguration( fst.args({ "cubic_box_length": str(args.cubic_box_length), "particle_type0": fst.install_dir() + "/forcefield/hard_sphere.fstprt" }))) mc.add(fst.MakePotential(fst.MakeHardSphere())) # mc.add_to_optimized(fst.MakePotential(fst.MakeHardSphere(), fst.MakeVisitModelCell(fst.args({"min_length": "1"})))) mc.set( fst.MakeThermoParams( fst.args({ "beta": "1", "chemical_potential": str(args.mu) }))) 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.min_sweeps)})), fst.MakeWLTM( fst.args({ "collect_flatness": "18", "min_flatness": "22", "min_sweeps": str(args.min_sweeps) })))) mc.add( fst.MakeTrialTranslate( fst.args({ "new_only": "true", "weight": "1.", "tunable_param": "1." }))) mc.add( fst.MakeTrialTransfer(fst.args({ "weight": "4", "particle_type": "0" }))) mc.add( fst.MakeCheckEnergy( fst.args({ "steps_per": steps_per, "tolerance": "0.0001" }))) mc.add( fst.MakeTune( fst.args({ "steps_per": steps_per, "stop_after_phase": "0" }))) mc.add( fst.MakeLogAndMovie( fst.args({ "steps_per": steps_per, "file_name": "clones" + str(thread), "file_name_append_phase": "True" }))) mc.add( fst.MakePairDistribution( fst.args({ "steps_per_update": "1000", "steps_per_write": steps_per, "dr": "0.025", "file_name": "gr" + str(thread) + ".txt", "file_name_append_phase": "True", "start_after_phase": "0", "multistate": "True", "multistate_aggregate": "False" }))) mc.add(fst.MakeCriteriaUpdater(fst.args({"steps_per": steps_per}))) mc.add( fst.MakeCriteriaWriter( fst.args({ "steps_per": 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": str(0.1 * args.num_procs * args.num_hours), "num_hours_terminate": str(0.9 * args.num_procs * args.num_hours) }))) return mc
def mc(thread, mn, mx): mc = fst.MakeMonteCarlo() #mc.set(fst.MakeRandomMT19937(fst.args({"seed": "123"}))) mc.add( fst.MakeConfiguration( fst.args({ "cubic_box_length": str(args.cubic_box_length), "physical_constants": "CODATA2010", "particle_type0": args.molecule }))) mc.add( fst.MakePotential( fst.MakeEwald( fst.args({ "alpha": str(5.6 / args.cubic_box_length), "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())) if mx > args.dccb_begin: mc.run( fst.MakeAddReference( fst.args({ "potential_index": "1", "cutoff": "3.16555789", "use_cell": "true" }))) beta = 1. / fst.kelvin2kJpermol(args.temperature, mc.configuration()) mc.set( fst.MakeThermoParams( fst.args({ "beta": str(beta), "chemical_potential": str(args.beta_mu / beta) }))) mc.set( fst.MakeFlatHistogram( fst.MakeMacrostateNumParticles( fst.Histogram( fst.args({ "width": "1", "max": str(mx), "min": str(mn) }))), fst.MakeTransitionMatrix(fst.args({"min_sweeps": "10"})))) mc.add( fst.MakeTrialTranslate( fst.args({ "weight": "1.", "tunable_param": "1.", }))) if mx > args.dccb_begin: regrow1 = [{ "angle": "true", "mobile_site": "1", "anchor_site": "0", "anchor_site2": "2" }] regrow2 = [{ "angle": "true", "mobile_site": "2", "anchor_site": "0", "anchor_site2": "1" }] regrow12 = [{ "bond": "true", "mobile_site": "1", "anchor_site": "0" }] + copy.deepcopy(regrow2) regrow21 = [{ "bond": "true", "mobile_site": "2", "anchor_site": "0" }] + copy.deepcopy(regrow1) grow012 = [{ "transfer": "true", "site": "0", "weight": "4" }] + copy.deepcopy(regrow12) grow021 = [{ "transfer": "true", "site": "0", "weight": "4" }] + copy.deepcopy(regrow21) for grow in [regrow1, regrow2]: grow[0]["weight"] = "0.3" for grow in [regrow12, regrow21]: grow[0]["weight"] = "0.2" for grow in [grow012, grow021, regrow12, regrow21, regrow1, regrow2]: grow[0]["particle_type"] = "0" mc.add( fst.MakeTrialGrow( fst.ArgsVector(grow), fst.args({ "reference_index": "0", "num_steps": "4" }))) else: mc.add( fst.MakeTrialRotate( fst.args({ "weight": "1.", "tunable_param": "1." }))) mc.add( fst.MakeTrialTransfer( fst.args({ "particle_type": "0", "weight": "4" }))) mc.add( fst.MakeCheckEnergyAndTune( fst.args({ "steps_per": str(args.steps_per), "tolerance": "0.0001" }))) mc.add( fst.MakeLogAndMovie( fst.args({ "steps_per": str(args.steps_per), "file_name": "clones" + str(thread) }))) 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" }))) mc.add( fst.MakeEnergy( fst.args({ "steps_per_write": str(args.steps_per), "file_name": "en" + str(thread), "multistate": "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
def mc(thread, mn, mx): steps_per = int(1e4) mc = fst.MakeMonteCarlo() mc.add( fst.MakeConfiguration( fst.args({ "cubic_box_length": "12", "particle_type0": fst.install_dir() + "/plugin/charge/forcefield/rpm_plus.fstprt", "particle_type1": fst.install_dir() + "/plugin/charge/forcefield/rpm_minus.fstprt", "cutoff": "4.891304347826090", "charge0": str(1. / math.sqrt(fst.CODATA2018().charge_conversion())), "charge1": str(-1. / math.sqrt(fst.CODATA2018().charge_conversion())) }))) mc.add( fst.MakePotential( fst.MakeEwald( fst.args({ "alpha": str(6.87098396396261 / 12), "kmax_squared": "38" })))) mc.add( fst.MakePotential( fst.MakeModelTwoBodyFactory(fst.MakeHardSphere(), fst.MakeChargeScreened()), fst.args({"table_size": "1e6"}))) mc.add(fst.MakePotential(fst.MakeChargeSelf())) num_steps = "1" ref = "-1" if mx >= args.dccb_begin: mc.run( fst.MakeAddReference( fst.args({ "potential_index": "1", "cutoff": "1", "use_cell": "true" }))) ref = "0" num_steps = "4" beta = 1. / args.temperature mc.set( fst.MakeThermoParams( fst.args({ "beta": str(beta), "chemical_potential0": str(args.beta_mu / beta), "chemical_potential1": str(args.beta_mu / beta) }))) 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.min_sweeps)})), fst.MakeWLTM( fst.args({ "collect_flatness": "18", "min_flatness": "22", "min_sweeps": str(args.min_sweeps) })), fst.MakeAEqualB(fst.args({"extra_A": "1"})))) mc.add( fst.MakeTrialTranslate( fst.args({ "weight": "1.", "tunable_param": "1." }))) for particle_type in range(mc.configuration().num_particle_types()): mc.add( fst.MakeTrialTransfer( fst.args({ "weight": "4", "particle_type": str(particle_type), "reference_index": ref, "num_steps": num_steps }))) mc.add( fst.MakeCheckEnergy( fst.args({ "steps_per": str(steps_per), "tolerance": "0.0001" }))) mc.add( fst.MakeTune( fst.args({ "steps_per": str(steps_per), "stop_after_phase": "0" }))) mc.add( fst.MakeLogAndMovie( fst.args({ "steps_per": str(steps_per), "file_name": "clones" + str(thread), "file_name_append_phase": "True" }))) mc.add( fst.MakeEnergy( fst.args({ "steps_per_write": str(steps_per), "file_name": "en" + str(thread) + ".txt.", "file_name_append_phase": "True", "start_after_phase": "0", "multistate": "True" }))) mc.add(fst.MakeCriteriaUpdater(fst.args({"steps_per": str(steps_per)}))) mc.add( fst.MakeCriteriaWriter( fst.args({ "steps_per": str(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": str(0.1 * args.num_procs * args.num_hours), "num_hours_terminate": str(0.9 * args.num_procs * args.num_hours) }))) return mc
def mc(thread, mn, mx): steps_per = str(int(1e5)) mc = fst.MakeMonteCarlo() #mc.set(fst.MakeRandomMT19937(fst.args({"seed": "12345"}))) #mc.set(fst.MakeRandomMT19937(fst.args({"seed": "1634926410"}))) chi = 0.7 # patch coverage patch_angle = 2 * math.asin(math.sqrt(chi / 2)) * 180 / math.pi print('patch_angle', patch_angle) mc = fst.MonteCarlo() config = fst.MakeConfiguration( fst.args({ "cubic_box_length": "8", "particle_type0": fst.install_dir() + "/plugin/patch/forcefield/two_patch_linear.fstprt" })) config.add(fst.MakeGroup(fst.args({"site_type0": "0"}))) mc.add(config) mc.add( fst.MakePotential( fst.MakeHardSphere(), fst.MakeVisitModelCell( fst.args({ "min_length": "1", "cell_group": "1" })), fst.args({"group_index": "1"}))) patch = fst.MakeVisitModelInnerPatch( fst.args({"patch_degrees_of_type1": str(patch_angle)})) mc.add( fst.MakePotential( fst.MakeSquareWell(), fst.MakeVisitModel(patch), #fst.MakeVisitModelCell(patch, fst.args({"min_length": "1.5", "cell_group": "1"})), fst.args({"group_index": "1"}))) mc.set( fst.MakeThermoParams( fst.args({ "beta": str(1. / args.temperature), "chemical_potential": str(args.mu) }))) 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.min_sweeps)})), fst.MakeWLTM( fst.args({ "collect_flatness": "18", "min_flatness": "22", "min_sweeps": str(args.min_sweeps) })))) mc.add( fst.MakeTrialTranslate( fst.args({ "weight": "0.5", "tunable_param": "0.1" }))) mc.add( fst.MakeTrialRotate(fst.args({ "weight": "0.5", "tunable_param": "20." }))) mc.add( fst.MakeTrialTransfer(fst.args({ "weight": "4", "particle_type": "0" }))) # mc.add(fst.MakeTrialGrow(fst.ArgsVector([{"translate": "true", "site": "0", "tunable_param": "1"}]), # {"reference_index": ref, "num_steps": num_steps})) # mc.add(fst.MakeTrialGrow(fst.ArgsVector([{"transfer": "true", "site": "0", "weight": "4"}]), # {"reference_index": ref, "num_steps": num_steps})) mc.add( fst.MakeCheckEnergy( fst.args({ "steps_per": steps_per, "tolerance": "0.0001" }))) mc.add( fst.MakeTune( fst.args({ "steps_per": steps_per, "stop_after_phase": "0" }))) mc.add( fst.MakeLog( fst.args({ "steps_per": steps_per, "file_name": "clones" + str(thread) + ".txt", "file_name_append_phase": "True" }))) mc.add( fst.MakeMoviePatch( fst.args({ "steps_per": steps_per, "file_name": "clones" + str(thread) + ".xyz", "file_name_append_phase": "True" }))) mc.add( fst.MakeEnergy( fst.args({ "steps_per_write": steps_per, "file_name": "en" + str(thread) + ".txt", "file_name_append_phase": "True", "start_after_phase": "0", "multistate": "True" }))) mc.add(fst.MakeCriteriaUpdater(fst.args({"steps_per": steps_per}))) mc.add( fst.MakeCriteriaWriter( fst.args({ "steps_per": 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": str(0.1 * args.num_procs * args.num_hours), "num_hours_terminate": str(0.9 * args.num_procs * args.num_hours) }))) return mc
def mc(thread, mn, mx): steps_per = int(1e4) mc = fst.MakeMonteCarlo() if mx > args.dccb_begin: ref = "0" num = "4" else: ref = "-1" num = "1" config_args = dict() index = 0 thermo_params = {"beta": str(1. / args.temperature)} for part in args.particles: config_args["particle_type" + str(index)] = part thermo_params["chemical_potential" + str(index)] = str( args.beta_mu * args.temperature) index += 1 thermo_params["chemical_potential0"] = str( (args.delta_betamu_0 + args.beta_mu) * args.temperature) mc.add( fst.MakeConfiguration( fst.args( dict( { "side_length0": str(args.lx), "side_length1": str(args.ly), "side_length2": str(args.lz) }, **config_args)))) mc.add(fst.MakePotential(fst.MakeLennardJones())) 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.set(fst.MakeThermoParams(thermo_params)) 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" })))) for particle_type in range(mc.configuration().num_particle_types()): mc.add( fst.MakeTrialTranslate( fst.args({ "particle_type": str(particle_type), "weight": "1.", "tunable_param": "1." }))) if mx > args.dccb_begin and mc.configuration().particle_type( particle_type).num_sites() == 2: mc.add( fst.MakeTrialGrow( fst.ArgsVector([ { "transfer": "true", # "regrow": "true", # regrow isn't very efficient "particle_type": str(particle_type), "site": "0", "weight": "4" }, { "bond": "true", "mobile_site": "1", "anchor_site": "0" } ]), fst.args({ "reference_index": ref, "num_steps": num }))) mc.add( fst.MakeTrialGrow( fst.ArgsVector([{ "particle_type": str(particle_type), "weight": "0.5", "bond": "true", "mobile_site": "1", "anchor_site": "0", "reference_index": ref, "num_steps": num }]))) mc.add( fst.MakeTrialGrow( fst.ArgsVector([{ "particle_type": str(particle_type), "weight": "0.5", "bond": "true", "mobile_site": "0", "anchor_site": "1", "reference_index": ref, "num_steps": num }]))) else: mc.add( fst.MakeTrialRotate( fst.args({ "particle_type": str(particle_type), "weight": "1.", "tunable_param": "1." }))) mc.add( fst.MakeTrialTransfer( fst.args({ "particle_type": str(particle_type), "weight": "4" }))) mc.add( fst.MakeCheckEnergy( fst.args({ "steps_per": str(steps_per), "tolerance": "0.0001" }))) mc.add( fst.MakeTune( fst.args({ "steps_per": str(steps_per), "stop_after_phase": "0" }))) mc.add( fst.MakeLogAndMovie( fst.args({ "steps_per": str(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(steps_per), "steps_per_update": "1", "multistate": "True" }))) if mc.configuration().num_particle_types() > 1: mc.add( fst.MakeNumParticles( fst.args({ "particle_type": "0", "file_name": "num" + str(thread) + '.txt', "file_name_append_phase": "True", "start_after_phase": "0", "steps_per_write": str(steps_per), "steps_per_update": "1", "multistate": "True" }))) mc.add( fst.MakeExtensiveMoments( fst.args({ "steps_per_write": str(steps_per), "file_name": "extmom" + str(thread) + ".txt", "file_name_append_phase": "True", "start_after_phase": "0", # do not update until equilibration complete (phase 1) "max_order": "3", "multistate": "True" }))) mc.add(fst.MakeCriteriaUpdater(fst.args({"steps_per": str(steps_per)}))) mc.add( fst.MakeCriteriaWriter( fst.args({ "steps_per": str(steps_per), "file_name": "clones" + str(thread) + "_crit.txt", "file_name_append_phase": "True" }))) print(0.9 * args.num_procs * args.num_hours) 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