コード例 #1
0
ファイル: 6_reseeding.py プロジェクト: yangxi1209/pele
 def takeStep(self, coords, **kwargs):
     # ake a new monte carlo class
     mc = MonteCarlo(coords,
                     self.potential,
                     self.mcstep,
                     temperature=self.T,
                     outstream=None)
     mc.run(self.nsteps)
     coords[:] = mc.coords[:]
コード例 #2
0
#set up the step taking routine
#Normal basin hopping takes each step from the quenched coords.  This modified step taking routine takes a step from the 
#last accepted coords, not from the quenched coords
from pele.take_step.random_displacement import takeStep
takestep = takeStep(stepsize=.01)


#pass a function which rejects the step if the system leaved the inital basin.
import do_quenching
dostuff = do_quenching.DoQuenching(pot, coords, quench=quench)
accept_test_list = [dostuff.acceptReject]





#set up basin hopping
from pele.mc import MonteCarlo
temperature = 1.0
event_after_step = []
mc = MonteCarlo(coords, pot, takestep, \
                  event_after_step = event_after_step, \
                  acceptTests = accept_test_list, temperature = temperature)

#run basin hopping
mc.run(200)

print mc.naccepted, "steps accepted out of", mc.stepnum
print "quench: ", dostuff.nrejected, "steps rejected out of", dostuff.ntot

コード例 #3
0
def runptmc(nsteps_tot=100000):
    natoms = 31
    nreplicas = 4
    Tmin = 0.2
    Tmax = 0.4

    nsteps_equil = 10000
    nsteps_tot = 100000
    histiprint = nsteps_tot / 10
    exchange_frq = 100 * nreplicas

    coords = np.random.random(3 * natoms)
    #quench the coords so we start from a reasonable location
    mypot = lj.LJ()
    ret = quench(coords, mypot)
    coords = ret.coords

    Tlist = getTemps(Tmin, Tmax, nreplicas)
    replicas = []
    ostreams = []
    histograms = []
    takesteplist = []
    radius = 2.5
    # create all the replicas which will be passed to PTMC
    for i in range(nreplicas):
        T = Tlist[i]
        potential = lj.LJ()

        takestep = RandomDisplacement(stepsize=0.01)
        adaptive = AdaptiveStepsize(takestep, last_step=nsteps_equil)
        takesteplist.append(adaptive)

        file = "mcout." + str(i + 1)
        ostream = open(file, "w")

        hist = EnergyHistogram(-134., 10., 1000)
        histograms.append(hist)
        event_after_step = [hist]

        radiustest = SphericalContainer(radius)
        accept_tests = [radiustest]

        mc = MonteCarlo(coords, potential, takeStep=takestep, temperature=T, \
                        outstream=ostream, event_after_step = event_after_step, \
                        confCheck = accept_tests)
        mc.histogram = hist  #for convienence
        mc.printfrq = 1
        replicas.append(mc)

    #is it possible to pickle a mc object?
    #cp = copy.deepcopy(replicas[0])
    #import pickle
    #with open("mc.pickle", "w") as fout:
    #pickle.dump(takesteplist[0], fout)

    #attach an event to print xyz coords
    from pele.printing.print_atoms_xyz import PrintEvent
    printxyzlist = []
    for n, rep in enumerate(replicas):
        outf = "dumpstruct.%d.xyz" % (n + 1)
        printxyz = PrintEvent(outf, frq=500)
        printxyzlist.append(printxyz)
        rep.addEventAfterStep(printxyz)

    #attach an event to print histograms
    for n, rep in enumerate(replicas):
        outf = "hist.%d" % (n + 1)
        histprint = PrintHistogram(outf, rep.histogram, histiprint)
        rep.addEventAfterStep(histprint)

    ptmc = PTMC(replicas)
    ptmc.use_independent_exchange = True
    ptmc.exchange_frq = exchange_frq
    ptmc.run(nsteps_tot)

    #do production run
    #fix the step sizes
    #for takestep in takesteplist:
    #    takestep.useFixedStep()
    #ptmc.run(30000)

    if False:  #this doesn't work
        print "final energies"
        for rep in ptmc.replicas:
            print rep.temperature, rep.markovE
        for rep in ptmc.replicas_par:
            print rep.mcsys.markovE
        for k in range(nreplicas):
            e, T = ptmc.getRepEnergyT(k)
            print T, e

    if False:  #this doesn't work
        print "histograms"
        for i, hist in enumerate(histograms):
            fname = "hist." + str(i)
            print fname
            with open(fname, "w") as fout:
                for (e, visits) in hist:
                    fout.write("%g %d\n" % (e, visits))

    ptmc.end()  #close the open threads