Ejemplo n.º 1
0
def add(monte_carlo, steps_per, proc="", log="log.txt", tolerance=1e-8):
    """Add Log, Movie, CheckEnergy and Tuner to monte_carlo

    steps_per -- perform analysis every this many steps
    proc -- append movie file name with proc
    log -- set the log file (default empty: standard output)
    """
    monte_carlo.add(
        feasst.MakeLog(
            feasst.args({
                "steps_per": str(steps_per),
                "file_name": str(log),
                "clear_file": "true"
            })))
    monte_carlo.add(
        feasst.MakeMovie(
            feasst.args({
                "steps_per": str(steps_per),
                "file_name": "movie" + str(proc) + ".xyz"
            })))
    monte_carlo.add(
        feasst.MakeCheckEnergy(
            feasst.args({
                "steps_per": str(steps_per),
                "tolerance": str(tolerance)
            })))
    monte_carlo.add(
        feasst.MakeTuner(feasst.args({"steps_per": str(steps_per)})))
Ejemplo n.º 2
0
def criteria_flathist(
    temperature=1.5,
    chemical_potential=-2.352321,
    macro_min=0,  # minimum macrostate
    macro_max=370,  # maximum macrostate
    tmmc=True,  # use Transition-Matrix (TM) if true, else Wang-Landau (WL)
    iterations=20):  # number of sweeps (TM) or flatness (WL)
    """Return a flat histogram acceptance criteria with number of particles as the macrostate"""
    if tmmc:
        bias = fst.MakeTransitionMatrix(
            fst.args({"min_sweeps": str(iterations)}))
    else:
        bias = fst.MakeWangLandau(fst.args({"min_flatness": str(iterations)}))
    return fst.MakeFlatHistogram(
        fst.MakeMacrostateNumParticles(
            fst.Histogram(
                fst.args({
                    "width": "1",
                    "min": str(macro_min),
                    "max": str(macro_max)
                }))), bias,
        fst.args({
            "beta": str(1. / temperature),
            "chemical_potential": str(chemical_potential)
        }))
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
    def test(self):
        rho = 1e-3  # number density
        nMol = 500  # number of particles
        space = feasst.makeSpace(
            feasst.args({
                "dimen": "3",
                "boxLength": str((float(nMol) / rho)**(1. / 3.))
            }))
        pair = feasst.makePairLJ(
            space,
            feasst.args({
                "rCut": "3",  # potential truncation at 3
                "cutType": "lrc",
                "molTypeInForcefield": "data.lj"
            }))
        criteria = feasst.makeCriteriaMetropolis(
            feasst.args({"beta": str(1. / 0.9)}))
        mc = feasst.MC(pair, criteria)
        feasst.addTrialTransform(
            mc,
            feasst.args({
                "transType": "translate",
                "maxMoveParam": str(0.1)
            }))
        mc.nMolSeek(nMol)
        mc.initLog("log", int(1e4))
        mc.initMovie("movie", int(1e4))
        mc.initRestart("tmp/rst", int(1e4))
        mc.setNFreqTune(int(1e4))
        mc.setNFreqCheckE(int(1e4), 1e-6)
        mc.runNumTrials(int(1e7))  # run equilibration

        # Run the production simulation and compute statistics on potential energy
        mc.setNFreqTune(0)  # do not tune during production
        pe = feasst.Accumulator()
        from itertools import islice, count
        for itrial in islice(count(1), int(1e7) - 1):
            mc.runNumTrials(1)
            pe.accumulate(pair.peTot() / float(space.nMol()))

        # Check average energy against the NIST SRSW
        # https:#mmlapps.nist.gov/srs/LJ_PURE/mc.htm
        # https:#www.nist.gov/programs-projects/nist-standard-reference-simulation-website
        peAv = pe.average()
        peStd = pe.blockStdev()
        peSRSW = -9.9165E-03
        peSRSWstd = 1.89E-05
        self.assertAlmostEqual(peAv, peSRSW, delta=2.576 * (peSRSWstd + peStd))
