コード例 #1
0
ファイル: asesurf2xxyz.py プロジェクト: jhiskard/NanoCore
def asesurf2xxyz(symb, lattice, index, size=(1,1,3), vac=15.0, orthogonal=0):
    """
    An interface function for ase.lattice.surface

    Usage:
    >>> atoms = asesurf2xxyz(symb, lattice, index, size, 
                             vac=15.0, orthogonal=0))

    Parameters:
    symb: atomic symbol
    lattice: 'fcc', 'bcc', or 'hcp0001'
    index: '100', '111' or '110' (if lattice is 'hcp0001', this will not work.)
    size: the number of atoms per each vector
    
    Optional Parameters:
    vac (default: 15.0 angstron): the thickness of space normal to the surface
    orthogonal (default: False) : if True, two lateral cell vectors will be 
    orthogonal.

    Example:
    >>> Fe_100_1x1 = asesurf2xxyz('Fe', 'bcc', '100', (1,1,2))
    >>> Au_111_2x2 = asesurf2xxyz('Au', 'fcc', '111', (1,1,3))
    """
    if lattice == 'fcc':
        if index   == '100': at_ase = AS.fcc100(symb, size, vacuum=vac)
        elif index == '111': at_ase = AS.fcc111(symb, size,
                                                orthogonal=orthogonal,
                                                vacuum=vac)
        elif index == '110': at_ase = AS.fcc110(symb, size, vacuum=vac)
        else: raise ValueError, "100, 111, or 110 surface is supported."
    elif lattice == 'bcc':
        if index   == '100': at_ase = AS.bcc100(symb, size, vacuum=vac)
        elif index == '111': at_ase = AS.bcc111(symb, size,
                                                orthogonal=orthogonal,
                                                vacuum=vac)
        elif index == '110': at_ase = AS.bcc110(symb, size,
                                                orthogonal=orthogonal,
                                                vacuum=vac)
        else: raise ValueError, "100, 111, or 110 surface is supported."
    elif lattice == 'hcp0001':
        at_ase = AS.hcp0001(symb, size, orthogonal=orthogonal, vacuum=vac)
    else: raise ValueError, "fcc, bcc, or hcp0001 surface is supported."
    
    symbols = at_ase.get_chemical_symbols()
    posits  = at_ase.get_positions()
    cell    = at_ase.get_cell()
    pbc     = at_ase.get_pbc()
    atoms = []; i=0
    for sym in symbols:
        temp_at = Atom(sym, list(posits[i]))
        atoms.append(temp_at.copy()); i+=1
    at_xxyz = AtomsSystem(atoms, cell=cell, pbc=pbc)
    return at_xxyz
コード例 #2
0
ファイル: asesurf2xxyz.py プロジェクト: yhkimlab/NanoCore
def asesurf2xxyz(symb, lattice, index, size=(1,1,3), vac=15.0, orthogonal=0):
    """
    An interface function for ase.lattice.surface

    Usage:
    >>> atoms = asesurf2xxyz(symb, lattice, index, size, 
                             vac=15.0, orthogonal=0))

    Parameters:
    symb: atomic symbol
    lattice: 'fcc', 'bcc', or 'hcp0001'
    index: '100', '111' or '110' (if lattice is 'hcp0001', this will not work.)
    size: the number of atoms per each vector
    
    Optional Parameters:
    vac (default: 15.0 angstron): the thickness of space normal to the surface
    orthogonal (default: False) : if True, two lateral cell vectors will be 
    orthogonal.

    Example:
    >>> Fe_100_1x1 = asesurf2xxyz('Fe', 'bcc', '100', (1,1,2))
    >>> Au_111_2x2 = asesurf2xxyz('Au', 'fcc', '111', (1,1,3))
    """
    if lattice == 'fcc':
        if index   == '100': at_ase = AS.fcc100(symb, size, vacuum=vac)
        elif index == '111': at_ase = AS.fcc111(symb, size,
                                                orthogonal=orthogonal,
                                                vacuum=vac)
        elif index == '110': at_ase = AS.fcc110(symb, size, vacuum=vac)
        else: raise ValueError("100, 111, or 110 surface is supported.")
    elif lattice == 'bcc':
        if index   == '100': at_ase = AS.bcc100(symb, size, vacuum=vac)
        elif index == '111': at_ase = AS.bcc111(symb, size,
                                                orthogonal=orthogonal,
                                                vacuum=vac)
        elif index == '110': at_ase = AS.bcc110(symb, size,
                                                orthogonal=orthogonal,
                                                vacuum=vac)
        else: raise ValueError("100, 111, or 110 surface is supported.")
    elif lattice == 'hcp0001':
        at_ase = AS.hcp0001(symb, size, orthogonal=orthogonal, vacuum=vac)
    else: raise ValueError("fcc, bcc, or hcp0001 surface is supported.")
    
    symbols = at_ase.get_chemical_symbols()
    posits  = at_ase.get_positions()
    cell    = at_ase.get_cell()
    pbc     = at_ase.get_pbc()
    atoms = []; i=0
    for sym in symbols:
        temp_at = Atom(sym, list(posits[i]))
        atoms.append(temp_at.copy()); i+=1
    at_xxyz = AtomsSystem(atoms, cell=cell, pbc=pbc)
    return at_xxyz
