def make_hcp_0001_cell(size=(1, 1, 1), symbols=['Ni'], pbc=(1, 1, 1)): direction_x = [2, -1, -1, 0] direction_y = [0, 1, -1, 0] direction_z = [0, 0, 0, 1] directions = [direction_x, direction_y, direction_z] atoms = None try: atoms = HexagonalClosedPacked( directions=[direction_x, direction_y, direction_z], size=size, symbol=symbols[0], pbc=pbc) except ValueError as e: if str( e ) == 'Cannot guess the hcp lattice constant of an element with crystal structure fcc.': r = get_atomic_radius(symbol=symbols[0]) _lattice_constants = {} _lattice_constants['a'] = r _lattice_constants['c/a'] = 1.663 atoms = HexagonalClosedPacked(\ directions=directions, size=size, symbol=symbols[0], pbc=pbc, latticeconstant=_lattice_constants) else: raise return atoms
def EfccEhcpCalculator(self, EMT, PARAMETERS): # Return 0 is used when the method is not desired to be used # return 0 """ This method uses the EMT calculator to calculate and return the difference in energy between a system of atoms placed in the HCP and FCC structure. """ # The atoms objects are created using the input size and element and the energy calculator # is set to the EMT calculator # The Lattice Constants, a,c, for the HCP lattice is here given by the nearest neighbor distance of # the system in the FCC crystal structure, a = dnn, and the ideal relation between a and # c: a/c = sqrt(8/3) => c = dnn / sqrt(8/3) a = beta * PARAMETERS[self.Element][1] * Bohr c = a * numpy.sqrt(8. / 3.) # The HCP crystal is created, the size of the crystal is defined as 5,5,5, any smaller crystal will result in # Neighborlist errors. atoms1 = HexagonalClosedPacked(size=(5, 5, 5), directions=[[2, -1, -1, 0], [0, 1, -1, 0], [0, 0, 0, 1]], symbol=self.Element, latticeconstant={ 'a': a, 'c': c }) atoms1.set_calculator(EMT) # The FCC crystal is created atoms2 = FaceCenteredCubic(size=(self.Size, self.Size, self.Size), symbol=self.Element) atoms2.set_calculator(EMT) # The energy difference pr atom is calculated and returned return atoms1.get_potential_energy() / len( atoms1) - atoms2.get_potential_energy() / len(atoms2)
def test_lattice_lindep(): from ase.lattice.cubic import FaceCenteredCubic from ase.lattice.hexagonal import HexagonalClosedPacked from ase.test import must_raise with must_raise(ValueError): # The Miller indices of the surfaces are linearly dependent atoms = FaceCenteredCubic(symbol='Cu', miller=[[1, 1, 0], [1, 1, 0], [0, 0, 1]]) # This one should be OK: atoms = FaceCenteredCubic(symbol='Cu', miller=[[1, 1, 0], [0, 1, 0], [0, 0, 1]]) print(atoms.get_cell()) with must_raise(ValueError): # The directions spanning the unit cell are linearly dependent atoms = FaceCenteredCubic(symbol='Cu', directions=[[1, 1, 0], [1, 1, 0], [0, 0, 1]]) with must_raise(ValueError): # The directions spanning the unit cell are linearly dependent atoms = FaceCenteredCubic(symbol='Cu', directions=[[1, 1, 0], [1, 0, 0], [0, 1, 0]]) # This one should be OK: atoms = FaceCenteredCubic(symbol='Cu', directions=[[1, 1, 0], [0, 1, 0], [0, 0, 1]]) print(atoms.get_cell()) with must_raise((ValueError, NotImplementedError)): # The Miller indices of the surfaces are linearly dependent atoms = HexagonalClosedPacked(symbol='Mg', miller=[[1, -1, 0, 0], [1, 0, -1, 0], [0, 1, -1, 0]]) # This one should be OK # # It is not! The miller argument is broken in hexagonal crystals! # # atoms = HexagonalClosedPacked(symbol='Mg', # miller=[[1, -1, 0, 0], # [1, 0, -1, 0], # [0, 0, 0, 1]]) # print(atoms.get_cell()) with must_raise(ValueError): # The directions spanning the unit cell are linearly dependent atoms = HexagonalClosedPacked(symbol='Mg', directions=[[1, -1, 0, 0], [1, 0, -1, 0], [0, 1, -1, 0]]) # This one should be OK atoms = HexagonalClosedPacked(symbol='Mg', directions=[[1, -1, 0, 0], [1, 0, -1, 0], [0, 0, 0, 1]]) print(atoms.get_cell())
def main(): for x in fccs+bccs+hcps+diamonds+rocksalts+zincblendes+cscls: f = x in fccs b = x in bccs h = x in hcps d = x in diamonds r = x in rocksalts z = x in zincblendes c = x in cscls try: if f: a = FaceCenteredCubic(x[0]).get_cell()[0][0]/2 elif b: a = BodyCenteredCubic(x[0]).get_cell()[0][0]/2 elif d: a = Diamond(x[0]).get_cell()[0][0]/2 elif h: cell = HexagonalClosedPacked(x[0]).get_cell() a,c = cell[0][0],cell[2][2] elif r | z | c: a = dataLookup(x[0]) else: raise NotImplementedError except ValueError: a = sum([radDict[e] for e in elems])/len(elems) print "Had to guess lattice constant of "+x[0] if f: name,struc,pos,cell,n = '-fcc', 'fcc', [[0,0,0]], [[0,a,a],[a,0,a],[a,a,0]], 1 elif b: name,struc,pos,cell,n = '-bcc', 'bcc', [[0,0,0]], [[a,a,-a],[-a,a,a],[a,-a,a]],1 elif h: name,struc,pos,cell,n = '-hcp', 'hexagonal', [[0,0,0],[2./3,1./3,1./2]], [a,a,c,90,90,120], 2 elif d: name,struc,pos,cell,n = '-diamond', 'diamond', [[0,0,0],[0.25,0.25,0.25]], [[0,a,a],[a,0,a],[a,a,0]], 2 elif z: name,struc,pos,cell,n = '-zincblende','zincblende', [[0,0,0],[0.25,0.25,0.25]], [[0,a,a],[a,0,a],[a,a,0]], 1 elif r: name,struc,pos,cell,n = '-rocksalt', 'rocksalt', [[0,0,0],[0.5,0.5,0.5]], [[0,a,a],[a,0,a],[a,a,0]], 1 elif c: name,struc,pos,cell,n = '-cscl', 'cubic', [[0,0,0],[0.5,0.5,0.5]], [a,a,a,90,90,90], 1 mag = magLookup(x[0]) elems = parseChemicalFormula(x[0]).keys()*n magmoms = [magmomInit if e in magElems else 0 for e in elems] atoms = Atoms(elems,scaled_positions=pos,cell=cell,pbc=[1,1,1],magmoms=magmoms,calculator=EMT()) info = {'name': x[0]+name ,'relaxed': False ,'emt': atoms.get_potential_energy()/len(elems) #normalized to per-atom basis ,'comments': 'Autogenerated by createTrajs' ,'kind': 'bulk' # vs surface/molecules ### Stuff for bulk ,'structure': struc ### Stuff for surfaces ,'parent': None ,'sites': None ,'facet': None ,'xy': None ,'layers': None ,'constrained': None ,'symmetric': None ,'vacuum': None ,'adsorbates': None} db.write(atoms,key_value_pairs=info)
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)
for b in bccs: try: a = BodyCenteredCubic(b[0]).get_cell()[0][0]/2 except ValueError: a = radDict[b[0]]; print "Should look up lattice constant of "+b[0] name = root+b[0]+'-bcc.traj' mag = magLookup(b[0]) info = {'name':b[0]+'-bcc','bravais':'cubic','mag':mag,'comments':'Autogenerated by createTrajs'} if name not in ds: io.write(name,Atoms(b[0],scaled_positions=[[0,0,0]],cell=[[a,a,-a],[-a,a,a],[a,-a,a]],pbc=[1,1,1] ,magmoms=[3 if e in magElems else 0 for e in b[0]],info=info)) ##################################################################### ##################################################################### for h in hcps: try: cell = HexagonalClosedPacked(h[0]).get_cell() a,c = cell[0][0],cell[2][2] except ValueError: a = radDict[h[0]] c = a*1.7 name = root+h[0]+'-hcp.traj' mag = magLookup(h[0]) info = {'name':h[0]+'-hcp','bravais':'hexagonal','mag':mag,'comments':'Autogenerated by createTrajs'} if name not in ds: io.write(name,Atoms([h[0]]*2,scaled_positions=[[0,0,0],[2./3,1./3,1./2]],cell=[a,a,c,90,90,120],pbc=[1,1,1] magmoms=[3 if e in magElems else 0 for e in h[0]],info=info)) ##################################################################### ##################################################################### for d in diamonds: try: a = Diamond(d[0]).get_cell()[0][0]*(2**(-0.5))
directions=[[1, 1, 0], [1, 1, 0], [0, 0, 1]]) with must_raise(ValueError): # The directions spanning the unit cell are linearly dependent atoms = FaceCenteredCubic(symbol='Cu', directions=[[1, 1, 0], [1, 0, 0], [0, 1, 0]]) # This one should be OK: atoms = FaceCenteredCubic(symbol='Cu', directions=[[1, 1, 0], [0, 1, 0], [0, 0, 1]]) print(atoms.get_cell()) with must_raise((ValueError, NotImplementedError)): # The Miller indices of the surfaces are linearly dependent atoms = HexagonalClosedPacked(symbol='Mg', miller=[[1, -1, 0, 0], [1, 0, -1, 0], [0, 1, -1, 0]]) # This one should be OK # # It is not! The miller argument is broken in hexagonal crystals! # # atoms = HexagonalClosedPacked(symbol='Mg', # miller=[[1, -1, 0, 0], # [1, 0, -1, 0], # [0, 0, 0, 1]]) # print(atoms.get_cell()) with must_raise(ValueError): # The directions spanning the unit cell are linearly dependent atoms = HexagonalClosedPacked(symbol='Mg',
from ase.lattice.hexagonal import HexagonalClosedPacked from vasp import Vasp import matplotlib.pyplot as plt atoms = HexagonalClosedPacked(symbol='Ru', latticeconstant={'a': 2.7, 'c/a': 1.584}) a_list = [2.5, 2.6, 2.7, 2.8, 2.9] covera_list = [1.4, 1.5, 1.6, 1.7, 1.8] for a in a_list: energies = [] for covera in covera_list: atoms = HexagonalClosedPacked(symbol='Ru', latticeconstant={'a': a, 'c/a': covera}) wd = 'bulk/Ru/{0:1.2f}-{1:1.2f}'.format(a, covera) calc = Vasp(wd, xc='PBE', # the c-axis is longer than the a-axis, so we use # fewer kpoints. kpts=[6, 6, 4], encut=350, atoms=atoms) energies.append(atoms.get_potential_energy()) if not None in energies: plt.plot(covera_list, energies, label=r'a={0} $\AA$'.format(a)) plt.xlabel('$c/a$') plt.ylabel('Energy (eV)') plt.legend() plt.savefig('images/Ru-covera-scan.png')
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
def test_hcp(): atoms = HexagonalClosedPacked(symbol='Mg', directions=[[1, -1, 0, 0], [1, 0, -1, 0], [0, 0, 0, 1]]) print(atoms.get_cell())
def test_hcp_cell_linearly_dependent(): with pytest.raises(ValueError): # The directions spanning the unit cell are linearly dependent HexagonalClosedPacked(symbol='Mg', directions=[[1, -1, 0, 0], [1, 0, -1, 0], [0, 1, -1, 0]])
def test_hcp_miller_lienarly_dependent(): with pytest.raises((ValueError, NotImplementedError)): # The Miller indices of the surfaces are linearly dependent HexagonalClosedPacked(symbol='Mg', miller=[[1, -1, 0, 0], [1, 0, -1, 0], [0, 1, -1, 0]])
a = Triclinic(directions=[[2, 1, 0], [-2, 3, 0], [0, 1, 4]], size=(3, 3, 3), symbol="Cu", latticeconstant=(3.61, a0, a0, 60, 45, 45)) testFCC(a, 32 * 3 * 3 * 3, "Triclinic/FCC 3") a = BaseCenteredMonoclinic(directions=[[2, 1, 0], [-2, 3, 0], [0, 1, 4]], size=(3, 3, 3), symbol="Cu", latticeconstant=(3.61, 3.61, a0, 45)) testFCC(a, 64 * 3 * 3 * 3, "Monoclinic/FCC") a0 = 3.15 * sqrt(3) / 2 a = Triclinic(directions=[[2, 1, 0], [-2, 3, 0], [0, 1, 4]], size=(3, 3, 3), symbol="Mo", latticeconstant=(3.15, 3.15, a0, 54.736, 54.736, 90)) testBCC(a, 32 * 3 * 3 * 3, "Triclinic/BCC") a = HexagonalClosedPacked(directions=[[2, -1, -1, 0], [0, 1, -1, 0], [0, 0, 0, 1]], size=(10, 5, 5), symbol="Cu", latticeconstant={ 'a': 3.61 / sqrt(2), 'c/a': 2 * sqrt(2) / sqrt(3) }) testHCP(a, 1000, "HCP 1") ReportTest.Summary()
from ase.lattice.hexagonal import HexagonalClosedPacked from vasp import Vasp import matplotlib.pyplot as plt atoms = HexagonalClosedPacked(symbol='Ru', latticeconstant={ 'a': 2.7, 'c/a': 1.584 }) a_list = [2.5, 2.6, 2.7, 2.8, 2.9] covera_list = [1.4, 1.5, 1.6, 1.7, 1.8] for a in a_list: energies = [] for covera in covera_list: atoms = HexagonalClosedPacked(symbol='Ru', latticeconstant={ 'a': a, 'c/a': covera }) wd = 'bulk/Ru/{0:1.2f}-{1:1.2f}'.format(a, covera) calc = Vasp( wd, xc='PBE', # the c-axis is longer than the a-axis, so we use # fewer kpoints. kpts=[6, 6, 4], encut=350, atoms=atoms) energies.append(atoms.get_potential_energy()) if not None in energies: plt.plot(covera_list, energies, label=r'a={0} $\AA$'.format(a)) plt.xlabel('$c/a$')
def main(): for x in fccs + bccs + hcps + diamonds + rocksalts + zincblendes + cscls: f = x in fccs b = x in bccs h = x in hcps d = x in diamonds r = x in rocksalts z = x in zincblendes c = x in cscls try: if f: a = FaceCenteredCubic(x[0]).get_cell()[0][0] / 2 elif b: a = BodyCenteredCubic(x[0]).get_cell()[0][0] / 2 elif d: a = Diamond(x[0]).get_cell()[0][0] / 2 elif h: cell = HexagonalClosedPacked(x[0]).get_cell() a, c = cell[0][0], cell[2][2] elif r | z | c: a = dataLookup(x[0]) else: raise NotImplementedError except ValueError: a = dataLookup(x[0]) / 2 print "Had to guess lattice constant of " + x[0] if f: name, struc, pos, cell, n = '-fcc', 'fcc', [[0, 0, 0]], [[0, a, a], [a, 0, a], [a, a, 0]], 1 elif b: name, struc, pos, cell, n = '-bcc', 'bcc', [[0, 0, 0]], [[a, a, -a], [-a, a, a], [a, -a, a]], 1 elif h: name, struc, pos, cell, n = '-hcp', 'hexagonal', [[ 0, 0, 0 ], [2. / 3, 1. / 3, 1. / 2]], [a, a, c, 90, 90, 120], 2 elif d: name, struc, pos, cell, n = '-diamond', 'diamond', [[ 0, 0, 0 ], [0.25, 0.25, 0.25]], [[0, a, a], [a, 0, a], [a, a, 0]], 2 elif z: name, struc, pos, cell, n = '-zincblende', 'zincblende', [[ 0, 0, 0 ], [0.25, 0.25, 0.25]], [[0, a, a], [a, 0, a], [a, a, 0]], 1 elif r: name, struc, pos, cell, n = '-rocksalt', 'rocksalt', [[ 0, 0, 0 ], [0.5, 0.5, 0.5]], [[0, a, a], [a, 0, a], [a, a, 0]], 1 elif c: name, struc, pos, cell, n = '-cscl', 'cubic', [[0, 0, 0], [0.5, 0.5, 0.5]], [ a, a, a, 90, 90, 90 ], 1 mag = magLookup(x[0]) elems = parseChemicalFormula(x[0]).keys() * n magmoms = [magmomInit if e in misc.magElems else 0 for e in elems] atoms = Atoms(elems, scaled_positions=pos, cell=cell, pbc=[1, 1, 1], magmoms=magmoms) info = {'name': x[0] + name, 'structure': struc} db.write(atoms, key_value_pairs=info)
# properties with a given model # # INPUTS: # model.calculator -- an ase.calculator.Calculator instance # this script can assume the calculator is checkpointed. # # OUTPUTS: # properties -- dictionary of key/value pairs corresponding # to physical quantities computed by this test # standard ASE structure generation routines from ase.lattice.hexagonal import HexagonalClosedPacked from math import sqrt import lattice_tetragonal # the current model import model c_over_a = 1.8 a0 = (16.0*2*2/sqrt(3.0)/c_over_a)**(1.0/3.0)# initial guess at lattice constant, cell will be relaxed below # set up the a bulk = HexagonalClosedPacked(symbol='Si', latticeconstant=(a0,a0*c_over_a)) (E_vs_V) = lattice_tetragonal.do_lattice(bulk, elastic=False, tol=1.0e-2) # dictionary of computed properties - this is output of this test, to # be compared with other models properties = {'hcp_E_vs_V': E_vs_V }
if __name__ == '__main__': from asap3 import EMT, units, EMThcpParameters from ase.lattice.cubic import FaceCenteredCubic from ase.lattice.hexagonal import HexagonalClosedPacked print "Calculating cubic constants for Cu" atoms = FaceCenteredCubic(size=(5, 5, 5), symbol='Cu', latticeconstant=3.59495722231) atoms.set_calculator(EMT()) e = ElasticConstants(atoms, 'cubic') print np.array(e) / units.GPa print "Pretending that Cu is hexagonal" e = ElasticConstants(atoms, 'hexagonal', sanity=False) print np.array(e) / units.GPa print "Calculating elastic constants for Ru" atoms = HexagonalClosedPacked(size=(5, 5, 5), symbol='Ru', directions=[[1, -2, 1, 0], [1, 0, -1, 0], [0, 0, 0, 1]]) atoms.set_calculator(EMT(EMThcpParameters())) e = ElasticConstants(atoms, 'hexagonal', minimize=True) print np.array(e) / units.GPa print "The EMT values are not even close to experimental values!" print "Pretending Ru is cubic" e = ElasticConstants(atoms, 'cubic') print np.array(e) / units.GPa