예제 #1
0
    def test_direct_evaluation(self):
        a = FaceCenteredCubic('Au', size=[2,2,2])
        a.rattle(0.1)
        calc = EAM('Au-Grochola-JCP05.eam.alloy')
        a.set_calculator(calc)
        f = a.get_forces()

        calc2 = EAM('Au-Grochola-JCP05.eam.alloy')
        i_n, j_n, dr_nc, abs_dr_n = neighbour_list('ijDd', a, cutoff=calc2.cutoff)
        epot, virial, f2 = calc2.energy_virial_and_forces(a.numbers, i_n, j_n, dr_nc, abs_dr_n)
        self.assertArrayAlmostEqual(f, f2)

        a = FaceCenteredCubic('Cu', size=[2,2,2])
        calc = EAM('CuAg.eam.alloy')
        a.set_calculator(calc)
        FIRE(StrainFilter(a, mask=[1,1,1,0,0,0]), logfile=None).run(fmax=0.001)
        e_Cu = a.get_potential_energy()/len(a)
 
        a = FaceCenteredCubic('Ag', size=[2,2,2])
        a.set_calculator(calc)
        FIRE(StrainFilter(a, mask=[1,1,1,0,0,0]), logfile=None).run(fmax=0.001)
        e_Ag = a.get_potential_energy()/len(a)
        self.assertTrue(abs(e_Ag+2.85)<1e-6)
 
        a = L1_2(['Ag', 'Cu'], size=[2,2,2], latticeconstant=4.0)
        a.set_calculator(calc)
        FIRE(UnitCellFilter(a, mask=[1,1,1,0,0,0]), logfile=None).run(fmax=0.001)
        e = a.get_potential_energy()
        syms = np.array(a.get_chemical_symbols())
        self.assertTrue(abs((e-(syms=='Cu').sum()*e_Cu-
                               (syms=='Ag').sum()*e_Ag)/len(a)-0.096)<0.0005)
 
        a = B1(['Ag', 'Cu'], size=[2,2,2], latticeconstant=4.0)
        a.set_calculator(calc)
        FIRE(UnitCellFilter(a, mask=[1,1,1,0,0,0]), logfile=None).run(fmax=0.001)
        e = a.get_potential_energy()
        syms = np.array(a.get_chemical_symbols())
        self.assertTrue(abs((e-(syms=='Cu').sum()*e_Cu-
                               (syms=='Ag').sum()*e_Ag)/len(a)-0.516)<0.0005)
 
        a = B2(['Ag', 'Cu'], size=[2,2,2], latticeconstant=4.0)
        a.set_calculator(calc)
        FIRE(UnitCellFilter(a, mask=[1,1,1,0,0,0]), logfile=None).run(fmax=0.001)
        e = a.get_potential_energy()
        syms = np.array(a.get_chemical_symbols())
        self.assertTrue(abs((e-(syms=='Cu').sum()*e_Cu-
                               (syms=='Ag').sum()*e_Ag)/len(a)-0.177)<0.0003)
 
        a = L1_2(['Cu', 'Ag'], size=[2,2,2], latticeconstant=4.0)
        a.set_calculator(calc)
        FIRE(UnitCellFilter(a, mask=[1,1,1,0,0,0]), logfile=None).run(fmax=0.001)
        e = a.get_potential_energy()
        syms = np.array(a.get_chemical_symbols())
        self.assertTrue(abs((e-(syms=='Cu').sum()*e_Cu-
                                (syms=='Ag').sum()*e_Ag)/len(a)-0.083)<0.0005)
