コード例 #1
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
コード例 #2
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
コード例 #3
0
ファイル: completeexample.py プロジェクト: aglgit/amp
def test():

    # Generate atomic system to create test data.
    atoms = fcc110('Cu', (2, 2, 2), vacuum=7.)
    adsorbate = Atoms([
        Atom('H', atoms[7].position + (0., 0., 2.)),
        Atom('H', atoms[7].position + (0., 0., 5.))
    ])
    atoms.extend(adsorbate)
    atoms.set_constraint(FixAtoms(indices=[0, 2]))
    calc = EMT()  # cheap calculator
    atoms.set_calculator(calc)

    # Run some molecular dynamics to generate data.
    trajectory = io.Trajectory('data.traj', 'w', atoms=atoms)
    MaxwellBoltzmannDistribution(atoms, temp=300. * units.kB)
    dynamics = VelocityVerlet(atoms, dt=1. * units.fs)
    dynamics.attach(trajectory)
    for step in range(50):
        dynamics.run(5)
    trajectory.close()

    # Train the calculator.
    train_images, test_images = randomize_images('data.traj')

    calc = Amp(descriptor=Behler(), regression=NeuralNetwork())
    calc.train(train_images, energy_goal=0.001, force_goal=None)

    # Plot and test the predictions.
    import matplotlib
    matplotlib.use('Agg')
    from matplotlib import pyplot

    fig, ax = pyplot.subplots()

    for image in train_images:
        actual_energy = image.get_potential_energy()
        predicted_energy = calc.get_potential_energy(image)
        ax.plot(actual_energy, predicted_energy, 'b.')

    for image in test_images:
        actual_energy = image.get_potential_energy()
        predicted_energy = calc.get_potential_energy(image)
        ax.plot(actual_energy, predicted_energy, 'r.')

    ax.set_xlabel('Actual energy, eV')
    ax.set_ylabel('Amp energy, eV')

    fig.savefig('parityplot.png')
def test():

    # Generate atomic system to create test data.
    atoms = fcc110('Cu', (2, 2, 2), vacuum=7.)
    adsorbate = Atoms([Atom('H', atoms[7].position + (0., 0., 2.)),
                       Atom('H', atoms[7].position + (0., 0., 5.))])
    atoms.extend(adsorbate)
    atoms.set_constraint(FixAtoms(indices=[0, 2]))
    calc = EMT()  # cheap calculator
    atoms.set_calculator(calc)

    # Run some molecular dynamics to generate data.
    trajectory = io.Trajectory('data.traj', 'w', atoms=atoms)
    MaxwellBoltzmannDistribution(atoms, temp=300. * units.kB)
    dynamics = VelocityVerlet(atoms, dt=1. * units.fs)
    dynamics.attach(trajectory)
    for step in range(50):
        dynamics.run(5)
    trajectory.close()

    # Train the calculator.
    train_images, test_images = randomize_images('data.traj')

    calc = Amp(descriptor=Behler(),
               regression=NeuralNetwork())
    calc.train(train_images, energy_goal=0.001, force_goal=None)

    # Plot and test the predictions.
    import matplotlib
    matplotlib.use('Agg')
    from matplotlib import pyplot

    fig, ax = pyplot.subplots()

    for image in train_images:
        actual_energy = image.get_potential_energy()
        predicted_energy = calc.get_potential_energy(image)
        ax.plot(actual_energy, predicted_energy, 'b.')

    for image in test_images:
        actual_energy = image.get_potential_energy()
        predicted_energy = calc.get_potential_energy(image)
        ax.plot(actual_energy, predicted_energy, 'r.')

    ax.set_xlabel('Actual energy, eV')
    ax.set_ylabel('Amp energy, eV')

    fig.savefig('parityplot.png')
def generate_data(count):
    """Generates test or training data with a simple MD simulation."""
    atoms = fcc110('Pt', (2, 2, 1), vacuum=7.)
    adsorbate = Atoms([Atom('Cu', atoms[3].position + (0., 0., 2.5)),
                       Atom('Cu', atoms[3].position + (0., 0., 5.))])
    atoms.extend(adsorbate)
    atoms.set_constraint(FixAtoms(indices=[0, 2]))
    atoms.set_calculator(EMT())
    MaxwellBoltzmannDistribution(atoms, 300. * units.kB)
    dyn = VelocityVerlet(atoms, dt=1. * units.fs)
    newatoms = atoms.copy()
    newatoms.set_calculator(EMT())
    newatoms.get_potential_energy()
    images = [newatoms]
    for step in range(count - 1):
        dyn.run(50)
        newatoms = atoms.copy()
        newatoms.set_calculator(EMT())
        newatoms.get_potential_energy()
        images.append(newatoms)
    return images