Ejemplo n.º 5
0
    def test(self):
        space = feasst.Space(3)
        space.initBoxLength(8)
        pair = feasst.PairLJ(space, feasst.args(
            {"rCut" : "3",          # potential truncation at 3
             "cutType" : "lrc"}))   # long range corrections

        # create clones of Space and Pair to perform two separate tests
        space2 = space.clone()
        pair2 = pair.clone(space2)

        # first, test the interaction between two particles
        xAdd = feasst.DoubleVector(space.dimen())  # position to add is origin
        pair.addMol(xAdd)        # add first molecule
        r = 1.2345
        xAdd[0] = r              # position of second particle
        pair.addMol(xAdd)        # add second particle
        pair.initEnergy()        # compute energy
        peExact = 4*(pow(r, -12) - pow(r, -6))
        self.assertAlmostEqual(pair.peLJ(), peExact, 15)
        peExactLRC = (8./3.)*feasst.PI*space.nMol()**2/space.volume() \
          *((1./3.)*pair.rCut()**(-9) - pair.rCut()**(-3))
        self.assertAlmostEqual(pair.peLRC(), peExactLRC, 15)

        # second, compare with the reference configuration
        config = space.install_dir() + \
          "/tutorial/1_lj/1_ref-config/lj_sample_config_periodic4.xyz"
        conf_file = feasst.make_ifstream(config)
        pair2.readXYZ(conf_file)                  # read the xyz file
        pair2.initEnergy()                        # compute energy
        peLJ = -16.790321304625856
        peLRC = -0.5451660014945704
        self.assertAlmostEqual(pair2.peLRC(), peLRC, 15)
        self.assertAlmostEqual(pair2.peLJ(), peLJ, 15)
Ejemplo n.º 6
0
    def test(self):
        feasst.ranInitByDate()
        space = feasst.makeSpace(
            feasst.args({
                "dimen": "3",
                "boxLength": "24.8586887"
            }))

        pair = feasst.makePairLJCoulEwald(
            space,
            feasst.args({
                "rCut": str(space.minl() / 2.),
                "molTypeInForcefield": "data.spce",
                "alphaL": "5.6",
                "k2max": "38"
            }))

        # acceptance criteria
        temperature = 298  # Kelvin
        beta = 1. / (temperature * feasst.idealGasConstant / 1e3)  # mol/KJ
        criteria = feasst.CriteriaMetropolis(beta, 1.)
        mc = feasst.MC(space, pair, criteria)
        feasst.transformTrial(mc, "translate", 0.1)
        feasst.transformTrial(mc, "rotate", 0.1)
        mc.initLog("log", int(1e4))
        mc.initMovie("movie", int(1e4))
        mc.initRestart("tmp/rst", int(1e4))
        mc.setNFreqTune(int(1e4))
        mc.setNFreqCheckE(int(1e4), 1e-6)
        mc.nMolSeek(512)
        mc.runNumTrials(int(1e6))  # run equilibration

        # Run the production simulation
        mc.initProduction()
        mc.zeroStat()
        mc.setNFreqTune(0)
        mc.runNumTrials(int(1e6))

        # Check average energy against Gerhard Hummer
        # https:#doi.org/10.1063/1.476834
        peAv = mc.peAccumulator().average() / float(space.nMol())
        peStd = mc.peAccumulator().blockStdev() / float(space.nMol())
        pePublish = -46.82  # published value
        pePublishStd = 0.02
        self.assertAlmostEqual(peAv,
                               pePublish,
                               delta=2.576 * (pePublishStd + peStd))
Ejemplo n.º 7
0
    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()
Ejemplo n.º 8
0
def configuration(box_length=8, forcefield='data.lj', num=0):
    """Return an LJ configuration with cubic box and (optionally) cell list.

    box_length -- the length of the cubic peroidic boundary conditions
    forcefield -- the file describing the particle
    num -- the number of particles of the first type to add.
    """
    config = feasst.Configuration(
        feasst.MakeDomain(
            feasst.args({
                "cubic_box_length": str(box_length),
                "init_cells": "3"
            })),  # optionally attempt to create a cell list
        feasst.args({
            "particle_type":
            feasst.install_dir() + '/forcefield/' + forcefield
        }))
    for _ in range(num):
        config.add_particle_of_type(0)
    return config
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
def initialize_neighbor_list(mc):
    neigh_crit = fst.MakeNeighborCriteria(
        fst.args({
            "maximum_distance": "10",
            "minimum_distance": "2.5",
            "site_type0": "0",
            "site_type1": "0",
            "potential_index": "1"
        }))
    mc.add(neigh_crit)
    lj_and_coul = fst.MakeModelTwoBodyFactory()
    lj_and_coul.add(fst.MakeLennardJones())
    lj_and_coul.add(fst.MakeChargeScreened(fst.args({"table_size": "0"})))
    mc.set(
        1,
        fst.MakePotential(
            lj_and_coul,
            fst.MakeVisitModel(
                fst.MakeVisitModelInner(
                    fst.MakeEnergyMapNeighborCriteria(neigh_crit))),
            fst.args({"table_size": "1e6"})))
