Example #1
0
    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
Example #2
0
 def get_basinhopping(self,
                      database=None,
                      takestep=None,
                      coords=None,
                      add_minimum=None,
                      max_n_minima=None,
                      **kwargs):
     """construct a basinhopping object with takestep and accept step already implemented
     
     Parameters
     ----------
     database : object
         Use this object to store the minima.  If None, use self.create_database()
     takestep : object
         Use this takestep routine.  If None, use self.get_takestep()
     coords : 1-d numpy array
         The starting point for the basinhopping run.  If None, use self.get_random_configuration()
     add_minimium : callable
         Call this function each time a minimum is found.  This is used instead of the database.
     max_n_minima : int
         Only keep this number of minima in the database.  The minima with the lowest energy are kept.
         This is ignored if add_minimum is passed
     kwargs : key word arguments
         Extra key word arguments are passed to BasinHopping.
     
     See Also
     --------
     pele.basinhopping
     """
     kwargs = dict_copy_update(self.params["basinhopping"], kwargs)
     # extract max_n_minima from kwargs
     try:
         val = kwargs.pop("max_n_minima")
         if max_n_minima is None:
             max_n_minima = val
     except KeyError:
         pass
     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(max_n_minima=max_n_minima)
     bh = basinhopping.BasinHopping(coords,
                                    pot,
                                    takestep,
                                    quench=self.get_minimizer(),
                                    storage=add_minimum,
                                    **kwargs)
     return bh
Example #3
0
    def takeStep(self, coords, **kwargs):
        # make a new monte carlo class
        mc = MonteCarlo(coords, 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()

step = TakeStepMonteCarlo(potential)

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

# some visualization
try:
    import pele.utils.pymolwrapper as pym

    pym.start()
    pym.draw_spheres(opt.coords, "A", 1)
except:
    print("Could not draw using pymol, skipping this step")
Example #4
0
import numpy as np
import oxdnagmin_ as GMIN
from pele.potentials.gminpotential import GMINPotential
import pele.basinhopping as bh
from pele.takestep import displace
from pele.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)
Example #5
0
# Example 3: Saving the coordinates as an xyz file
# ###########################################################
import numpy as np
import pele.potentials.lj as lj
import pele.basinhopping as bh
from pele.takestep import displace
from pele.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 pele.utils.pymolwrapper as pym
Example #6
0
import ambgmin_ as GMIN
import pele.potentials.gminpotential as gminpot
import numpy as np
import pele.basinhopping as bh
from pele.optimize import _quench as quench
from pele.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, quench=quench.lbfgs_py)
opt.quenchParameters['tol'] = 1e-4
opt.run(3)

# some visualization
try: 
    import pele.utils.pymolwrapper as pym
    pym.start()
    pym.draw_spheres(opt.coords, "A", 1)
except:
    print "Could not draw using pymol, skipping this step"
from pele.utils.xyz import write_xyz
write_xyz(open("final.xyz", "w"), opt.coords)