def test_basin_hopping(pot, angles): from pygmin.basinhopping import BasinHopping from pygmin.takestep.displace import RandomDisplacement from pygmin.takestep.adaptive import AdaptiveStepsize takestep = RandomDisplacement(stepsize=np.pi / 4) takestepa = AdaptiveStepsize(takestep, frequency=20) bh = BasinHopping(angles, pot, takestepa, temperature=1.01) bh.run(20)
def getSetOfMinLJ(natoms = 11): #for testing purposes from pygmin.potentials.lj import LJ pot = LJ() coords = np.random.uniform(-1,1,natoms*3) from pygmin.basinhopping import BasinHopping from pygmin.takestep.displace import RandomDisplacement from pygmin.takestep.adaptive import AdaptiveStepsize from pygmin.storage.savenlowest import SaveN saveit = SaveN(10) takestep1 = RandomDisplacement() takestep = AdaptiveStepsize(takestep1, frequency=15) bh = BasinHopping(coords, pot, takestep, storage=saveit, outstream=None) bh.run(100) return pot, saveit
def guesstsLJ(): from pygmin.potentials.lj import LJ pot = LJ() natoms = 9 coords = np.random.uniform(-1, 1, natoms * 3) from pygmin.basinhopping import BasinHopping from pygmin.takestep.displace import RandomDisplacement from pygmin.takestep.adaptive import AdaptiveStepsize from pygmin.storage.savenlowest import SaveN saveit = SaveN(10) takestep1 = RandomDisplacement() takestep = AdaptiveStepsize(takestep1, frequency=15) bh = BasinHopping(coords, pot, takestep, storage=saveit, outstream=None) bh.run(100) coords1 = saveit.data[0].coords coords2 = saveit.data[1].coords return guessts(coords1, coords2, pot)
#def center(E, coords, accepted): # c = np.reshape() natoms = 40 coords = np.random.rand(natoms * 3) lj = LJ() ret = quench(coords, lj) coords = ret.coords takestep = TakeStep(stepsize=0.1) #do equilibration steps, adjusting stepsize tsadapt = AdaptiveStepsize(takestep) mc = MonteCarlo(coords, lj, tsadapt, temperature=0.5) equilout = open("equilibration", "w") #mc.outstream = equilout mc.setPrinting(equilout, 1) mc.run(10000) #fix stepsize and do production run mc.takeStep = takestep mcout = open("mc.out", "w") mc.setPrinting(mcout, 10) #print coords from time to time xyzout = open("out.xyz", "w") printevent = PrintEvent(xyzout, 300) mc.addEventAfterStep(printevent.printwrapper)
print "quenched e = ", ret.energy, "funcalls", ret.nfev print ret.coords m = getm(ret[0]) print "magnetization after quench", m #do basin hopping from pygmin.basinhopping import BasinHopping from pygmin.takestep.displace import RandomDisplacement from pygmin.takestep.adaptive import AdaptiveStepsize from pygmin.storage import savenlowest takestep = RandomDisplacement(stepsize=np.pi / 4) takestepa = AdaptiveStepsize(takestep, frequency=10) storage = savenlowest.SaveN(20) bh = BasinHopping(coords, pot, takestepa, temperature=1.01, storage=storage) bh.run(200) print "lowest structures fount:" with open("out.spins", "w") as fout: for min in storage.data: m = getm(min.coords) print "energy", min.energy, "magnetization", m fout.write("energy %g magnetization %g\n" % (min.energy, m)) printspins(fout, pot, min.coords) fout.write("\n\n") """ view the spins with gnuplot using the command