Пример #1
0
    def test(self):
        space = feasst.Space(3)
        space.initBoxLength(8)
        pair = feasst.PairLJ(space, 3)  # potential truncation at 3
        molNameSS = space.install_dir() + "/forcefield/data.lj"
        pair.initData(molNameSS)  # initialize the sigma and epsilon

        # 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.vol() \
          *((1./3.)*pair.rCut()**(-9) - pair.rCut()**(-3))
        self.assertAlmostEqual(pair.peLRC(), peExactLRC, 15)

        # second, compare with the reference configuration
        config = space.install_dir() + \
          "/testcase/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)
Пример #2
0
    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))
Пример #3
0
    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))
Пример #4
0
    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))
Пример #5
0
    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()
Пример #6
0
    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)
Пример #7
0
	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
Пример #8
0
                    type=str)
args = parser.parse_args()
print(args)

# if the lnz was set to some value, reweight to the given lnz
if (args.lnz != LNZDEFAULT):
    criteria = feasst.CriteriaWLTMMC(args.inFile)
    criteria.readCollectMat(args.inFile)
    criteria.lnPIrw(math.exp(args.lnz))
    criteria.printRWinit()
    criteria.printCollectMat(args.outFile)

# otherwise, attempt to find saturation and reweight the lnzsat
else:
    # if volume is not given or unphysical, attempt to find volume from restart
    if (args.volume < 0):
        assert (os.path.isfile(args.rstFile))  # provide either -v or -r flags
        space = feasst.Space(args.rstFile)
    else:
        space = feasst.Space()
        space.initBoxLength(1)
        space.scaleDomain(args.volume)

    pair = feasst.PairIdeal(space)
    criteria = feasst.CriteriaWLTMMC(args.inFile)
    wltmmc = feasst.WLTMMC(space, pair, criteria)
    criteria.readCollectMat(args.inFile)
    if (args.phaseBoundary != -1):
        criteria.setPhaseBoundary(args.phaseBoundary)
    wltmmc.printSat()
Пример #9
0
    def test(self):

        for srswConfig in range(1, 3):
            space = feasst.Space(3)
            space.initBoxLength(20.)
            pair = feasst.PairLJCoulEwald(space, 10.)
            pair.initData(space.install_dir() + "/forcefield/data.spce")
            pair.initKSpace(
                5.6,  # alpha*L
                27)  # k^2 < k2max cutoff

            # Set atom-based cut-off for comparison to SRSW reference config
            # Warning: atom-based cut-offs will fail because an optimized routine for
            # molecule-based cutoff is used by Monte Carlo trials.
            pair.initAtomCut(1)
            for iType in range(space.nParticleTypes()):
                for jType in range(space.nParticleTypes()):
                    pair.rCutijset(iType, jType, pair.rCut())

            # Read the configuration
            conf_file = feasst.make_ifstream(space.install_dir() + \
                "/testcase/3_spce/1_ref-config/spce_sample_config_periodic" + \
                str(srswConfig) + ".xyz")
            pair.readxyz(conf_file)
            pair.erfTable().tableOff()  # turn off the error function table
            pair.initEnergy()

            # Compare with the SRSW
            KJperMol2Kelvin = 1e3 / feasst.idealGasConstant
            if srswConfig == 1:
                self.assertEqual(100, space.nMol())
                self.assertAlmostEqual(pair.peLJ() * KJperMol2Kelvin,
                                       99538.736236886805,
                                       delta=feasst.DTOL)
                self.assertAlmostEqual(pair.peLRC() * KJperMol2Kelvin,
                                       -823.71499511652178,
                                       delta=feasst.DTOL)
                self.assertAlmostEqual(pair.peQReal() * KJperMol2Kelvin,
                                       -558888.91972785105,
                                       delta=1e-9)
                self.assertAlmostEqual(pair.peQFrr() * KJperMol2Kelvin,
                                       6270.0937839397402,
                                       delta=1e-11)
                # Note, this is the negative of the sum of E_self and E_intra in SRSW
                self.assertAlmostEqual(pair.peQFrrSelf() * KJperMol2Kelvin,
                                       34699.373693030466,
                                       delta=1e-9)
                self.assertAlmostEqual(pair.peTot() * KJperMol2Kelvin,
                                       -488603.17839517148,
                                       delta=1e-9)
            elif srswConfig == 2:
                self.assertEqual(200, space.nMol())
                self.assertAlmostEqual(pair.peLJ() * KJperMol2Kelvin,
                                       193712.42256683594,
                                       delta=feasst.DTOL)
                self.assertAlmostEqual(pair.peLRC() * KJperMol2Kelvin,
                                       -3294.8599804660735,
                                       delta=feasst.DTOL)
                self.assertAlmostEqual(pair.peQReal() * KJperMol2Kelvin,
                                       -1192948.6940245957,
                                       delta=1e-8)
                self.assertAlmostEqual(pair.peQFrr() * KJperMol2Kelvin,
                                       6034.9503269097158,
                                       delta=1e-9)
                # Note, this is the negative of the sum of E_self and E_intra in SRSW
                self.assertAlmostEqual(pair.peQFrrSelf() * KJperMol2Kelvin,
                                       69398.747386013289,
                                       delta=1e-9)
                self.assertAlmostEqual(pair.peTot() * KJperMol2Kelvin,
                                       -1065894.9284973294,
                                       delta=1e-8)
Пример #10
0
"""
 * FEASST - Free Energy and Advanced Sampling Simulation Toolkit
 * 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))