Exemplo n.º 1
0
 def get_offspring(self, cluster_a, cluster_b):
     '''Generate an offspring structure from two parent structures.'''
     #Prepare clusters
     for cluster in [cluster_a, cluster_b]:
         cluster.centre()
         cluster.rotate_random()
         cluster.sort_z()
     #Choose cutting plane
     cut = np.random.randint(1, cluster_a.natoms)
     #Make new cluster
     coords = np.empty(shape=(cluster_a.natoms, 3))
     atom_types = []
     for i in range(0, cut):
         coords[i] = cluster_a.get_coords(i)
         atom_types.append(cluster_a.atom_types[i])
     for i in range(cut, cluster_a.natoms):
         coords[i] = cluster_b.get_coords(i)
         atom_types.append(cluster_b.atom_types[i])
         composition = get_composition(cluster_a.atom_types)
     atom_types = fix_composition(composition, atom_types)
     offspring = Cluster(cluster_a.natoms,
                         coords,
                         cluster_a.minimiser,
                         atom_types=atom_types,
                         labels=cluster_a.labels)
     offspring.quenched = False
     offspring.sort_type()
     cluster_a.sort_type()
     cluster_b.sort_type()
     return offspring
Exemplo n.º 2
0
 def get_offspring(self,cluster_a,cluster_b):
     '''Generate an offspring structure from two parent structures.'''
     #Prepare clusters
     for cluster in [cluster_a,cluster_b]:
         cluster.centre()
         cluster.rotate_random()
         cluster.sort_z()
     #Choose cutting plane
     cut=np.random.randint(1,cluster_a.natoms)
     #Make new cluster
     coords=np.empty(shape=(cluster_a.natoms,3))
     atom_types=[]
     for i in range(0,cut):
         coords[i]=cluster_a.get_coords(i)
         atom_types.append(cluster_a.atom_types[i])
     for i in range(cut,cluster_a.natoms):
         coords[i]=cluster_b.get_coords(i)
         atom_types.append(cluster_b.atom_types[i])
         composition = get_composition(cluster_a.atom_types)
     atom_types=fix_composition(composition,atom_types)
     offspring=Cluster(cluster_a.natoms,
                       coords,
                       cluster_a.minimiser,
                       atom_types=atom_types,
                       labels=cluster_a.labels)
     offspring.quenched=False
     offspring.sort_type()
     cluster_a.sort_type()
     cluster_b.sort_type()
     return offspring
Exemplo n.º 3
0
 def read_db(self,minimum):
     '''Read structure from Pele minimum'''
     cluster=Cluster(self.natoms,
                     np.reshape(minimum.coords,(-1,3)),
                     self.minimiser,
                     atom_types=get_atom_types(self.composition),
                     labels=self.labels)
     cluster.energy=minimum.energy
     cluster.quenched=True
     return cluster
Exemplo n.º 4
0
 def get_random_cluster(self):
     '''Return a cluster with random coordinates'''
     coords=(np.random.rand(self.natoms,3) -0.5) * 1.4 * float(self.natoms)**(1./3.)
     cluster = Cluster(self.natoms,
                       coords,
                       self.minimiser,
                       atom_types=get_atom_types(self.composition),
                       labels=self.labels)
     cluster.quenched=False
     return cluster
Exemplo n.º 5
0
 def read_db(self, minimum):
     '''Read structure from Pele minimum'''
     cluster = Cluster(self.natoms,
                       np.reshape(minimum.coords, (-1, 3)),
                       self.minimiser,
                       atom_types=get_atom_types(self.composition),
                       labels=self.labels)
     cluster.energy = minimum.energy
     cluster.quenched = True
     return cluster
Exemplo n.º 6
0
class ClusterTest(unittest.TestCase):
    def setUp(self):
        self.natoms=3
        minimiser=PeleMinimiser(lj.LJ())
        coords=np.array(((0.,0.,0.1),
                         (1.,1.,0.3),
                         (0.,2.,0.2)))
        self.cluster = Cluster(self.natoms,coords,minimiser)
        
    def test_z_sort(self):
        self.cluster.sort_z()
        for i in range(1,self.natoms):
            self.assertGreater(self.cluster.get_coords(i)[2],
                               self.cluster.get_coords(i-1)[2])
   
    def test_get_energy(self):
        self.assertAlmostEquals(self.cluster.get_energy(),-3.)
        
    def test_centre(self):
        self.assertEquals(self.cluster.centre()[1],-1.)
    
    def test_get_atom(self):
        self.assertEquals(self.cluster.get_coords(0)[0],0.0)
        self.assertEquals(self.cluster.get_coords(0)[1],0.0)
        self.assertEquals(self.cluster.get_coords(0)[2],0.1)
        
    def test_get_label(self):
        self.assertEquals(self.cluster.get_label(2),"X")
class ClusterTest(unittest.TestCase):
    def setUp(self):
        self.natoms = 3
        minimiser = PeleMinimiser(lj.LJ())
        coords = np.array(((0., 0., 0.1), (1., 1., 0.3), (0., 2., 0.2)))
        self.cluster = Cluster(self.natoms, coords, minimiser)

    def test_z_sort(self):
        self.cluster.sort_z()
        for i in range(1, self.natoms):
            self.assertGreater(
                self.cluster.get_coords(i)[2],
                self.cluster.get_coords(i - 1)[2])

    def test_get_energy(self):
        self.assertAlmostEquals(self.cluster.get_energy(), -3.)

    def test_centre(self):
        self.assertEquals(self.cluster.centre()[1], -1.)

    def test_get_atom(self):
        self.assertEquals(self.cluster.get_coords(0)[0], 0.0)
        self.assertEquals(self.cluster.get_coords(0)[1], 0.0)
        self.assertEquals(self.cluster.get_coords(0)[2], 0.1)

    def test_get_label(self):
        self.assertEquals(self.cluster.get_label(2), "X")
 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)
