示例#1
0
文件: test.py 项目: ishan111/feasst
    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)
        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))
示例#3
0
文件: test.py 项目: ishan111/feasst
    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)
示例#4
0
文件: lj.py 项目: ishan111/feasst
 * 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