コード例 #6
0
def generate_data(count):
    """Generates test or training data with a simple MD simulation."""
    atoms = fcc110('Pt', (2, 2, 2), vacuum=7.)
    adsorbate = Atoms([
        Atom('Cu', atoms[7].position + (0., 0., 2.5)),
        Atom('Cu', atoms[7].position + (0., 0., 5.))
    ])
    atoms.extend(adsorbate)
    atoms.set_constraint(FixAtoms(indices=[0, 2]))
    atoms.set_calculator(EMT())
    MaxwellBoltzmannDistribution(atoms, 300. * units.kB)
    dyn = VelocityVerlet(atoms, dt=1. * units.fs)
    newatoms = atoms.copy()
    newatoms.set_calculator(EMT())
    newatoms.get_potential_energy(apply_constraint=False)
    images = [newatoms]
    for step in range(count):
        dyn.run(5)
        newatoms = atoms.copy()
        newatoms.set_calculator(EMT())
        newatoms.get_potential_energy(apply_constraint=False)
        images.append(newatoms)
    return images
コード例 #7
0
ファイル: script-174.py プロジェクト: Pyroseza/dillinger
from vasp import Vasp
from ase.lattice.surface import fcc110
from ase.io import write
from ase.constraints import FixAtoms
atoms = fcc110('Au', size=(2, 1, 6), vacuum=10.0)
constraint = FixAtoms(mask=[atom.tag > 2 for atom in atoms])
atoms.set_constraint(constraint)
write('images/Au-110.png',
      atoms.repeat((2, 2, 1)),
      rotation='-90x',
      show_unit_cell=2)
print Vasp('surfaces/Au-110',
           xc='PBE',
           kpts=[6, 6, 1],
           encut=350,
           ibrion=2,
           isif=2,
           nsw=10,
           atoms=atoms).potential_energy
コード例 #8
0
ファイル: minimahop.py プロジェクト: PHOTOX/fuase
from ase import Atoms, Atom
from ase.lattice.surface import fcc110
from ase.optimize.minimahopping import MinimaHopping
from ase.calculators.emt import EMT
from ase.constraints import FixAtoms, Hookean

# Make the Pt 110 slab.
atoms = fcc110('Pt', (2, 2, 2), vacuum=7.)

# Add the Cu2 adsorbate.
adsorbate = Atoms([Atom('Cu', atoms[7].position + (0., 0., 2.5)),
                   Atom('Cu', atoms[7].position + (0., 0., 5.0))])
atoms.extend(adsorbate)

# Constrain the surface to be fixed and a Hookean constraint between
# the adsorbate atoms.
constraints = [FixAtoms(indices=[atom.index for atom in atoms if
                                 atom.symbol == 'Pt']),
               Hookean(a1=8, a2=9, rt=2.6, k=15.),
               Hookean(a1=8, a2=(0., 0., 1., -15.), k=15.)]
atoms.set_constraint(constraints)

# Set the calculator.
calc = EMT()
atoms.set_calculator(calc)

# Instantiate and run the minima hopping algorithm.
hop = MinimaHopping(atoms,
                    Ediff0=2.5,
                    T0=2000.)
hop(totalsteps=3)
コード例 #9
0
ファイル: script-155.py プロジェクト: alejandrogallo/dft-book
from jasp import *
from ase.lattice.surface import fcc110
from ase.io import write
from ase.constraints import FixAtoms
atoms = fcc110('Au', size=(2, 1, 6), vacuum=10.0)
del atoms[11]  # delete surface row
constraint = FixAtoms(mask=[atom.tag > 2 for atom in atoms])
atoms.set_constraint(constraint)
write('images/Au-110-missing-row.png',
      atoms.repeat((2, 2, 1)),
      rotation='-90x',
      show_unit_cell=2)
with jasp('surfaces/Au-110-missing-row',
          xc='PBE',
          kpts=(6, 6, 1),
          encut=350,
          ibrion=2,
          isif=2,
          nsw=10,
          atoms=atoms) as calc:
    calc.calculate()
コード例 #10
0
ファイル: Cu2_Pt110.py プロジェクト: grhawk/ASE
from ase import Atoms, Atom
from ase.lattice.surface import fcc110
from ase.optimize.minimahopping import MinimaHopping
from ase.calculators.emt import EMT
from ase.constraints import FixAtoms, Hookean
from ase.optimize import BFGS

# Make the Pt 110 slab.
atoms = fcc110('Pt', (2, 2, 2), vacuum=7.)

# Add the Cu2 adsorbate.
adsorbate = Atoms([
    Atom('Cu', atoms[7].position + (0., 0., 2.5)),
    Atom('Cu', atoms[7].position + (0., 0., 5.0))
])
atoms.extend(adsorbate)

# Constrain the surface to be fixed and a Hookean constraint between
# the adsorbate atoms.
constraints = [
    FixAtoms(indices=[atom.index for atom in atoms if atom.symbol == 'Pt']),
    Hookean(a1=8, a2=9, rt=2.6, k=15.),
    Hookean(a1=8, a2=(0., 0., 1., -15.), k=15.),
]
atoms.set_constraint(constraints)

# Set the calculator.
calc = EMT()
atoms.set_calculator(calc)