Exemplo n.º 9
0
 def get_random_cluster(self):
     '''Return a cluster with random coordinates'''
     coords = (np.random.rand(self.natoms, 3) - 0.5) * 1.4 * float(
         self.natoms)**(1. / 3.)
     cluster = Cluster(self.natoms,
                       coords,
                       self.minimiser,
                       atom_types=get_atom_types(self.composition),
                       labels=self.labels)
     cluster.quenched = False
     return cluster
Exemplo n.º 10
0
class OverlapTest(unittest.TestCase):
    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)

    def test_cutoff_default(self):
        self.cluster.fix_overlaps()
        self.assertGreaterEqual(min_dist(self.cluster._coords), 1.0)

    def test_cutoff_2(self):
        self.cluster.fix_overlaps(2.0)
        self.assertGreaterEqual(min_dist(self.cluster._coords), 2.0)
Exemplo n.º 11
0
 def get_mutant(self, cluster):
     cluster.sort_type()
     atom_types = list(cluster.atom_types)
     swap0 = np.random.randint(0, get_composition(atom_types)[0])
     swap1 = np.random.randint(
         get_composition(atom_types)[0], cluster.natoms)
     atom_types[swap0] = 1
     atom_types[swap1] = 0
     mutant = Cluster(cluster.natoms,
                      np.array(cluster._coords),
                      cluster.minimiser,
                      atom_types=atom_types,
                      labels=cluster.labels)
     mutant.sort_type()
     return mutant
Exemplo n.º 12
0
 def read_xyz(self,xyz_file):
     '''Read structure from xyz file.'''
     natoms=int(xyz_file.readline())
     coords=np.empty(shape=(natoms,3))
     energy=float(xyz_file.readline().split()[1])
     for i in range(0,natoms):
         coords[i]=xyz_file.readline().split()[1:4]
     cluster=Cluster(natoms,
                     coords,
                     self.minimiser,
                     atom_types=get_atom_types(self.composition),
                     labels=self.labels)
     cluster.energy=energy
     cluster.quenched=True
     return cluster
Exemplo n.º 13
0
 def read_xyz(self, xyz_file):
     '''Read structure from xyz file.'''
     natoms = int(xyz_file.readline())
     coords = np.empty(shape=(natoms, 3))
     energy = float(xyz_file.readline().split()[1])
     for i in range(0, natoms):
         coords[i] = xyz_file.readline().split()[1:4]
     cluster = Cluster(natoms,
                       coords,
                       self.minimiser,
                       atom_types=get_atom_types(self.composition),
                       labels=self.labels)
     cluster.energy = energy
     cluster.quenched = True
     return cluster
Exemplo n.º 14
0
 def get_mutant(self,cluster):
     cluster.sort_type()
     atom_types=list(cluster.atom_types)
     swap0=np.random.randint(0,
                             get_composition(atom_types)[0])
     swap1=np.random.randint(get_composition(atom_types)[0],
                             cluster.natoms)
     atom_types[swap0]=1
     atom_types[swap1]=0
     mutant=Cluster(cluster.natoms,
                     np.array(cluster._coords),
                     cluster.minimiser,
                     atom_types=atom_types,
                     labels=cluster.labels)
     mutant.sort_type()
     return mutant
Exemplo n.º 15
0
class OverlapTest(unittest.TestCase):
    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)
        
    def test_cutoff_default(self):
        self.cluster.fix_overlaps()
        self.assertGreaterEqual(min_dist(self.cluster._coords), 1.0)
        
    def test_cutoff_2(self):
        self.cluster.fix_overlaps(2.0)
        self.assertGreaterEqual(min_dist(self.cluster._coords), 2.0)
Exemplo n.º 16
0
 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)
Exemplo n.º 17
0
 def get_mutant(self, cluster):
     coords = (np.random.rand(cluster.natoms, 3) - 0.5) * 1.4 * float(
         cluster.natoms)**(1. / 3.)
     mutant = Cluster(cluster.natoms,
                      coords,
                      cluster.minimiser,
                      atom_types=list(cluster.atom_types),
                      labels=cluster.labels)
     return mutant
Exemplo n.º 18
0
 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)
Exemplo n.º 19
0
class BinaryClusterTest(unittest.TestCase):
    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_labels(self):
        self.assertEquals(self.cluster.get_label(0),"X")
        self.assertEquals(self.cluster.get_label(1),"Y")
        self.assertEquals(self.cluster.get_label(2),"X")

    def test_sort_labels(self):
        self.cluster.sort_z()
        self.assertEquals(self.cluster.get_label(0),"X")
        self.assertEquals(self.cluster.get_label(1),"X")
        self.assertEquals(self.cluster.get_label(2),"Y")    
Exemplo n.º 20
0
class BinaryClusterTest(unittest.TestCase):
    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_labels(self):
        self.assertEquals(self.cluster.get_label(0), "X")
        self.assertEquals(self.cluster.get_label(1), "Y")
        self.assertEquals(self.cluster.get_label(2), "X")

    def test_sort_labels(self):
        self.cluster.sort_z()
        self.assertEquals(self.cluster.get_label(0), "X")
        self.assertEquals(self.cluster.get_label(1), "X")
        self.assertEquals(self.cluster.get_label(2), "Y")
Exemplo n.º 21
0
 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)
Exemplo n.º 22
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)