コード例 #1
0
    def minimize(self):
        #shape(visits2d) is now (nqbins, nebins, nreps)
        #we need it to be (nreps, nqbins*nebins)
        #first reorder indices
        nreps = self.nrep
        nebins = self.nebins
        nqbins = self.nqbins
        nbins = self.nebins * self.nqbins
        #visits = np.zeros([nreps, nebins, nqbins], np.integer)
        reduced_energy = np.zeros([nreps, nebins, nqbins])
#        for k in range(self.nrep):
#            for j in range(self.nqbins):
#                for i in range(self.nebins):
#                    #visits[k,i,j] = self.visits2d[i,j,k]
#                    reduced_energy[k,i,j] = self.binenergy[i] / (self.Tlist[k]*self.k_B)
        for j in range(self.nqbins):
            reduced_energy[:,:,j] = self.binenergy[np.newaxis,:] / (self.Tlist[:,np.newaxis]*self.k_B)
                    
        visits = self.visits2d
        visits = np.reshape( visits, [nreps, nbins ]) 
        reduced_energy = np.reshape( reduced_energy, [nreps, nbins])           
        self.logP = np.where( visits != 0, np.log( visits.astype(float) ), 0 )

        
        from wham_potential import WhamPotential
        whampot = WhamPotential( self.logP, reduced_energy )
        
        nvar = nbins + nreps
        X = np.random.rand(nvar)
        print "initial energy", whampot.getEnergy(X)
        try: 
            from pygmin.optimize import mylbfgs as quench
            ret = quench(X, whampot, iprint=10, maxstep = 1e4)
        except ImportError:
            from pygmin.optimize import lbfgs_scipy as quench
            ret = quench(X, whampot)            

        print "quenched energy", ret.energy
        
        global_min = False
        if global_min:
            from pygmin.basinhopping import BasinHopping
            from pygmin.takestep.displace import RandomDisplacement
            takestep = RandomDisplacement(stepsize=10.)
            takestep.useAdaptiveStep()
            takestep.adaptive_class.f = 2.
            bh = BasinHopping(X, whampot, takestep)
            bh.run(1000)
        
        
        #self.logn_Eq = zeros([nebins,nqbins], float64)
        X = ret.coords
        self.logn_Eq = X[nreps:]
        self.w_i_final = X[:nreps]
        
        self.logn_Eq = np.reshape(self.logn_Eq, [nebins, nqbins])
        self.logn_Eq = np.where( self.visits2d.sum(0) == 0, self.LOGMIN, self.logn_Eq )
コード例 #2
0
ファイル: xyspin1d.py プロジェクト: js850/PyGMIN
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(400)
コード例 #3
0
ファイル: _bfgs.py プロジェクト: js850/PyGMIN
def getInitialCoords(natoms, pot):
    from pygmin.basinhopping import BasinHopping
    from pygmin.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
コード例 #4
0
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)
コード例 #5
0
def getInitialCoords(natoms, pot):
    from pygmin.basinhopping import BasinHopping
    from pygmin.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
コード例 #6
0
ファイル: min_ts_graph.py プロジェクト: yfyh2013/PyGMIN
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
コード例 #7
0
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)
コード例 #8
0
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)
コード例 #9
0
ファイル: connect_min.py プロジェクト: wwwtyro/PyGMIN
def getSetOfMinLJ(natoms = 32): #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.database import Database
    import os
    #dbfile = "test.db"
    #os.remove(dbfile)
    #saveit = Database(db=dbfile)
    saveit = Database()
    takestep1 = RandomDisplacement()
    takestep = AdaptiveStepsize(takestep1, frequency=15)
    bh = BasinHopping(coords, pot, takestep, storage=saveit.minimum_adder(), outstream=None)
    bh.run(100)
    return pot, saveit
コード例 #10
0
 def globalMinimization(self):
     """
     in experimentation i've never been able to find more than
     one minimum
     """
     nreps = self.nrep
     nbins = self.nebins
     visitsT = (self.visits1d)
     #print "min vis", np.min(visitsT)
     self.logP = np.where( visitsT != 0, np.log( visitsT ), 0 )
     #print "minlogp", np.min(self.logP)
     self.reduced_energy = self.binenergy[np.newaxis,:] / (self.Tlist[:,np.newaxis] * self.k_B)
     
     self.whampot = WhamPotential(self.logP, self.reduced_energy)
     
     X = np.random.rand( nreps + nbins )
     E = self.whampot.getEnergy(X)
     print "energy", E 
     
     print "quenching"
     from pygmin.optimize import lbfgs_scipy as quench
     ret = quench(X, self.whampot)
     print "quench energy", ret.energy
     
     from pygmin.basinhopping import BasinHopping
     from pygmin.takestep.displace import RandomDisplacement
     takestep = RandomDisplacement(stepsize=10)
     takestep.useAdaptiveStep()
     takestep.adaptive_class.f = 1.5 #i have no idea what a good stepsize should be
     bh = BasinHopping(X, self.whampot, takestep )
     
     import matplotlib.pyplot as plt
     for i in range(10):
         bh.run(2000)
         self.logn_E = bh.coords[nreps:]
         cvdata = self.calc_Cv(400)
         plt.plot(cvdata[:,0], cvdata[:,5], '-')
     plt.show()
         
         
     
     X = bh.coords
     self.logn_E = X[nreps:]
     self.w_i_final = X[:nreps]