コード例 #3
0
def build():
    p = OptionParser(usage='%prog  [options] [ads@]surf [output file]',
                     version='%prog 0.1',
                     description='Example ads/surf: fcc-CO@2x2Ru0001')
    p.add_option('-l',
                 '--layers',
                 type='int',
                 default=4,
                 help='Number of layers.')
    p.add_option('-v', '--vacuum', type='float', default=5.0, help='Vacuum.')
    p.add_option('-x',
                 '--crystal-structure',
                 help='Crystal structure.',
                 choices=['sc', 'fcc', 'bcc', 'hcp'])
    p.add_option('-a',
                 '--lattice-constant',
                 type='float',
                 help='Lattice constant in Angstrom.')
    p.add_option('--c-over-a', type='float', help='c/a ratio.')
    p.add_option('--height',
                 type='float',
                 help='Height of adsorbate over surface.')
    p.add_option('--distance',
                 type='float',
                 help='Distance between adsorbate and nearest surface atoms.')
    p.add_option('-M',
                 '--magnetic-moment',
                 type='float',
                 default=0.0,
                 help='Magnetic moment.')
    p.add_option('-G', '--gui', action='store_true', help="Pop up ASE's GUI.")
    p.add_option('-P',
                 '--python',
                 action='store_true',
                 help="Write Python script.")

    opt, args = p.parse_args()

    if not 1 <= len(args) <= 2:
        p.error("incorrect number of arguments")

    if '@' in args[0]:
        ads, surf = args[0].split('@')
    else:
        ads = None
        surf = args[0]

    if surf[0].isdigit():
        i1 = surf.index('x')
        n = int(surf[:i1])
        i2 = i1 + 1
        while surf[i2].isdigit():
            i2 += 1
        m = int(surf[i1 + 1:i2])
        surf = surf[i2:]
    else:
        n = 1
        m = 1

    if surf[-1].isdigit():
        if surf[1].isdigit():
            face = surf[1:]
            surf = surf[0]
        else:
            face = surf[2:]
            surf = surf[:2]
    else:
        face = None

    Z = atomic_numbers[surf]
    state = reference_states[Z]

    if opt.crystal_structure:
        x = opt.crystal_structure
    else:
        x = state['symmetry']

    if opt.lattice_constant:
        a = opt.lattice_constant
    else:
        a = estimate_lattice_constant(surf, x, opt.c_over_a)

    script = [
        'from ase.lattice.surface import ',
        'vac = %r' % opt.vacuum,
        'a = %r' % a
    ]

    if x == 'fcc':
        if face is None:
            face = '111'
        slab = fcc111(surf, (n, m, opt.layers), a, opt.vacuum)
        script[0] += 'fcc111'
        script += [
            'slab = fcc111(%r, (%d, %d, %d), a, vac)' %
            (surf, n, m, opt.layers)
        ]
        r = a / np.sqrt(2) / 2
    elif x == 'bcc':
        if face is None:
            face = '110'
        if face == '110':
            slab = bcc110(surf, (n, m, opt.layers), a, opt.vacuum)
        elif face == '100':
            slab = bcc100(surf, (n, m, opt.layers), a, opt.vacuum)
        script[0] += 'bcc' + face
        script += [
            'slab = bcc%s(%r, (%d, %d, %d), a, vac)' %
            (face, surf, n, m, opt.layers)
        ]
        r = a * np.sqrt(3) / 4
    elif x == 'hcp':
        if face is None:
            face = '0001'
        if opt.c_over_a is None:
            c = np.sqrt(8 / 3.0) * a
        else:
            c = opt.c_over_a * a
        slab = hcp0001(surf, (n, m, opt.layers), a, c, opt.vacuum)
        script[0] += 'hcp0001'
        script += [
            'c = %r * a' % (c / a),
            'slab = hcp0001(%r, (%d, %d, %d), a, c, vac)' %
            (surf, n, m, opt.layers)
        ]
        r = a / 2
    elif x == 'diamond':
        if face is None:
            face = '111'
        slab = diamond111(surf, (n, m, opt.layers), a, opt.vacuum)
        script[0] += 'diamond111'
        script += [
            'slab = diamond111(%r, (%d, %d, %d), a, vac)' %
            (surf, n, m, opt.layers)
        ]
        r = a * np.sqrt(3) / 8
    else:
        raise NotImplementedError

    magmom = opt.magnetic_moment
    if magmom is None:
        magmom = {'Ni': 0.6, 'Co': 1.2, 'Fe': 2.3}.get(surf, 0.0)
    slab.set_initial_magnetic_moments([magmom] * len(slab))
    if magmom != 0:
        script += [
            'slab.set_initial_magnetic_moments([%r] * len(slab))' % magmom
        ]

    slab.pbc = 1
    script += ['slab.pbc = True']

    name = '%dx%d%s%s' % (n, m, surf, face)

    if ads:
        site = 'ontop'
        if '-' in ads:
            site, ads = ads.split('-')

        name = site + '-' + ads + '@' + name
        symbols = string2symbols(ads)
        nads = len(symbols)
        if nads == 1:
            script[:0] = ['from ase import Atoms']
            script += ['ads = Atoms(%r)' % ads]
            ads = Atoms(ads)
        else:
            script[:0] = ['from ase.data.molecules import molecule']
            script += ['ads = molecule(%r)' % ads]
            ads = molecule(ads)

        add_adsorbate(slab, ads, 0.0, site)

        d = opt.distance
        if d is None:
            d = r + covalent_radii[ads[0].number] / 2

        h = opt.height
        if h is None:
            R = slab.positions
            y = ((R[:-nads] - R[-nads])**2).sum(1).min()**0.5
            h = (d**2 - y**2)**0.5
        else:
            assert opt.distance is None

        slab.positions[-nads:, 2] += h

        script[1] += ', add_adsorbate'
        script += ['add_adsorbate(slab, ads, %r, %r)' % (h, site)]

    if len(args) == 2:
        write(args[1], slab)
        script[1:1] = ['from ase.io import write']
        script += ['write(%r, slab)' % args[1]]
    elif not opt.gui:
        write(name + '.traj', slab)
        script[1:1] = ['from ase.io import write']
        script += ['write(%r, slab)' % (name + '.traj')]

    if opt.gui:
        view(slab)
        script[1:1] = ['from ase.visualize import view']
        script += ['view(slab)']

    if opt.python:
        print('\n'.join(script))