예제 #2
0
    def test_CuAg(self):
        a = FaceCenteredCubic('Cu', size=[2, 2, 2])
        calc = EAM('CuAg.eam.alloy')
        a.set_calculator(calc)
        FIRE(StrainFilter(a, mask=[1, 1, 1, 0, 0, 0]),
             logfile=None).run(fmax=0.001)
        e_Cu = a.get_potential_energy() / len(a)

        a = FaceCenteredCubic('Ag', size=[2, 2, 2])
        a.set_calculator(calc)
        FIRE(StrainFilter(a, mask=[1, 1, 1, 0, 0, 0]),
             logfile=None).run(fmax=0.001)
        e_Ag = a.get_potential_energy() / len(a)
        self.assertTrue(abs(e_Ag + 2.85) < 1e-6)

        a = L1_2(['Ag', 'Cu'], size=[2, 2, 2], latticeconstant=4.0)
        a.set_calculator(calc)
        FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]),
             logfile=None).run(fmax=0.001)
        e = a.get_potential_energy()
        syms = np.array(a.get_chemical_symbols())
        self.assertTrue(
            abs((e - (syms == 'Cu').sum() * e_Cu -
                 (syms == 'Ag').sum() * e_Ag) / len(a) - 0.096) < 0.0005)

        a = B1(['Ag', 'Cu'], size=[2, 2, 2], latticeconstant=4.0)
        a.set_calculator(calc)
        FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]),
             logfile=None).run(fmax=0.001)
        e = a.get_potential_energy()
        syms = np.array(a.get_chemical_symbols())
        self.assertTrue(
            abs((e - (syms == 'Cu').sum() * e_Cu -
                 (syms == 'Ag').sum() * e_Ag) / len(a) - 0.516) < 0.0005)

        a = B2(['Ag', 'Cu'], size=[2, 2, 2], latticeconstant=4.0)
        a.set_calculator(calc)
        FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]),
             logfile=None).run(fmax=0.001)
        e = a.get_potential_energy()
        syms = np.array(a.get_chemical_symbols())
        self.assertTrue(
            abs((e - (syms == 'Cu').sum() * e_Cu -
                 (syms == 'Ag').sum() * e_Ag) / len(a) - 0.177) < 0.0003)

        a = L1_2(['Cu', 'Ag'], size=[2, 2, 2], latticeconstant=4.0)
        a.set_calculator(calc)
        FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]),
             logfile=None).run(fmax=0.001)
        e = a.get_potential_energy()
        syms = np.array(a.get_chemical_symbols())
        self.assertTrue(
            abs((e - (syms == 'Cu').sum() * e_Cu -
                 (syms == 'Ag').sum() * e_Ag) / len(a) - 0.083) < 0.0005)
    def test_hessian_crystalline_alloy(self):
        """Calculate Hessian matrix of crystalline alloy

        Reference: finite difference approximation of 
        Hessian from ASE
        """
        calculator = EAM('ZrCu.onecolumn.eam.alloy')
        lattice_size = [4, 4, 4]
        # The lattice parameters are not correct, but that should be irrelevant
        # CuZr3
        atoms = L1_2(['Cu', 'Zr'], size=lattice_size, latticeconstant=4.0)
        self._test_hessian(atoms, calculator)
        # Cu3Zr
        atoms = L1_2(['Zr', 'Cu'], size=lattice_size, latticeconstant=4.0)
        self._test_hessian(atoms, calculator)
        # CuZr
        atoms = B2(['Zr', 'Cu'], size=lattice_size, latticeconstant=3.3)
        self._test_hessian(atoms, calculator)
예제 #4
0
    def test_CuZr(self):
        # This is a test for the potential published in:
        # Mendelev, Sordelet, Kramer, J. Appl. Phys. 102, 043501 (2007)
        a = FaceCenteredCubic('Cu', size=[2, 2, 2])
        calc = EAM('CuZr_mm.eam.fs', kind='eam/fs')
        a.set_calculator(calc)
        FIRE(StrainFilter(a, mask=[1, 1, 1, 0, 0, 0]),
             logfile=None).run(fmax=0.001)
        a_Cu = a.cell.diagonal().mean() / 2
        #print('a_Cu (3.639) = ', a_Cu)
        self.assertAlmostEqual(a_Cu, 3.639, 3)

        a = HexagonalClosedPacked('Zr', size=[2, 2, 2])
        a.set_calculator(calc)
        FIRE(StrainFilter(a, mask=[1, 1, 1, 0, 0, 0]),
             logfile=None).run(fmax=0.001)
        a, b, c = a.cell / 2
        #print('a_Zr (3.220) = ', norm(a), norm(b))
        #print('c_Zr (5.215) = ', norm(c))
        self.assertAlmostEqual(norm(a), 3.220, 3)
        self.assertAlmostEqual(norm(b), 3.220, 3)
        self.assertAlmostEqual(norm(c), 5.215, 3)

        # CuZr3
        a = L1_2(['Cu', 'Zr'], size=[2, 2, 2], latticeconstant=4.0)
        a.set_calculator(calc)
        FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]),
             logfile=None).run(fmax=0.001)
        self.assertAlmostEqual(a.cell.diagonal().mean() / 2, 4.324, 3)

        # Cu3Zr
        a = L1_2(['Zr', 'Cu'], size=[2, 2, 2], latticeconstant=4.0)
        a.set_calculator(calc)
        FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]),
             logfile=None).run(fmax=0.001)
        self.assertAlmostEqual(a.cell.diagonal().mean() / 2, 3.936, 3)

        # CuZr
        a = B2(['Zr', 'Cu'], size=[2, 2, 2], latticeconstant=3.3)
        a.set_calculator(calc)
        FIRE(UnitCellFilter(a, mask=[1, 1, 1, 0, 0, 0]),
             logfile=None).run(fmax=0.001)
        self.assertAlmostEqual(a.cell.diagonal().mean() / 2, 3.237, 3)
