Example #1
0
class ClusterTest(unittest.TestCase):
    def setUp(self):
        natoms = 3
        self.minimiser = PeleMinimiser(lj.LJ())
        coords = np.array(((0., 0., 0.1), (1., 1., 0.3), (0., 2., 0.2)))
        self.cluster = Cluster(natoms, coords, self.minimiser)

    def test_get_energy(self):
        self.minimiser.minimise(self.cluster)
        self.assertAlmostEquals(self.cluster.energy, -3.)
Example #2
0
class ClusterTest(unittest.TestCase):
    def setUp(self):
        natoms=3
        self.minimiser=PeleMinimiser(lj.LJ())
        coords=np.array(((0.,0.,0.1),
                         (1.,1.,0.3),
                         (0.,2.,0.2)))
        self.cluster = Cluster(natoms,coords,self.minimiser)
   
    def test_get_energy(self):
        self.minimiser.minimise(self.cluster)
        self.assertAlmostEquals(self.cluster.energy,-3.)
Example #3
0
 def setUp(self):
     natoms=3
     self.minimiser=PeleMinimiser(lj.LJ())
     coords=np.array(((0.,0.,0.1),
                      (1.,1.,0.3),
                      (0.,2.,0.2)))
     self.cluster = Cluster(natoms,coords,self.minimiser)
 def setUp(self):
     natoms = 10
     minimiser = PeleMinimiser(BLJCluster(natoms, 5))
     self.factory = ClusterFactory(natoms,
                                   minimiser,
                                   composition=[5, 5],
                                   labels=["A", "B"])
 def test_cluster(self):
     natoms=3
     minimiser=PeleMinimiser(LJCluster(natoms))
     factory=ClusterFactory(natoms,minimiser)
     with open("restart.xyz",'r') as xyz_file:
         cluster=factory.read_xyz(xyz_file)
     self.assertEquals(-5.,cluster.get_energy())
 def setUp(self):
     natoms = 10
     minimiser = PeleMinimiser(lj.LJ())
     factory = ClusterFactory(natoms, minimiser)
     self.population = PopulationList(natoms, factory, max_size=5)
     while len(self.population) < self.population.max_size:
         self.population.append(factory.get_random_cluster())
 def test_replace(self):
     natoms=10
     minimiser=PeleMinimiser(lj.LJ())
     factory=ClusterFactory(natoms,minimiser)
     parent = factory.get_random_cluster()   
     mutator = MutateReplace()
     mutant = mutator.get_mutant(parent)
     self.assertLess(mutant.get_energy(), 0)
Example #8
0
 def test_mutant(self):
     natoms = 10
     minimiser = PeleMinimiser(lj.LJ())
     factory = ClusterFactory(natoms, minimiser)
     parent_a = factory.get_random_cluster()
     parent_b = factory.get_random_cluster()
     crossover = DeavenHo()
     offspring = crossover.get_offspring(parent_a, parent_b)
     self.assertLess(offspring.get_energy(), 0)
 def test_population(self):
     natoms=3
     minimiser=PeleMinimiser(LJCluster(natoms))
     factory=ClusterFactory(natoms,minimiser)
     with open("restart.xyz",'r') as xyz_file:
         population=PopulationList(natoms,factory)
         population.read_xyz(xyz_file)
     self.assertEquals(-5.,population[0].get_energy())
     self.assertEquals(-4.,population[1].get_energy())
 def setUp(self):
     self.natoms = 3
     minimiser = PeleMinimiser(BLJCut(3, 1))
     coords = np.array(((0., 0., 0.1), (1., 1., 0.3), (0., 2., 0.2)))
     types = [0, 1, 0]
     labels = ["X", "Y"]
     self.cluster = Cluster(self.natoms,
                            coords,
                            minimiser,
                            atom_types=types,
                            labels=labels)
 def test_exchange(self):
     natoms=20
     minimiser=PeleMinimiser(BLJCluster(natoms,10))
     factory=ClusterFactory(natoms,minimiser,
                                 composition=[10,10],
                                 labels=["A","B"])
     cluster = factory.get_random_cluster()
     mutator = MutateExchange()
     for i in range(0,50):
         mutant=mutator.get_mutant(cluster)
         self.assertEquals(mutant.atom_types[9],0)
         self.assertEquals(mutant.atom_types[10],1)
'''
A simple GA run. We use a 38 atom Lennard-Jones in this example.

The natoms argument defines the number of atoms in the cluster and is required for all GA searchs.
The minimiser object is also needed to perform the energy evaluations. This example uses a simple
Lennard-Jones minimiser. Other examples show how to set up minimisers for more complicated potentials.

@author: Mark Oakley
'''

from bcga.genetic_algorithm import GeneticAlgorithm
import pele.potentials.lj as lj
from bcga.pele_interface import PeleMinimiser

myga = GeneticAlgorithm(
    natoms=38,  # Number of atoms
    minimiser=PeleMinimiser(lj.LJ()))  #Energy minimisation method
myga.run()
Example #13
0
'''
Example PyBCGA input for a binary Lennard-Jones cluster.

@author: Mark Oakley
'''

from bcga.genetic_algorithm import GeneticAlgorithm
from pele.potentials import BLJCut
from bcga.pele_interface import PeleMinimiser

natoms = 13
ntypea = 5
ntypeb = 8
myga = GeneticAlgorithm(natoms=natoms,
                        minimiser=PeleMinimiser(BLJCut(natoms, ntypea)),
                        composition=[ntypea, ntypeb],
                        labels=["A", "B"],
                        remove_duplicates=True,
                        max_generation=50)
myga.run()
 def setUp(self):
     self.natoms = 3
     minimiser = PeleMinimiser(lj.LJ())
     coords = np.array(((0., 0., 0.1), (0.1, 0.1, 0.1), (0., 0.2, 0.2)))
     self.cluster = Cluster(self.natoms, coords, minimiser)
Example #15
0
'''
The batch GA is designed to be used in conjunction with a task arrays on a
scheduling system. The population of structures is stored in an SQL database
that can be accessed by several instances of the GA at the same time.

For this example, we use a simple Lennard-Jones potential. However, the batch
GA is designed to be most useful for very expensive energy calculations (e.g.
DFT).

Use the read_database script to view the database in a human-readable format.

@author: Mark Oakley
'''

from bcga.batch_genetic_algorithm import BatchGeneticAlgorithm
from bcga.pele_interface import PeleMinimiser
import pele.potentials.lj as lj

natoms = 38
minimiser=PeleMinimiser(lj.LJ())

myga = BatchGeneticAlgorithm(natoms,
                        minimiser,
                        remove_duplicates=True,
                        max_generation=20)

myga.run()
Example #16
0
 def setUp(self):
     natoms = 3
     self.minimiser = PeleMinimiser(lj.LJ())
     coords = np.array(((0., 0., 0.1), (1., 1., 0.3), (0., 2., 0.2)))
     self.cluster = Cluster(natoms, coords, self.minimiser)
 def setUp(self):
     natoms = 10
     minimiser = PeleMinimiser(lj.LJ())
     self.factory = ClusterFactory(natoms, minimiser)
Example #18
0
 def setUp(self):
     natoms = 10
     minimiser = PeleMinimiser(lj.LJ())
     self.ga = GeneticAlgorithm(natoms, minimiser, max_generation=2)