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))
def test(self): space = feasst.Space(3) space.initBoxLength(24.8586887) # molecule-center based cut-off pair = feasst.PairLJCoulEwald(space, space.minl() / 2.) pair.initData(space.install_dir() + "/forcefield/data.spce") pair.initKSpace( 5.6, # alpha*L 38) # k^2 < k2max cutoff # Read the pre-equilibrated configuration of 512 water molecules conf_file = feasst.make_ifstream(space.install_dir() + \ "/testcase/3_spce/2_nvt-mc/test.xyz") pair.readxyz(conf_file) pair.initEnergy() # 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) mc.initLog("log", int(1e4)) mc.initMovie("movie", int(1e4)) mc.initRestart("tmp/rst", int(1e4)) mc.setNFreqTune(int(1e4)) mc.runNumTrials(int(1e6)) # run equilibration # Run the production simulation mc.zeroStat() 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. # pePublish = -46.82 # published value pePublishStd = 0.02 self.assertAlmostEqual(peAv, pePublish, delta=2.576 * (pePublishStd + peStd))
def test(self): space = feasst.Space(3) rho = 1e-3 # number density nMol = 500 # number of particles space.initBoxLength( (float(nMol) / rho)**(1. / 3.)) # set the cubic PBCs pair = feasst.PairHardSphere(space) pair.initData(space.install_dir() + "/forcefield/data.atom") pair.initEnergy() criteria = feasst.CriteriaMetropolis(1., 1.) mc = feasst.MC(space, pair, criteria) feasst.transformTrial(mc, "translate", 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.runNumTrials(int(1e7)) # run equilibration # Run the production simulation mc.runNumTrials(int(1e7))
def test(self): space = feasst.Space(3) rho = 1e-3 # number density nMol = 500 # number of particles space.initBoxLength( (float(nMol) / rho)**(1. / 3.)) # set the cubic PBCs molNameSS = space.install_dir() + "/forcefield/data.lj" space.addMolInit(molNameSS) pair = feasst.PairLJ(space, 3) # potential truncation at 3 pair.initEnergy() temperature = 0.9 criteria = feasst.CriteriaMetropolis(1. / temperature, 1.) mc = feasst.MC(space, pair, criteria) feasst.transformTrial(mc, "translate", 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.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))
def run(self, orderMax=100, orderMin=0, temp=1.50, mu1=0.0, dmu2=0.0, order=3, steps=10000): """ Run a new simulation from scratch. Parameters ---------- orderMax : int Max number of particles to allow in this window (default=100) orderMin : int Min number of particles to allow in this window (default=0) temp : double Temperature (default = 1.5) mu1 : double Chemical potential of species 1 dmu2 : double mu2 - mu1 order : int Max order to record extensive moments up to steps : int Number of MC steps to perform """ s = feasst.Space(3, 0) s.lset(15) p = feasst.PairLJMulti(s, s.minl() / 4.0) molA = os.path.dirname(os.path.realpath(__file__)) + "/data.lj" molB = os.path.dirname(os.path.realpath(__file__)) + "/data.ljb" s.addMolInit(molA) p.initLMPData(molA) s.addMolInit(molB) p.initLMPData(molB) p.rCutijset(0, 0, (p.sig(0) + p.sig(0)) / 2 * 3.0) p.rCutijset(0, 1, (p.sig(0) + p.sig(1)) / 2 * 3.0) p.rCutijset(1, 1, (p.sig(1) + p.sig(1)) / 2 * 3.0) for i in range(2): for j in range(2): p.linearShiftijset(i, j, True) s.updateCells( p.rCutMaxAll()) # intermolecular potential needs max rcut barrier = feasst.SpeciesBarriers(s.nParticleTypes()) radius = 4.0 # this goes to CENTER OF MASS, so pore radius actually = 4.5 with sigma/2 exclusion eps_w = 3.0 width = 0.5 pt = [0.0, 0.0, 0.0] barrier.addSqwCylinder(0, pt, radius, eps_w, width, 0) barrier.addSqwCylinder(1, pt, radius - (p.sig(1) - p.sig(0)) / 2, eps_w / 2.0, width, 0) pairBarr = feasst.PairBarriers(s, barrier) ipair = feasst.PairHybrid(s, max(p.rCutMaxAll(), width)) ipair.addPair(p) ipair.addPair(pairBarr) ipair.initEnergy() assert ( barrier.safe(ipair) ) # check barrier doesn't violate any boundary conditions or allow periodic interactions orderParam = "nmol" beta = 1.0 / temp cc = feasst.CriteriaWLTMMC(beta, math.exp(beta * mu1), orderParam, orderMin - 0.5 * 1.0, orderMax + 0.5 * 1.0, orderMax - orderMin + 1) cc.addActivity(math.exp(beta * (mu1 + dmu2))) mc = feasst.WLTMMC(s, ipair, cc) em = feasst.AnalyzeExtensiveMoments(s, ipair) em.setOrderParam(order, cc) mc.weight = 0.6 feasst.deleteTrial(mc, molA) mc.weight = 0.6 feasst.deleteTrial(mc, molB) mc.weight = 0.6 feasst.addTrial(mc, molA) mc.weight = 0.6 feasst.addTrial(mc, molB) mc.weight = 0.2 feasst.xswapTrial(mc) mc.weight = 0.4 feasst.transformTrial(mc, "translate", 0.4) mc.nMolSeek( orderMin, molA, 1000000) # mininum bound with pure A (smaller of the 2 species) nfreq = 100000 mc.initLog("log", nfreq) mc.initColMat("colMat", nfreq) mc.setNFreqCheckE(nfreq, 1e-8) mc.setNFreqTune(nfreq) mc.initMovie("movie", nfreq * 1000) mc.initRestart("tmp/rst", nfreq * 1000) em.initFreq(5) em.initPrintFreq(nfreq * 1000) em.initFileName("extMom") mc.initAnalyze(em) cc.collectInit(4.0e-6) # start collecting TMMC matric at wlFlat == 18 cc.tmmcInit(5.0e-7) # switch to TMMC after 22 mc.wlFlatProduction( 22 ) # after this # iterations, switch to "production" phase and measure mc.runNumTrials(steps) em.write()
def test(self): feasst.ranInitByDate() # initialize random number generator space = feasst.Space(3, 0) # initialize simulation domain space.initBoxLength(args.boxl) addMolType = space.install_dir() + "/forcefield/" + args.molName space.addMolInit(addMolType) # initialize pair-wise interactions pair = feasst.PairLJ(space, args.rCut) pair.initEnergy() # acceptance criteria nMolMin = 0 import math criteria = feasst.CriteriaWLTMMC(1. / args.temp, math.exp(args.lnz), "nmol", nMolMin, args.nMolMax) criteria.collectInit() criteria.tmmcInit() # initialize monte carlo mc = feasst.WLTMMC(space, pair, criteria) mc.weight = 3. / 4. feasst.transformTrial(mc, "translate") mc.weight = 1. / 8. feasst.deleteTrial(mc) mc.weight = 1. / 8. feasst.addTrial(mc, addMolType) # 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)
def run (self, **kwargs): """ Run a new simulation from scratch. Parameters ---------- orderMax : int Max number of particles to allow in this window (default=100) orderMin : int Min number of particles to allow in this window (default=0) temp : double Temperature (default = 1.5) mu1 : double Chemical potential of species 1 dmu2 : double mu2 - mu1 order : int Max order to record extensive moments up to steps : int Number of MC steps to perform lam11 : float Value of lambda_11 lam22 : float Value of lambda_22 molA : string Filename for molA (1) molB : string Filename for molB (2) """ self.parse(kwargs) s = feasst.Space(3,0) s.lset(9.0) p = feasst.PairLJMulti(s, s.minl()/2.0) s.addMolInit(self.molA) p.initLMPData(self.molA) s.addMolInit(self.molB) p.initLMPData(self.molB) # Force-shift potential for each pair p.rCutijset(0,0,(p.sig(0)+p.sig(0))/2*3.0) p.rCutijset(0,1,(p.sig(0)+p.sig(1))/2*3.0) p.rCutijset(1,1,(p.sig(1)+p.sig(1))/2*3.0) p.setLambdaij(0,0, self.lam11) p.setLambdaij(0,1, 0.5*(self.lamm11+self.lam22)) # LB mixing p.setLambdaij(1,1, self.lam22) p.lrcFlag = 0; for i in range(2): for j in range(2): p.linearShiftijset(i,j,True) s.updateCells(p.rCutMaxAll()) # intermolecular potential needs max rcut ipair = feasst.PairHybrid (s, p.rCutMaxAll()) ipair.addPair(p) ipair.initEnergy() orderParam = "nmol" beta = 1.0/self.temp cc = feasst.CriteriaWLTMMC (beta, math.exp(beta*self.mu1), orderParam, self.orderMin-0.5*1.0, self.orderMax+0.5*1.0, self.orderMax-self.orderMin+1) cc.addActivity(math.exp(beta*(self.mu1+self.dmu2))) mc = feasst.WLTMMC (s, ipair, cc) em = feasst.AnalyzeExtensiveMoments(s, ipair) em.setOrderParam (self.order, cc) mc.weight = 0.6 feasst.deleteTrial(mc, self.molA) mc.weight = 0.6 feasst.deleteTrial(mc, self.molB) mc.weight = 0.6 feasst.addTrial(mc, self.molA) mc.weight = 0.6 feasst.addTrial(mc, self.molB) mc.weight = 0.2 feasst.xswapTrial(mc) mc.weight = 0.4 feasst.transformTrial(mc, "translate", 0.4) mc.nMolSeek(self.orderMin, self.molA, 1000000) # mininum bound with pure A (smaller of the 2 species) nfreq = 100000 mc.initLog("log", nfreq) mc.initColMat("colMat", nfreq*1000) mc.setNFreqCheckE(nfreq*1000, 1e-8) mc.setNFreqTune(nfreq*1000) mc.initMovie("movie", nfreq*1000) mc.initRestart("tmp/rst", nfreq*1000) em.initFreq(5) # from 1 -> 5 makes this as efficient as measuring 2nd vs 3rd order moments em.initPrintFreq(nfreq*1000) em.initFileName("extMom") mc.initAnalyze(em) cc.collectInit(4.0e-6) # start collecting TMMC matric at wlFlat == 18 cc.tmmcInit(5.0e-7) # switch to TMMC after 22 mc.wlFlatProduction(22) # after this number of iterations, switch to "production" phase and measure mc.runNumTrials(self.steps) em.write() # write at the end to ensure up-to-date
* Harold W. Hatch, [email protected] * * Permission to use this data/software is contingent upon your acceptance of * the terms of LICENSE.txt and upon your providing * appropriate acknowledgments of NIST's creation of the data/software. """ # # The following three lines are an alternative method to link _feasst.so # import os, sys # feasstdir = os.getenv("FEASST_INSTALL_DIR_") + "/build" # sys.path.append(feasstdir) import feasst feasst.ranInitByDate() space = feasst.makeSpace(3) space.initBoxLength(8) space.addMolInit("../forcefield/data.lj") pair = feasst.PairLJ(space, 3) # potential truncation at 3 pair.initEnergy() criteria = feasst.CriteriaMetropolis(1.2, 1.) # 1/kT = 1.2 mc = feasst.MC(space, pair, criteria) maxMoveParam = 0.1 feasst.transformTrial(mc, "translate", maxMoveParam) mc.nMolSeek(50) # add 50 particles mc.initLog("log", int(1e4)) mc.initMovie("movie", int(1e4)) mc.runNumTrials(int(1e6)) # mc.initWindows(1) # initialize parallel windows # mc.runNumSweeps(1, -1) # run until all windows sweep once
* http:#pages.nist.gov/feasst, National Institute of Standards and Technology * Harold W. Hatch, [email protected] * * Permission to use this data/software is contingent upon your acceptance of * the terms of LICENSE.txt and upon your providing * appropriate acknowledgments of NIST's creation of the data/software. """ import feasst space = feasst.Space(3) rho = 1e-3 # number density nMol = 500 # number of particles space.initBoxLength((float(nMol)/rho)**(1./3.)) # set the cubic PBCs pair = feasst.PairHardSphere(space) pair.initData(space.install_dir() + "/forcefield/data.atom") pair.initEnergy() criteria = feasst.CriteriaMetropolis(1., 1.) mc = feasst.MC(space, pair, criteria) feasst.transformTrial(mc, "translate", 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.runNumTrials(int(1e7)) # run equilibration # Run the production simulation mc.runNumTrials(int(1e7))