import matplotlib.pyplot as plt
import pandas as pd
import feasst as fst
import pyfeasst

num_procs = 12
clones = fst.MakeClones('checkpoint', num_procs)
beta = clones.clone(0).thermo_params().beta()
volume = clones.clone(0).configuration().domain().volume()
plt.plot(clones.ln_prob().values(), label='T*=' + str(1. / beta))
sat = list()
for extrap_temp in np.arange(0.8, 1.201, 0.05):
    extrap = fst.ExtrapolateBetaGCE(
        clones,
        fst.args({
            "beta_new": str(1 / extrap_temp),
            "beta_original": str(beta)
        }))
    extrap = pyfeasst.find_equilibrium(extrap, beta_mu_guess=-6)
    plt.plot(extrap.ln_prob().values(),
             label='T*=' + str(round(extrap_temp, 2)))

    # tabulate saturation properties
    num_vapor = extrap.average_macrostate(0)
    num_liquid = extrap.average_macrostate(1)
    sat.append([
        extrap_temp, num_vapor / volume, num_liquid / volume,
        extrap.betaPV() / volume * extrap_temp,
        extrap.average(extrap.energy(), 0) / num_vapor,
        extrap.average(extrap.energy(), 1) / num_liquid
    ])
Ejemplo n.º 12
0
import pandas as pd
import argparse
import matplotlib.pyplot as plt
import feasst as fst
import pyfeasst

parser = argparse.ArgumentParser()
parser.add_argument("--file_name", "-f", type=str, help="file name", action='append', required=True)
parser.add_argument("--label", "-l", type=str, help="variable label", default='ln_prob')
parser.add_argument("--delta_conjugate", "-d", type=float, help="reweight by change in conjugate variable", default=0.)
args = parser.parse_args()
print(args.file_name)

for fname in args.file_name:
    df = pd.read_csv(fname, header=pyfeasst.line_beginning_with_state(fname))
    gce = fst.GrandCanonicalEnsemble(
        fst.Histogram(fst.args({"width": "1", "max": str(df["state"].iloc[-1]),
                                              "min": str(df["state"].iloc[0])})),
        fst.LnProbability(fst.DoubleVector(df["ln_prob"])))
    #print(df)
    #plt.plot(df['state'], df[args.label], label=fname)
    gce.reweight(args.delta_conjugate)
    plt.plot(df['state'], gce.ln_prob().values(), label=fname)
plt.legend()
plt.show()
Ejemplo n.º 13
0
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
Ejemplo n.º 14
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()
Ejemplo n.º 15
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
Ejemplo n.º 16
0
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))
Ejemplo n.º 17
0
    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


windows = fst.WindowExponential(
    fst.args({
        "alpha": "1.75",
        "num": str(args.num_procs),
        "minimum": str(args.min_particles),
        "maximum": str(args.max_particles),
        "extra_overlap": "0"
    })).boundaries()
print(windows)

if args.task == 0:
    clones = fst.MakeClones()
    for proc, win in enumerate(windows):
        clones.add(mc(proc, win[0], win[1]))
    clones.set(fst.MakeCheckpoint(fst.args({"file_name": "checkpoint.fst"})))
else:
    clones = fst.MakeClones("checkpoint", args.num_procs)
#clones.initialize_and_run_until_complete()
clones.initialize_and_run_until_complete(
    fst.args({"ln_prob_file": "ln_prob.txt"}))
Ejemplo n.º 18
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
Ejemplo n.º 19
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(
Ejemplo n.º 20
0
    type=int,
    help="total number of trials (equilibration and production)",
    default=int(3e8))
