Exemple #1
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()
Exemple #2
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
Exemple #3
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)
Exemple #4
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()