Example #1
0
        for m in self.minimizer:
            pl.loglog(np.array(m[3]), label=m[0])

        pl.legend()
        #pl.semilogy()
        pl.xlabel("energy evaluations")
        pl.ylabel("energy")
        pl.show()


if __name__ == "__main__":
    import pygmin.potentials.lj as lj
    import scipy.optimize
    from pygmin.optimize import _quench as quench
    print "Running benchmark with lennard jones potential"
    pot = lj.LJ()

    natoms = 36

    coords = np.random.random(3 * natoms) * 10.0
    res = quench.lbfgs_scipy(coords, pot, tol=1e-3)
    coords = res.coords
    coords = coords + np.random.random(coords.shape) * 0.1
    res = quench.lbfgs_scipy(coords, pot, tol=1e-3)
    Emin = res.energy

    bench = QuenchBenchmark(pot)
    bench.addMinimizer("lbfgs", quench.lbfgs_scipy)
    bench.addMinimizer("mylbfgs", quench.mylbfgs)
    bench.addMinimizer("lbfgs_py", quench.lbfgs_py)
    #bench.addMinimizer("lbfgs_ase", quench.lbfgs_ase)
Example #2
0
                        self.potential,
                        self.mcstep,
                        temperature=self.T,
                        outstream=None)
        mc.run(self.nsteps)
        coords[:] = mc.coords[:]

    def updateStep(self, acc, **kwargs):
        pass


natoms = 12

# random initial coordinates
coords = np.random.random(3 * natoms)
potential = lj.LJ()

reseed = TakeStepMonteCarlo(potential, T=100, nsteps=1000)
takestep = displace.RandomDisplacement(stepsize=0.5)

stepGroup = group.Reseeding(takestep, reseed, maxnoimprove=20)

opt = bh.BasinHopping(coords, potential, takeStep=stepGroup)
opt.run(100)

# some visualization
try:
    import pygmin.utils.pymolwrapper as pym
    pym.start()
    pym.draw_spheres(opt.coords, "A", 1)
except:
Example #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 pygmin.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