コード例 #1
0
 def get_basinhopping(self,
                      database=None,
                      takestep=None,
                      coords=None,
                      add_minimum=None,
                      **kwargs):
     """return the basinhopping object with takestep
     and accept step already implemented
     
     See Also
     --------
     pygmin.basinhopping
     """
     kwargs = dict_copy_update(self.params["basinhopping"], kwargs)
     pot = self.get_potential()
     if coords is None:
         coords = self.get_random_configuration()
     if takestep is None:
         takestep = self.get_takestep()
     if add_minimum is None:
         if database is None:
             database = self.create_database()
         add_minimum = database.minimum_adder()
     bh = basinhopping.BasinHopping(coords,
                                    pot,
                                    takestep,
                                    quench=self.get_minimizer(),
                                    storage=add_minimum,
                                    **kwargs)
     return bh
コード例 #2
0
ファイル: run_gui.py プロジェクト: yfyh2013/PyGMIN
    def createBasinHopping(self):
        GMIN.initialize()
        pot = gminpot.GMINPotental(GMIN)
        coords = pot.getCoords()

        step = displace.RandomDisplacement()
        opt = bh.BasinHopping(coords,
                              pot,
                              takeStep=step,
                              temperature=0.4,
                              storage=self.storage)
        return opt
コード例 #3
0
ファイル: oxdna.py プロジェクト: yfyh2013/PyGMIN
import numpy as np
import oxdnagmin_ as GMIN
from pygmin.potentials.gminpotential import GMINPotential
import pygmin.basinhopping as bh
from pygmin.takestep import displace
from pygmin.storage.database import Database

# initialize GMIN
GMIN.initialize()
# create a potential which calls GMIN
potential = GMINPotential(GMIN)
# get the initial coorinates
coords = potential.getCoords()
coords = np.random.random(coords.shape)
# create takestep routine
step = displace.RandomDisplacement(stepsize=1.)

# store all minima in a database
db = Database(db="storage.sqlite", accuracy=1e-2)

# create Basinhopping object
opt = bh.BasinHopping(coords, potential, step, db.minimum_adder())

# run for 100 steps
opt.run(1000)

# now dump all the minima
i = 0
for m in db.minima():
    i += 1
    GMIN.userpot_dump("lowest_%03d.dat" % (i), m.coords)
コード例 #4
0
                        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:
    print "Could not draw using pymol, skipping this step"
コード例 #5
0
ファイル: amber.py プロジェクト: yfyh2013/PyGMIN
import numpy as np
import pygmin.basinhopping as bh
from pygmin.optimize import _quench as quench
from pygmin.takestep import displace

# export PYTHONPATH=/home/ss2029/svn/GMIN/bin:$PWD/../..

GMIN.initialize()
pot = gminpot.GMINPotental(GMIN)

coords = pot.getCoords()

step = displace.RandomDisplacement(stepsize=0.7)

opt = bh.BasinHopping(coords,
                      pot,
                      takeStep=step,
                      quenchRoutine=quench.lbfgs_py)
opt.quenchParameters['tol'] = 1e-4
opt.run(3)

# some visualization
try:
    import pygmin.utils.pymolwrapper as pym
    pym.start()
    pym.draw_spheres(opt.coords, "A", 1)
except:
    print "Could not draw using pymol, skipping this step"
import pygmin.printing.print_atoms_xyz as pr
pr.printAtomsXYZ(open("final.xyz", "w"), opt.coords)
コード例 #6
0
ファイル: 4_adaptivestep.py プロジェクト: yfyh2013/PyGMIN
# -*- coding: iso-8859-1 -*-
############################################################
#Example 4: adaptive step size
############################################################
import numpy as np
import pygmin.potentials.lj as lj
import pygmin.basinhopping as bh
from pygmin.takestep import displace
from pygmin.takestep import adaptive

natoms = 12

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

takeStep = displace.RandomDisplacement(stepsize=0.3)
tsAdaptive = adaptive.AdaptiveStepsize(takeStep, acc_ratio=0.5, frequency=100)
opt = bh.BasinHopping(coords, potential, takeStep=tsAdaptive)
opt.run(1000)
コード例 #7
0
#Example 3: Saving the coordinates as an xyz file
############################################################
import numpy as np
import pygmin.potentials.lj as lj
import pygmin.basinhopping as bh
from pygmin.takestep import displace
from pygmin.storage.savenlowest import SaveN as saveit

natoms = 12
coords = np.random.random(3 * natoms)

potential = lj.LJ()
step = displace.RandomDisplacement(stepsize=0.5)

storage = saveit(nsave=10)
opt = bh.BasinHopping(coords, potential, step, storage=storage.insert)
opt.run(100)

with open("lowest", "w") as fout:
    fout.write(str(natoms) + "\n")
    fout.write(str(storage.data[0].energy) + "\n")
    atoms = storage.data[0].coords.reshape(natoms, 3)
    for a in atoms:
        fout.write("LA " + str(a[0]) + " " + str(a[1]) + " " + str(a[2]) +
                   "\n")