parser.add_argument("--num_hours",
                    type=float,
                    help="number of hours before restart",
                    default=1.)
args = parser.parse_args()
print("args:", args)

mc = fst.MonteCarlo()
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",
Ejemplo n.º 21
0
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
Ejemplo n.º 22
0
import feasst
space = feasst.makeSpace(feasst.args(
    {"dimen" : "3",                 # 3D space
     "boxLength" : "8"}))           # cubic periodic boundaries
pair = feasst.makePairLJ(space, feasst.args(
    {"rCut" : "3",                  # potential truncation
     "cutType" : "lrc"}))           # long range corrections
criteria = feasst.makeCriteriaMetropolis(feasst.args(
    {"beta" : "1.2"}))              # beta = 1/k_B/T
mc = feasst.MC(pair, criteria)
feasst.addTrialTransform(mc, feasst.args(
    {"transType" : "translate",          # attempt particle translations
     "maxMoveParam" : "0.1"}))   # maximum displacement for each dimension
mc.nMolSeek(50)                     # add particles
mc.initLog("log", int(1e4))         # output instantaneous values
mc.initMovie("movie", int(1e4))     # output xyz trajectory
mc.runNumTrials(int(1e6))           # perform MC trials
Ejemplo n.º 23
0
    def test(self):
        feasst.ranInitByDate()  # initialize random number generator
        space = feasst.makeSpace(
            feasst.args({
                "dimen": "3",
                "boxLength": str(args.boxl)
            }))

        # initialize pair-wise interactions
        pair = feasst.PairLJ(
            space,
            feasst.args({
                "rCut": str(args.rCut),
                "cutType": "lrc",
                "molTypeInForcefield": args.molName
            }))

        # acceptance criteria
        nMolMin = 0
        import math
        criteria = feasst.makeCriteriaWLTMMC(
            feasst.args({
                "beta": str(1. / args.temp),
                "activ": str(math.exp(args.lnz)),
                "mType": "nmol",
                "nMin": str(nMolMin),
                "nMax": str(args.nMolMax)
            }))
        criteria.collectInit()
        criteria.tmmcInit()

        # initialize monte carlo
        mc = feasst.WLTMMC(pair, criteria)
        mc.weight = 3. / 4.
        feasst.transformTrial(mc, "translate")
        mc.weight = 1. / 8.
        feasst.deleteTrial(mc)
        mc.weight = 1. / 8.
        feasst.addTrial(mc, space.addMolListType(0))

        # output log, lnpi and movie
        mc.initLog("log", args.nfreq)
        mc.initColMat("colMat", args.ncfreq)
        mc.setNFreqCheckE(args.ncfreq, 1e-8)
        mc.setNFreqTune(args.nfreq)
        mc.initMovie("movie", args.nfreq)
        #mc.initXTC("movie", args.nfreq)
        mc.initRestart("tmp/rst", args.ncfreq)

        # production tmmc simulation
        if args.openMP:
            mc.initWindows(
                2.,  # exponent that determines size of windows
                0)  # extra macrostate overlap between processors
        mc.runNumSweeps(
            20,  # number of "sweeps"
            -1)  # maximum number of trials. Infinite if "-1".

        # test against SRSW values
        self.assertAlmostEqual(criteria.pe(0).average(), 0, 13)
        compareEnergyAndMacro(criteria, 1, self, -0.0006057402333333332,
                              6.709197666659334e-10,
                              -270.0061768 + 274.6763737666667,
                              0.037092307087640365)

        compareEnergyAndMacro(criteria, 2, self, -0.030574223333333334,
                              9.649146611661053e-06,
                              -266.0191155333334 + 274.6763737666667,
                              0.03696447428346385)

        compareEnergyAndMacro(criteria, 3, self, -0.089928316,
                              0.0001387472078025413,
                              -262.4277240666667 + 274.6763737666667,
                              0.037746391500313385)

        compareEnergyAndMacro(criteria, 4, self, -0.1784570533333333,
                              3.3152449884326804e-05,
                              -259.11444086666665 + 274.6763737666667,
                              0.03809721387875822)

        compareEnergyAndMacro(criteria, 5, self, -0.29619201333333334,
                              1.3487910636322294e-05,
                              -256.0144809 + 274.6763737666667,
                              0.03845757460933292)