예제 #5
0
    def get_structure(self, name, elements, a=None, c=None, l=None):
        # Check number of elements
        if name[:3] in ['fcc', 'hcp']:
            if len(elements) != 1:
                raise ValueError("Tuple of elements must be of length one")
        if name[:3] in ['l12', 'l10'] or name[:2] == 'B2':
            if len(elements) != 2:
                raise ValueError("Tuple of elements must be of length two")

        # Get lattice constants
        if a is None:
            if name[:2] == 'B2':
                a = self.get_lattice_constant_a(name[:2], elements)
            elif name[:3] in ['fcc', 'hcp', 'bcc', 'l12', 'l10']:
                a = self.get_lattice_constant_a(name[:3], elements)

        if c is None:
            if name[:3] in ['hcp', 'l10']:
                c = self.get_lattice_constant_c(name[:3], elements)

        # Get size
        if name in ['fcc', 'hcp', 'bcc', 'l12', 'l10', 'B2']:
            size = self.properties[name + '_size']
        elif name in ['fcc100', 'fcc111', 'hcp0001']:
            size = self.properties[name + '_size'][:2] + (l, )

        # Make structure
        if name == 'fcc':
            atoms = FaceCenteredCubic(symbol=elements[0],
                                      size=size,
                                      latticeconstant=a)
        elif name == 'hcp':
            atoms = HexagonalClosedPacked(symbol=elements[0],
                                          size=size,
                                          directions=[[2, -1, -1, 0],
                                                      [0, 1, -1, 0],
                                                      [0, 0, 0, 1]],
                                          latticeconstant=(a, c))
        elif name == 'bcc':
            atoms = BodyCenteredCubic(symbol=elements[0],
                                      size=size,
                                      latticeconstant=a)
        elif name == 'B2':
            atoms = B2(symbol=elements, size=size, latticeconstant=a)
        elif name == 'l12':
            atoms = L1_2(symbol=elements, size=size, latticeconstant=a)
        elif name == 'l10':
            atoms = L1_0(symbol=elements, size=size, latticeconstant=(a, c))
        elif name == 'fcc100':
            atoms = fcc100(symbol=elements[0], size=size, a=a, vacuum=10.0)
        elif name == 'fcc111':
            atoms = fcc111(symbol=elements[0],
                           size=size,
                           a=a,
                           vacuum=10.0,
                           orthogonal=True)
        elif name == 'hcp0001':
            atoms = hcp0001(symbol=elements[0],
                            size=size,
                            a=a,
                            c=c,
                            vacuum=10.0,
                            orthogonal=True)
        elif name == 'hcp1010A':
            raise ValueError("Structure '%s' not supported" % (name, ))
            atoms = None
        elif name == 'hcp1010B':
            raise ValueError("Structure '%s' not supported" % (name, ))
            atoms = None
        elif name == 'l12100':
            n = (l + 1) / 2
            atoms = L1_2(symbol=elements, size=(8, 8, n), latticeconstant=a)
            atoms.set_pbc([True, True, False])
            # Remove layers
            atoms = atoms[atoms.get_positions()[:, 2] > 0.1 * a]
            # Set vacuum
            atoms.center(axis=2, vacuum=10.0)
        elif name == 'l12111':
            if l % 3 == 0:
                n = l / 3
                c = 0
            else:
                n = l / 3 + 1
                c = 3 - l % 3
            atoms = L1_2(
                symbol=elements,
                size=(8, 4, n),
                #directions=[[1,-1,0],[1,0,-1],[1,1,1]], latticeconstant=a)
                directions=[[1, -1, 0], [1, 1, -2], [1, 1, 1]],
                latticeconstant=a)
            atoms.set_pbc([True, True, False])
            # Wrap positions
            scpos = atoms.get_scaled_positions()
            scpos[scpos > (1.0 - 1e-12)] = 0.0
            atoms.set_scaled_positions(scpos)
            # Remove layers
            if c > 0:
                atoms = atoms[atoms.get_positions()[:, 2] > (c - 0.5) * a /
                              np.sqrt(3.0)]
            # Set vacuum
            atoms.center(axis=2, vacuum=10.0)
        else:
            raise ValueError("Structure '%s' not supported" % (name, ))
        return atoms
예제 #6
0
         dict(name="dia-C",
              struct=Diamond("C", size=[sx, sx, sx]),
              Ec=7.376 - 0.0524,
              a0=3.558,
              C11=621,
              C12=415,
              C44=383,
              B=484),
         dict(name='B1-W-C',
              struct=B1(['W', 'C'], latticeconstant=4.38, size=[sx, sx,
                                                                sx]),
              Ec=(16.68 - 0.98) / 2,
              a0=4.380,
              B=433),
         dict(name='B2-W-C',
              struct=B2(['W', 'C'], latticeconstant=2.7, size=[sx, sx, sx]),
              Ec=(16.68 - 2.32) / 2,
              a0=2.704,
              B=411),
         dict(name='B3-W-C',
              struct=B3(['W', 'C'], latticeconstant=4.6, size=[sx, sx, sx]),
              Ec=(16.68 - 2.12) / 2,
              a0=4.679,
              B=511),
     ]),
 (Kumagai, Kumagai_CompMaterSci_39_457_Si, [
     dict(name="dia-Si",
          struct=Diamond("Si", size=[sx, sx, sx]),
          Ec=4.630,
          a0=5.429,
          C11=166.4,