def system(config, alphaL=5.6, kmax_squared=38, rcut=False): if rcut: config.set_model_param("cutoff", 0, rcut) config.set_model_param("cutoff", 1, rcut) system = feasst.System() system.add(config) system.add( feasst.Potential( feasst.MakeEwald( feasst.args({ "kmax_squared": str(kmax_squared), "alpha": str(alphaL / system.configuration().domain().min_side_length()) })))) # Unfortunatley, swig isn't accepting the below method of constructing a two body factory # system.add(feasst.Potential(feasst.MakeModelTwoBodyFactory( # feasst.ModelTwoBodyVector([feasst.MakeLennardJones(), feasst.MakeChargeScreened()])))) two = feasst.MakeModelTwoBodyFactory() two.add(feasst.MakeLennardJones()) two.add(feasst.MakeChargeScreened()) system.add(feasst.Potential(two)) system.add( feasst.Potential(feasst.MakeChargeScreenedIntra(), feasst.MakeVisitModelBond())) system.add(feasst.Potential(feasst.MakeChargeSelf())) system.add(feasst.Potential(feasst.MakeLongRangeCorrections())) # system.precompute() return system
def system(config): """Return an LJ system with long-range corrections and (optionally) an optimized potential. config -- the configuration """ sys = feasst.System() sys.add(config) sys.add(feasst.Potential(feasst.MakeLennardJones())) sys.add(feasst.Potential(feasst.MakeLongRangeCorrections())) # If the requested cell list spacing is not large enough for the box, the cell list will # be disabled even if a cell list was requested previously. if sys.configuration().domain().is_cell_enabled(): # While adding a potential is by default considered an "unoptimized" # potential, a system may also contain an optimized potential. # Optimized potentials are used for most energy calculations, but # CheckEnergy asserts that it is equivalent to the unoptimized # potential. sys.add_to_optimized( feasst.Potential(feasst.MakeLennardJones(), feasst.MakeVisitModelCell())) sys.add_to_optimized( feasst.Potential(feasst.MakeLongRangeCorrections())) # While the cell list is optimized, the LRCs are not. Regardless, the LRCs are added so # that the energy is equivalent to the unoptimized potentials. return sys
def lj_system(box_length, cutoff): system = feasst.System() config = feasst.Configuration( feasst.MakeDomain(feasst.args({"cubic_box_length": str(box_length)})), feasst.args( {"particle_type": feasst.install_dir() + "/forcefield/lj.fstprt"})) config.set_model_param("cutoff", 0, cutoff) system.add(config) system.add(feasst.Potential(feasst.MakeLennardJones())) if system.configuration().domain().is_cell_enabled(): #system.add_to_optimized(feasst.Potential(feasst.MakeLennardJones(), feasst.MakeVisitModelCell())) system.add_to_reference( feasst.Potential(feasst.MakeHardSphere(), feasst.MakeVisitModelCell())) return system
def lj_system(box_length): system = feasst.System() config = feasst.Configuration( feasst.Domain(feasst.args({"cubic_box_length": str(box_length)})), feasst.args({"particle_type": feasst.install_dir() + "/forcefield/lj.fstprt"})) config.set_model_param("cutoff", 0, args.cutoff) system.add(config) system.add(feasst.Potential(feasst.MakeLennardJones())) return system
def system(config=None, box_length=8.109613, alphaL=6.870983963962610000, kmax_squared=38, rcut=4.891304347826090): if not config: config = feasst.Configuration( feasst.MakeDomain( feasst.args({"cubic_box_length": str(box_length)})), feasst.args({ "particle_type0": feasst.install_dir() + "/plugin/ewald/forcefield/data.rpm_plus", "particle_type1": feasst.install_dir() + "/plugin/ewald/forcefield/data.rpm_minus" })) config.set_model_param("cutoff", 0, rcut) config.set_model_param("cutoff", 1, rcut) system = feasst.System() system.add(config) system.add( feasst.Potential( feasst.MakeEwald( feasst.args({ "kmax_squared": str(kmax_squared), "alpha": str(alphaL / system.configuration().domain().min_side_length()) })))) # Unfortunatley, swig isn't accepting the below method of constructing a two body factory # system.add(feasst.Potential(feasst.MakeModelTwoBodyFactory( # feasst.ModelTwoBodyVector([feasst.MakeLennardJones(), feasst.MakeChargeScreened()])))) two = feasst.MakeModelTwoBodyFactory() two.add(feasst.MakeHardSphere()) two.add(feasst.MakeChargeScreened()) system.add(feasst.Potential(two)) system.add(feasst.Potential(feasst.MakeChargeSelf())) # system.precompute() return system
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
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(
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