############################################################
# some visualization
############################################################
try:
    import pygmin.utils.pymolwrapper as pym
コード例 #8
0
def minPermDistRBMol(coords1,
                     coords2,
                     mysys,
                     niter=100,
                     permlist=None,
                     verbose=False):
    """
    Minimize the distance between two clusters.  The following symmetries will be accounted for
    
    Translational symmetry

    Global rotational symmetry

    Permutational symmetry
    
    This method uses basin hopping to find the rotation of X2 which best
    optimizes the overlap (an effective energy) between X1 and X2.  The overlap
    is chosen to be permutation independent.

    Once the rotation is optimized, the correct permutation of rigid bodies can be determined
    deterministically using the Hungarian algorithm.
    
    Finally 
    
    input:
    
    coords1, coords2: the structures for which to minimize the distance in com + angle-axis format
    
    permlist  ([range(natoms)]) 
        A list of lists of atoms which are interchangable.
        e.g. for a 50/50 binary mixture, permlist = [ range(1,natoms/2), range(natoms/2,natoms) ]
    """
    nmol = mysys.nmol

    if permlist == None:
        permlist = [range(nmol)]

    ###############################################
    # move the centers of mass to the origin
    ###############################################
    #warning: this assumes all molecules have the same mass
    coords1[0:3 * nmol] = CoMToOrigin(coords1[0:3 * nmol])
    coords2[0:3 * nmol] = CoMToOrigin(coords2[0:3 * nmol])

    coords1in = coords1.copy()
    coords2in = coords2.copy()

    comcoords1 = copy.copy(coords1[0:3 * nmol])
    comcoords2 = copy.copy(coords2[0:3 * nmol])

    ###############################################
    # set initial conditions
    ###############################################
    aamin = np.array([0., 0., 0.])

    ######################################
    # set up potential, dependent only on the center of mass coords
    ######################################
    pot = distpot.MinPermDistPotential(comcoords1, comcoords2, 0.4, permlist)
    #if False:
    #print some stuff. not necessary
    #Emin = pot.getEnergy(aamin)
    #dist, X11, X22 = findBestPermutationRBMol(coords1, aa2xyz(X2in, aamin), permlist )
    #print "initial energy", Emin, "dist", dist
    saveit = storage.SaveN(20)
    takestep = distpot.RandomRotationTakeStep()
    bh = basinhopping.BasinHopping(aamin,
                                   pot,
                                   takestep,
                                   storage=saveit.insert,
                                   outstream=None)

    Eminglobal = pot.globalEnergyMin()  #condition for determining isomer
    if verbose: print "global Emin", Eminglobal

    ##########################################################################
    # run basin hopping for ninter steps or until the global minimum is found
    # (i.e. determine they are isomers)
    ##########################################################################
    if verbose:
        print "using basin hopping to optimize rotations + permutations"
    for i in range(niter):
        bh.run(1)
        Emin = saveit.data[0].energy
        if abs(Emin - Eminglobal) < 1e-6:
            print "isomer found"
            break
    """
    Lower energies generally mean smaller distances, but it's not guaranteed.
    Check a number of the lowest energy structures. To ensure get the correct
    minimum distance structure.
    """
    if verbose: print "lowest structures found"
    aamin = saveit.data[0].coords
    dmin = 1000.
    for min in saveit.data:
        aa = min.coords
        coords2 = coordsApplyRotation(coords2in, aa)
        dist, X11, X22 = findBestPermutationRBMol(coords1, coords2, mysys,
                                                  permlist)
        if verbose: print "E %11.5g dist %11.5g" % (min.energy, dist)
        if dist < dmin:
            dmin = dist
            aamin = aa.copy()

    ###################################################################
    #we've optimized the rotation in a permutation independent manner
    #now optimize the permutation
    ###################################################################
    dbefore = getDistaa(coords1, coords2in, mysys)
    coords2 = coordsApplyRotation(coords2in, aamin)
    dafter = getDistaa(coords1, coords2, mysys)
    if verbose:
        print "dist before, after applying rotation from basin hopping", dbefore, dafter, mysys.getEnergy(
            coords2in), mysys.getEnergy(coords2)
    dmin, coords1, coords2min = findBestPermutationRBMol(
        coords1, coords2, mysys, permlist)
    #dafter = getDistaa(coords1, coords2min, mysys)
    if verbose: print "dist findBestPerm", dmin, mysys.getEnergy(coords2min)

    ###################################################################
    # permutations are set, do one final mindist improve accuracy
    #of rotation optimization
    ###################################################################
    #dmin, X2min = alignRotation( X1, X2min )

    ###################################################################
    #minimize the cartesian distance between the angle axis coords
    #by applying symmetry operations.
    ###################################################################
    for i in range(3 * nmol, 2 * 3 * nmol, 3):
        aadistance(coords1[i:i + 3], coords2min[i:i + 3])

    return dmin, coords1, coords2min