def getInitialCoords(natoms, pot): from pele.basinhopping import BasinHopping from pele.takestep.displace import RandomDisplacement takestep = RandomDisplacement(0.3) X = np.random.uniform(-1,1,natoms*3)*(1.*natoms)**(1./3)*.1 bh = BasinHopping(X, pot, takestep) bh.run(30) X = bh.coords return X
def test_basin_hopping(pot, angles): from pele.basinhopping import BasinHopping from pele.takestep.displace import RandomDisplacement from pele.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(400)
def test_basin_hopping(pot, angles): # pragma: no cover from pele.basinhopping import BasinHopping from pele.takestep.displace import RandomDisplacement from pele.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 pele.potentials.lj import LJ pot = LJ() coords = np.random.uniform(-1,1,natoms*3) from pele.basinhopping import BasinHopping from pele.takestep.displace import RandomDisplacement from pele.takestep.adaptive import AdaptiveStepsize from pele.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 pele.potentials.lj import LJ pot = LJ() natoms = 9 coords = np.random.uniform(-1,1,natoms*3) from pele.basinhopping import BasinHopping from pele.takestep.displace import RandomDisplacement from pele.takestep.adaptive import AdaptiveStepsize from pele.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 bh_no_system_class(): import numpy as np from pele.potentials import LJ natoms = 17 potential = LJ() x0 = np.random.uniform(-1, 1, 3*natoms) from pele.takestep import RandomDisplacement, AdaptiveStepsizeTemperature displace = RandomDisplacement() adaptive_displacement = AdaptiveStepsizeTemperature(displace) from pele.storage import Database database = Database("lj17.sqlite") from pele.basinhopping import BasinHopping bh = BasinHopping(x0, potential, adaptive_displacement, storage=database.minimum_adder) bh.run(10) for m in database.minima(): print m.energy
m = getm(ret[0]) print "magnetization after quench", m # do basin hopping from pele.basinhopping import BasinHopping from pele.takestep.displace import RandomDisplacement from pele.takestep.adaptive import AdaptiveStepsize from pele.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 h = 2. s = 0.7 splot 'out.spins' u 1:2:(0) w p pt 5, '' index 1 u 1:2:(0):($6/h):($7/h):($8/h) w vectors t "fields", '' index 1 u 1:2:(0):($3*s):($4*s):($5*s) w vectors t "spins"
rotate=0.), frequency=50) step2 = takestep.AdaptiveStepsize(OXDNATakestep(displace=0., rotate=parameters.rotate), frequency=50) group.addBlock(100, step1) group.addBlock(100, step2) # with a generate random configuration genrandom = OXDNAReseed() # in a reseeding takestep procedure reseed = takestep.Reseeding(group, genrandom, maxnoimprove=parameters.reseed) # store all minima in a database db = Database(db="storage.sqlite", accuracy=1e-2) # create Basinhopping object opt = BasinHopping(coords, potential, reseed, db.minimum_adder(), temperature=parameters.temperature) # run for 100 steps opt.run(parameters.nsteps) # now dump all the minima i = 0 for m in db.minima(): i += 1 GMIN.userpot_dump("lowest_%03d.dat" % (i), m.coords)
# set up and run basin hopping from pele.basinhopping import BasinHopping from pele.takestep.displace import RandomDisplacement from pele.takestep.adaptive import AdaptiveStepsize from pele.storage import savenlowest # should probably use a different take step routine which takes into account # the cyclical periodicity of angles takestep = RandomDisplacement(stepsize = np.pi/4) takestepa = AdaptiveStepsize(takestep, frequency = 20) storage = savenlowest.SaveN(500) bh = BasinHopping( angles, pot, takestepa, temperature = 1.01, storage = storage) bh.run(400) print "minima found" with open("out.spin", "w") as fout: for min in storage.data: print "energy", min.energy fout.write("# %g\n" % (min.energy)) printspins(fout, pot, min.coords) fout.write('\n\n') """ view this in gnuplot with the command set size ratio -1 plot 'out.spin' index 0 u 1:2 w p pt 5, '' index 0 u 1:2:($3*0.5):($4*0.5) w vectors """ with open("out.energies", "w") as fout:
# set up and run basin hopping from pele.basinhopping import BasinHopping from pele.takestep.displace import RandomDisplacement from pele.takestep.adaptive import AdaptiveStepsize from pele.storage import savenlowest # should probably use a different take step routine which takes into account # the cyclical periodicity of angles takestep = RandomDisplacement(stepsize=old_div(np.pi, 4)) takestepa = AdaptiveStepsize(takestep, frequency=20) storage = savenlowest.SaveN(500) bh = BasinHopping(angles, pot, takestepa, temperature=1.01, storage=storage) bh.run(400) print("minima found") with open("out.spin", "w") as fout: for min in storage.data: print("energy", min.energy) fout.write("# %g\n" % (min.energy)) printspins(fout, pot, min.coords) fout.write('\n\n') """ view this in gnuplot with the command set size ratio -1 plot 'out.spin' index 0 u 1:2 w p pt 5, '' index 0 u 1:2:($3*0.5):($4*0.5) w vectors """ with open("out.energies", "w") as fout:
m = getm(ret[0]) print "magnetization after quench", m # do basin hopping from pele.basinhopping import BasinHopping from pele.takestep.displace import RandomDisplacement from pele.takestep.adaptive import AdaptiveStepsize from pele.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 h = 2. s = 0.7 splot 'out.spins' u 1:2:(0) w p pt 5, '' index 1 u 1:2:(0):($6/h):($7/h):($8/h) w vectors t "fields", '' index 1 u 1:2:(0):($3*s):($4*s):($5*s) w vectors t "spins" """
coords=potential.getCoords() coords=np.random.random(coords.shape) # create takestep routine # we combine a normal step taking group = takestep.BlockMoves() step1 = takestep.AdaptiveStepsize(OXDNATakestep(displace=parameters.displace, rotate=0.), frequency=50) step2 = takestep.AdaptiveStepsize(OXDNATakestep(displace=0., rotate=parameters.rotate), frequency=50) group.addBlock(100, step1) group.addBlock(100, step2) # with a generate random configuration genrandom = OXDNAReseed() # in a reseeding takestep procedure reseed = takestep.Reseeding(group, genrandom, maxnoimprove=parameters.reseed) # store all minima in a database db = Database(db="storage.sqlite", accuracy=1e-2) # create Basinhopping object opt = BasinHopping(coords, potential, reseed, db.minimum_adder(), temperature=parameters.temperature) # run for 100 steps opt.run(parameters.nsteps) # now dump all the minima i=0 for m in db.minima(): i+=1 GMIN.userpot_dump("lowest_%03d.dat"%(i), m.coords)
coords[k : k + 3] = rot.random_aa() #set up the takestep routine from pele.potentials.rigid_bodies.take_step import RBTakeStep takestep = RBTakeStep() #set up the class to save lowest energy structures from pele.storage.savenlowest import SaveN saveit = SaveN(100) #set up basinhopping from pele.basinhopping import BasinHopping bh = BasinHopping(coords, mysys, takestep, storage=saveit.insert ) #run basin hopping bh.run(40) #print the saved coords fname = "otp.xyz" print "saving xyz coords to", fname from pele.utils.xyz import write_xyz with open(fname, "w") as fout: for minimum in saveit.data: xyz = mysys.getxyz(minimum.coords) write_xyz( fout, xyz, atomtypes=["N", "O", "O"])