コード例 #4
0
ファイル: adsorb.py プロジェクト: jboes/ase
def build():
    p = OptionParser(usage='%prog  [options] [ads@]surf [output file]',
                     version='%prog 0.1',
                     description='Example ads/surf: fcc-CO@2x2Ru0001')
    p.add_option('-l', '--layers', type='int',
                 default=4,
                 help='Number of layers.')
    p.add_option('-v', '--vacuum', type='float',
                 default=5.0,
                 help='Vacuum.')
    p.add_option('-x', '--crystal-structure',
                 help='Crystal structure.',
                 choices=['sc', 'fcc', 'bcc', 'hcp'])
    p.add_option('-a', '--lattice-constant', type='float',
                 help='Lattice constant in Angstrom.')
    p.add_option('--c-over-a', type='float',
                 help='c/a ratio.')
    p.add_option('--height', type='float',
                 help='Height of adsorbate over surface.')
    p.add_option('--distance', type='float',
                 help='Distance between adsorbate and nearest surface atoms.')
    p.add_option('-M', '--magnetic-moment', type='float', default=0.0,
                 help='Magnetic moment.')
    p.add_option('-G', '--gui', action='store_true',
                 help="Pop up ASE's GUI.")
    p.add_option('-P', '--python', action='store_true',
                 help="Write Python script.")

    opt, args = p.parse_args()

    if not 1 <= len(args) <= 2:
        p.error("incorrect number of arguments")

    if '@' in args[0]:
        ads, surf = args[0].split('@')
    else:
        ads = None
        surf = args[0]

    if surf[0].isdigit():
        i1 = surf.index('x')
        n = int(surf[:i1])
        i2 = i1 + 1
        while surf[i2].isdigit():
            i2 += 1
        m = int(surf[i1 + 1:i2])
        surf = surf[i2:]
    else:
        n = 1
        m = 1

    if surf[-1].isdigit():
        if surf[1].isdigit():
            face = surf[1:]
            surf = surf[0]
        else:
            face = surf[2:]
            surf = surf[:2]
    else:
        face = None

    Z = atomic_numbers[surf]
    state = reference_states[Z]

    if opt.crystal_structure:
        x = opt.crystal_structure
    else:
        x = state['symmetry']
    
    if opt.lattice_constant:
        a = opt.lattice_constant
    else:
        a = estimate_lattice_constant(surf, x, opt.c_over_a)

    script = ['from ase.lattice.surface import ',
              'vac = %r' % opt.vacuum,
              'a = %r' % a]
    
    if x == 'fcc':
        if face is None:
            face = '111'
        slab = fcc111(surf, (n, m, opt.layers), a, opt.vacuum)
        script[0] += 'fcc111'
        script += ['slab = fcc111(%r, (%d, %d, %d), a, vac)' %
                   (surf, n, m, opt.layers)]
        r = a / np.sqrt(2) / 2
    elif x == 'bcc':
        if face is None:
            face = '110'
        if face == '110':
            slab = bcc110(surf, (n, m, opt.layers), a, opt.vacuum)
        elif face == '100':
            slab = bcc100(surf, (n, m, opt.layers), a, opt.vacuum)
        script[0] += 'bcc' + face
        script += ['slab = bcc%s(%r, (%d, %d, %d), a, vac)' %
                   (face, surf, n, m, opt.layers)]
        r = a * np.sqrt(3) / 4
    elif x == 'hcp':
        if face is None:
            face = '0001'
        if opt.c_over_a is None:
            c = np.sqrt(8 / 3.0) * a
        else:
            c = opt.c_over_a * a
        slab = hcp0001(surf, (n, m, opt.layers), a, c, opt.vacuum)
        script[0] += 'hcp0001'
        script += ['c = %r * a' % (c / a),
                   'slab = hcp0001(%r, (%d, %d, %d), a, c, vac)' %
                   (surf, n, m, opt.layers)]
        r = a / 2
    elif x == 'diamond':
        if face is None:
            face = '111'
        slab = diamond111(surf, (n, m, opt.layers), a, opt.vacuum)
        script[0] += 'diamond111'
        script += ['slab = diamond111(%r, (%d, %d, %d), a, vac)' %
                   (surf, n, m, opt.layers)]
        r = a * np.sqrt(3) / 8
    else:
        raise NotImplementedError

    magmom = opt.magnetic_moment
    if magmom is None:
        magmom = {'Ni': 0.6, 'Co': 1.2, 'Fe': 2.3}.get(surf, 0.0)
    slab.set_initial_magnetic_moments([magmom] * len(slab))
    if magmom != 0:
        script += ['slab.set_initial_magnetic_moments([%r] * len(slab))' %
                   magmom]
    
    slab.pbc = 1
    script += ['slab.pbc = True']
    
    name = '%dx%d%s%s' % (n, m, surf, face)

    if ads:
        site = 'ontop'
        if '-' in ads:
            site, ads = ads.split('-')

        name = site + '-' + ads + '@' + name
        symbols = string2symbols(ads)
        nads = len(symbols)
        if nads == 1:
            script[:0] = ['from ase import Atoms']
            script += ['ads = Atoms(%r)' % ads]
            ads = Atoms(ads)
        else:
            script[:0] = ['from ase.structure import molecule']
            script += ['ads = molecule(%r)' % ads]
            ads = molecule(ads)

        add_adsorbate(slab, ads, 0.0, site)

        d = opt.distance
        if d is None:
            d = r + covalent_radii[ads[0].number] / 2
        
        h = opt.height
        if h is None:
            R = slab.positions
            y = ((R[:-nads] - R[-nads])**2).sum(1).min()**0.5
            h = (d**2 - y**2)**0.5
        else:
            assert opt.distance is None
        
        slab.positions[-nads:, 2] += h

        script[1] += ', add_adsorbate'
        script += ['add_adsorbate(slab, ads, %r, %r)' % (h, site)]
        
    if len(args) == 2:
        write(args[1], slab)
        script[1:1] = ['from ase.io import write']
        script += ['write(%r, slab)' % args[1]]
    elif not opt.gui:
        write(name + '.traj', slab)
        script[1:1] = ['from ase.io import write']
        script += ['write(%r, slab)' % (name + '.traj')]
        
    if opt.gui:
        view(slab)
        script[1:1] = ['from ase.visualize import view']
        script += ['view(slab)']

    if opt.python:
        print('\n'.join(script))