# Instantiate and run the minima hopping algorithm.
コード例 #11
0
# The vasp path should be set in the shell terminal.

import sys
sys.path.append('/export/zimmerman/paulzim/ase')
from math import sqrt
import os, fnmatch
from ase import Atoms
import io 
from ase.io import read
from subprocess import call
from ase.calculators.vasp import Vasp
from ase.calculators.emt import EMT
from ase.lattice.surface import fcc110, add_adsorbate

slab = fcc110('Cu', size=(3,3,4), vacuum=10)
molecule = Atoms('OHH')
add_adsorbate(slab, molecule, 1.7, 'ontop')

path = os.getcwd()

FH = open('finalForces', 'a')
for file in sorted(os.listdir(path)):
    if fnmatch.fnmatch(file, '*.xyz'):
        fName = file
        slabatoms = read(fName)
        slab.set_positions(slabatoms.get_positions())
#    calc = Vasp(xc='PBE',lreal='Auto',kpts=[1,1,1],ismear=1,sigma=0.2,algo='fast',istart=0,npar=8,encut=300)
#        calc = EMT()
        slab.set_calculator(calc)
        f = slab.get_forces()
コード例 #12
0
# The vasp path should be set in the shell terminal.

import sys
sys.path.append('/export/zimmerman/paulzim/ase')
from math import sqrt
import os, fnmatch
from ase import Atoms
import io
from ase.io import read
from subprocess import call
from ase.calculators.vasp import Vasp
from ase.calculators.emt import EMT
from ase.lattice.surface import fcc110, add_adsorbate

slab = fcc110('Cu', size=(3, 3, 4), vacuum=10)
molecule = Atoms('OHH')
add_adsorbate(slab, molecule, 1.7, 'ontop')

path = os.getcwd()

FH = open('finalForces', 'a')
for file in sorted(os.listdir(path)):
    if fnmatch.fnmatch(file, '*.xyz'):
        fName = file
        slabatoms = read(fName)
        slab.set_positions(slabatoms.get_positions())
        #    calc = Vasp(xc='PBE',lreal='Auto',kpts=[1,1,1],ismear=1,sigma=0.2,algo='fast',istart=0,npar=8,encut=300)
        #        calc = EMT()
        slab.set_calculator(calc)
        f = slab.get_forces()
コード例 #13
0
from ase import Atoms
from ase.lattice import surface
from ase.constraints import FixAtoms
from ase.calculators.vasp import Vasp
from ase.visualize import view
from ase.io import write
from ase.io import read
calc = Vasp(xc='PBE', kpts=(3,3,1), nwrite=1, lwave=False, lcharg=False,lvtot=False
            , encut=400, algo='Fast', ismear=1, sigma=0.1, voskown=1, istart=0, nelm=400, nelmdl=-10, ediff=1e-6, ispin=1
            ,nsw=1000, isif=2, ibrion=2, nfree=2, potim=0.2, ediffg=-0.04
            ,npar=2, lvdw=True, vdw_version=3
            ,lreal='Auto')

# Create a 4X4 surface with 4 layers and 14 Angstrom of vacuum
CONTCAR = read('CONTCAR')
slab = surface.fcc110('Ag', size=(4,4,4), a=4.07,vacuum=20.0)
#slab.positions=CONTCAR.positions
adsorbate = surface.Atoms('N')

surface.add_adsorbate(slab, adsorbate, 1.20, 'longbridge')

slab.center(vacuum=20.0,axis=2)

#freeze all layers below top two layers
mask = [atom.tag > 2 for atom in slab]
slab.set_constraint(FixAtoms(mask=mask))

#write_vasp('POSCAR', slab,  long_format=True, vasp5=True)

view(slab) # View the slab, frozen atoms will be marked with a "X"
コード例 #14
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
コード例 #15
0
    parser.print_help()
    sys.exit()


l=options.lattice
p=options.periods
v=options.vaccuum
e=options.element

atoms = []
if(options.bravais == 'fcc'):
    if(options.hkl == '111'):
        #atoms = fcc111(e, size=p,a=l, vacuum=v, orthogonal=False)
        atoms = fcc111(e, size=p,a=l, vacuum=v, orthogonal=options.ortogonal)
    elif(options.hkl == '110'):
        atoms = fcc110(e, size=p,a=l, vacuum=v)
    elif(options.hkl == '100'):
        atoms = fcc100(e, size=p,a=l, vacuum=v)
elif(options.bravais == 'MoS2'):
    atoms = mx2(formula='MoS2', kind='2H', a=3.18, thickness=3.19, size=(1, 1, 1), vacuum=7.5)
#c=atoms.get_cell()
#c[1][0] += l*math.sqrt(2)*0.5
#atoms.set_cell(c)

#atoms.translate([0.0,0.0,-14.9999999999999982])


if(options.cell != None):
    to_remove = []
    for i, atom in enumerate(atoms):
        r = atom.position.astype(float)