コード例 #11
0
    def globalMinimization(self):
        """
        in experimentation i've never been able to find more than
        one minimum
        """
        nreps = self.nrep
        nbins = self.nebins
        visitsT = (self.visits1d)
        #print "min vis", np.min(visitsT)
        self.logP = np.where(visitsT != 0, np.log(visitsT), 0)
        #print "minlogp", np.min(self.logP)
        self.reduced_energy = self.binenergy[np.newaxis, :] / (
            self.Tlist[:, np.newaxis] * self.k_B)

        self.whampot = WhamPotential(self.logP, self.reduced_energy)

        X = np.random.rand(nreps + nbins)
        E = self.whampot.getEnergy(X)
        print "energy", E

        print "quenching"
        from pygmin.optimize import lbfgs_scipy as quench
        ret = quench(X, self.whampot)
        print "quench energy", ret.energy

        from pygmin.basinhopping import BasinHopping
        from pygmin.takestep.displace import RandomDisplacement
        takestep = RandomDisplacement(stepsize=10)
        takestep.useAdaptiveStep()
        takestep.adaptive_class.f = 1.5  #i have no idea what a good stepsize should be
        bh = BasinHopping(X, self.whampot, takestep)

        import matplotlib.pyplot as plt
        for i in range(10):
            bh.run(2000)
            self.logn_E = bh.coords[nreps:]
            cvdata = self.calc_Cv(400)
            plt.plot(cvdata[:, 0], cvdata[:, 5], '-')
        plt.show()

        X = bh.coords
        self.logn_E = X[nreps:]
        self.w_i_final = X[:nreps]
コード例 #12
0
ファイル: 2dRAHM.py プロジェクト: js850/PyGMIN
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
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"
コード例 #13
0
ファイル: OTPrun.py プロジェクト: yfyh2013/PyGMIN
coords = np.zeros(2 * 3 * nmol, np.float64)
coords[0:nmol *
       3] = np.random.uniform(-1, 1, [nmol * 3]) * 1.3 * (nsites)**(1. / 3)
for i in range(nmol):
    k = nmol * 3 + 3 * i
    coords[k:k + 3] = rot.random_aa()

#set up the takestep routine
from pygmin.potentials.rigid_bodies.take_step import RBTakeStep
takestep = RBTakeStep()

#set up the class to save lowest energy structures
from pygmin.storage.savenlowest import SaveN
saveit = SaveN(100)

#set up basinhopping
from pygmin.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 pygmin.printing.print_atoms_xyz import printAtomsXYZ as printxyz
with open(fname, "w") as fout:
    for minimum in saveit.data:
        xyz = mysys.getxyz(minimum.coords)
        printxyz(fout, xyz, atom_type=["N", "O", "O"])
コード例 #14
0
ファイル: OTPrun.py プロジェクト: js850/PyGMIN
    coords[k : k + 3] = rot.random_aa()


#set up the takestep routine
from  pygmin.potentials.rigid_bodies.take_step import RBTakeStep
takestep = RBTakeStep()

#set up the class to save lowest energy structures
from pygmin.storage.savenlowest import SaveN
saveit = SaveN(100)

#set up basinhopping
from  pygmin.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 pygmin.printing.print_atoms_xyz import printAtomsXYZ as printxyz
with open(fname, "w") as fout:
    for minimum in saveit.data:
        xyz = mysys.getxyz(minimum.coords)
        printxyz( fout, xyz, atom_type=["N", "O", "O"])


コード例 #15
0
ファイル: oxdna_param.py プロジェクト: yfyh2013/PyGMIN
                                                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)
コード例 #16
0
ファイル: runxymodel.py プロジェクト: js850/PyGMIN
#set up and run basin hopping

from pygmin.basinhopping import BasinHopping
from pygmin.takestep.displace import RandomDisplacement
from pygmin.takestep.adaptive import AdaptiveStepsize
from pygmin.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:
コード例 #17
0
#set up and run basin hopping

from pygmin.basinhopping import BasinHopping
from pygmin.takestep.displace import RandomDisplacement
from pygmin.takestep.adaptive import AdaptiveStepsize
from pygmin.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:
コード例 #18
0
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
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"
"""
コード例 #19
0
ファイル: oxdna_param.py プロジェクト: js850/PyGMIN
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)