コード例 #5
0
ファイル: initsim.py プロジェクト: patilanchal/lennyffs
def initlatticepositions(params, nlayers):
    """
    Return nlayers of positions according to lattice type/plane and
    shift positions so that no atoms are on the edges of the box.
    """

    lxsurf = params['lxsurf']
    lysurf = params['lysurf']
    alat = params['alat']

    if params['surftype'] == 'fcc':

        if params['plane'] == '111':
            surf = ase.fcc111('O',
                              a=alat,
                              size=(lxsurf, lysurf, nlayers),
                              orthogonal=True)
            positions = surf.positions
            positions[:, 0] = positions[:, 0] + (alat / 2.0**0.5) / 4.0
            positions[:, 1] = (positions[:, 1] + (1.0 / 2.0) * (3.0**0.5) *
                               (alat / 2.0**0.5) / 4.0)

        elif params['plane'] == '100':
            surf = ase.fcc100('O', a=alat, size=(lxsurf, lysurf, nlayers))
            positions = surf.positions
            positions[:, 0] = positions[:, 0] + (alat / 2.0**0.5) / 4.0
            positions[:, 1] = positions[:, 1] + (alat / 2.0**0.5) / 4.0

        elif params['plane'] == '110':
            surf = ase.fcc110('O', a=alat, size=(lxsurf, lysurf, nlayers))
            positions = surf.positions
            positions[:, 0] = positions[:, 0] + alat / 4.0
            positions[:, 1] = positions[:, 1] + (alat / 2.0**0.5) / 4.0

    elif params['surftype'] == 'bcc':

        if params['plane'] == '100':
            surf = ase.bcc100('O', a=alat, size=(lxsurf, lysurf, nlayers))
            positions = surf.positions
            positions[:, 0] = positions[:, 0] + alat / 2.0
            positions[:, 1] = positions[:, 1] + alat / 2.0

    elif params['surftype'] == 'hcp':

        clat = params['clat']
        if params['plane'] == '0001':
            surf = ase.hcp0001('O',
                               a=alat,
                               c=clat,
                               size=(lxsurf, lysurf, nlayers),
                               orthogonal=True)
            positions = surf.positions
            positions[:, 0] = positions[:, 0] + alat / 4.0
            positions[:,
                      1] = positions[:,
                                     1] + (1.0 / 2.0) * (3.0**0.5) * alat / 4.0

        elif params['plane'] == '1010':
            surf = ase.hcp10m10('O',
                                a=alat,
                                c=clat,
                                size=(lxsurf, lysurf, nlayers))
            positions = surf.positions
            positions[:, 0] = positions[:, 0] + alat / 4.0
            positions[:, 1] = positions[:, 1] + clat / 4.0

    return positions