Exemplo n.º 1
0
def get_atoms_adsorbate():
    # We need the relaxed slab here!
    slab = Atoms([
        Atom('Cu',
             [-1.028468159509163, -0.432387156877267, -0.202086055768265]),
        Atom('Cu', [0.333333333333333, 0.333333333333333, -2.146500000000000]),
        Atom('Cu',
             [1.671531840490805, -0.432387156877287, -0.202086055768242]),
        Atom('Cu', [3.033333333333334, 0.333333333333333, -2.146500000000000]),
        Atom('Cu',
             [4.371531840490810, -0.432387156877236, -0.202086055768261]),
        Atom('Cu', [5.733333333333333, 0.333333333333333, -2.146500000000000]),
        Atom('Cu',
             [7.071531840490944, -0.432387156877258, -0.202086055768294]),
        Atom('Cu', [8.433333333333335, 0.333333333333333, -2.146500000000000]),
        Atom('Cu', [0.321531840490810, 1.905881433340708, -0.202086055768213]),
        Atom('Cu', [1.683333333333333, 2.671601923551318, -2.146500000000000]),
        Atom('Cu', [3.021531840490771, 1.905881433340728, -0.202086055768250]),
        Atom('Cu', [4.383333333333334, 2.671601923551318, -2.146500000000000]),
        Atom('Cu', [5.721531840490857, 1.905881433340735, -0.202086055768267]),
        Atom('Cu', [7.083333333333333, 2.671601923551318, -2.146500000000000]),
        Atom('Cu', [8.421531840490820, 1.905881433340739, -0.202086055768265]),
        Atom('Cu', [9.783333333333335, 2.671601923551318, -2.146500000000000]),
        Atom('Cu', [1.671531840490742, 4.244150023558601, -0.202086055768165]),
        Atom('Cu', [3.033333333333334, 5.009870513769302, -2.146500000000000]),
        Atom('Cu', [4.371531840490840, 4.244150023558694, -0.202086055768265]),
        Atom('Cu', [5.733333333333333, 5.009870513769302, -2.146500000000000]),
        Atom('Cu', [7.071531840490880, 4.244150023558786, -0.202086055768352]),
        Atom('Cu', [8.433333333333335, 5.009870513769302, -2.146500000000000]),
        Atom('Cu', [9.771531840491031, 4.244150023558828, -0.202086055768371]),
        Atom('Cu',
             [11.133333333333335, 5.009870513769302, -2.146500000000000]),
        Atom('Cu', [3.021531840490714, 6.582418613776583, -0.202086055768197]),
        Atom('Cu', [4.383333333333334, 7.348139103987287, -2.146500000000000]),
        Atom('Cu', [5.721531840490814, 6.582418613776629, -0.202086055768203]),
        Atom('Cu', [7.083333333333333, 7.348139103987287, -2.146500000000000]),
        Atom('Cu', [8.421531840490985, 6.582418613776876, -0.202086055768357]),
        Atom('Cu', [9.783333333333335, 7.348139103987287, -2.146500000000000]),
        Atom('Cu',
             [11.121531840490929, 6.582418613776676, -0.202086055768221]),
        Atom('Cu',
             [12.483333333333334, 7.348139103987287, -2.146500000000000]),
    ])
    mask = [a.position[2] < -1 for a in slab]
    slab.set_constraint(FixAtoms(mask=mask))

    a = 2.70
    c = 1.59 * a
    h = 1.85
    d = 1.10
    x = slab.positions[0, 2] / (c / 2) * 100

    molecule = Atoms('2N', positions=[(0., 0., h), (0., 0., h + d)])
    molecule.set_calculator(EMT())
    slab.extend(molecule)
    return slab
Exemplo n.º 2
0
from math import sqrt
from ase_ext import Atoms
from ase_ext.constraints import StrainFilter
from ase_ext.optimize.mdmin import MDMin
from ase_ext.io import PickleTrajectory
try:
    from asap3 import EMT
except ImportError:
    pass
else:
    a = 3.6
    b = a / 2
    cu = Atoms('Cu', cell=[(0, b, b), (b, 0, b), (b, b, 0)], pbc=1) * (6, 6, 6)

    cu.set_calculator(EMT())
    f = StrainFilter(cu, [1, 1, 1, 0, 0, 0])
    opt = MDMin(f, dt=0.01)
    t = PickleTrajectory('Cu.traj', 'w', cu)
    opt.attach(t)
    opt.run(0.001)

    # HCP:
    from ase_ext.lattice.surface import hcp0001
    cu = hcp0001('Cu', (1, 1, 2), a=a / sqrt(2))
    cu.cell[1, 0] += 0.05
    cu *= (6, 6, 3)

    cu.set_calculator(EMT())
    f = StrainFilter(cu)
    opt = MDMin(f, dt=0.01)
    t = PickleTrajectory('Cu.traj', 'w', cu)
Exemplo n.º 3
0
d = 1.14
co = Atoms('CO', positions=[(0, 0, 0), (0, 0, d)],
              pbc=True)
co.center(vacuum=5.)

calc = Vasp(
            xc = 'PBE',
            prec = 'Low',
            algo = 'Fast',
            ismear= 0,
            sigma = 1.,
            lwave = False,
            lcharg = False)

co.set_calculator(calc)
en = co.get_potential_energy()
assert abs(en + 14.918933) < 1e-4

# Secondly, check that restart from the previously created VASP output works

calc2 = Vasp(restart=True)
co2 = calc2.get_atoms()

# Need tolerance of 1e-14 because VASP itself changes coordinates
# slightly between reading POSCAR and writing CONTCAR even if no ionic
# steps are made.
assert array_almost_equal(co.positions, co2.positions, 1e-14)

assert en - co2.get_potential_energy() == 0.
assert array_almost_equal(calc.get_stress(co), calc2.get_stress(co2))
Exemplo n.º 4
0
    print("No Scientific python found. Check your PYTHONPATH")
    raise NotAvailable('ScientificPython version 2.8 or greater is required')

if not (os.system('which dacapo.run') == 0):
    print(
        "No Dacapo Fortran executable (dacapo.run) found. Check your path settings."
    )
    raise NotAvailable(
        'dacapo.run is not installed on this machine or not in the path')

# Now Scientific 2.8 and dacapo.run should both be available

from ase_ext import Atoms, Atom
from ase_ext.calculators.jacapo import Jacapo

atoms = Atoms([Atom('H', [0, 0, 0])], cell=(2, 2, 2))

calc = Jacapo('Jacapo-test.nc',
              pw=200,
              nbands=2,
              kpts=(1, 1, 1),
              spinpol=False,
              dipole=False,
              symmetry=False,
              ft=0.01)

atoms.set_calculator(calc)

print(atoms.get_potential_energy())
os.system('rm -f Jacapo-test.nc Jacapo-test.txt')
Exemplo n.º 5
0
def read_aims_output(filename, index=-1):
    """  Import FHI-aims output files with all data available, i.e. relaxations, 
    MD information, force information etc etc etc. """
    from ase_ext import Atoms, Atom
    from ase_ext.calculators.singlepoint import SinglePointCalculator
    from ase_ext.units import Ang, fs
    molecular_dynamics = False
    fd = open(filename, 'r')
    cell = []
    images = []
    n_periodic = -1
    f = None
    pbc = False
    found_aims_calculator = False
    v_unit = Ang / (1000.0 * fs)
    while True:
        line = fd.readline()
        if not line:
            break
        if "List of parameters used to initialize the calculator:" in line:
            fd.readline()
            calc = read_aims_calculator(fd)
            calc.out = filename
            found_aims_calculator = True
        if "Number of atoms" in line:
            inp = line.split()
            n_atoms = int(inp[5])
        if "| Unit cell:" in line:
            if not pbc:
                pbc = True
                for i in range(3):
                    inp = fd.readline().split()
                    cell.append([inp[1], inp[2], inp[3]])
        if "Atomic structure:" in line and not molecular_dynamics:
            fd.readline()
            atoms = Atoms()
            for i in range(n_atoms):
                inp = fd.readline().split()
                atoms.append(Atom(inp[3], (inp[4], inp[5], inp[6])))
        if "Complete information for previous time-step:" in line:
            molecular_dynamics = True
        if "Updated atomic structure:" in line and not molecular_dynamics:
            fd.readline()
            atoms = Atoms()
            velocities = []
            for i in range(n_atoms):
                inp = fd.readline().split()
                atoms.append(Atom(inp[4], (inp[1], inp[2], inp[3])))
                if molecular_dynamics:
                    inp = fd.readline().split()
        if "Atomic structure (and velocities)" in line:
            fd.readline()
            atoms = Atoms()
            velocities = []
            for i in range(n_atoms):
                inp = fd.readline().split()
                atoms.append(Atom(inp[4], (inp[1], inp[2], inp[3])))
                inp = fd.readline().split()
                velocities += [[
                    float(inp[1]) * v_unit,
                    float(inp[2]) * v_unit,
                    float(inp[3]) * v_unit
                ]]
            atoms.set_velocities(velocities)
            images.append(atoms)
        if "Total atomic forces" in line:
            f = []
            for i in range(n_atoms):
                inp = fd.readline().split()
                f.append([float(inp[2]), float(inp[3]), float(inp[4])])
            if not found_aims_calculator:
                e = images[-1].get_potential_energy()
                images[-1].set_calculator(
                    SinglePointCalculator(e, f, None, None, atoms))
            e = None
            f = None
        if "Total energy corrected" in line:
            e = float(line.split()[5])
            if pbc:
                atoms.set_cell(cell)
                atoms.pbc = True
            if not found_aims_calculator:
                atoms.set_calculator(
                    SinglePointCalculator(e, None, None, None, atoms))
            if not molecular_dynamics:
                images.append(atoms)
            e = None
            if found_aims_calculator:
                calc.set_results(images[-1])
                images[-1].set_calculator(calc)
    fd.close()
    if molecular_dynamics:
        images = images[1:]

    # return requested images, code borrowed from ase_ext.io/trajectory.py
    if isinstance(index, int):
        return images[index]
    else:
        step = index.step or 1
        if step > 0:
            start = index.start or 0
            if start < 0:
                start += len(images)
            stop = index.stop or len(images)
            if stop < 0:
                stop += len(images)
        else:
            if index.start is None:
                start = len(images) - 1
            else:
                start = index.start
                if start < 0:
                    start += len(images)
            if index.stop is None:
                stop = -1
            else:
                stop = index.stop
                if stop < 0:
                    stop += len(images)
        return [images[i] for i in range(start, stop, step)]
Exemplo n.º 6
0
from ase_ext import Atom, Atoms
from gpaw import GPAW

a = 4.0
b = a / 2**.5
L = 7.0
al = Atoms([Atom('Al')], cell=(b, b, L), pbc=True)
calc = GPAW(kpts=(4, 4, 1))
al.set_calculator(calc)
al.get_potential_energy()
calc.write('Al100.gpw', 'all')
Exemplo n.º 7
0
from ase_ext import Atoms
from ase_ext.calculators.emt import EMT
from ase_ext.md import VelocityVerlet
from ase_ext.io import PickleTrajectory

a = 3.6
b = a / 2
fcc = Atoms('Cu',
            positions=[(0, 0, 0)],
            cell=[(0, b, b), (b, 0, b), (b, b, 0)],
            pbc=1)
fcc *= (2, 1, 1)
fcc.set_calculator(EMT())
fcc.set_momenta([(0.9, 0.0, 0.0), (-0.9, 0, 0)])
md = VelocityVerlet(fcc, dt=0.1)


def f():
    print(fcc.get_potential_energy(), fcc.get_total_energy())


md.attach(f)
md.attach(PickleTrajectory('Cu2.traj', 'w', fcc).write, interval=3)
md.run(steps=20)
fcc2 = PickleTrajectory('Cu2.traj', 'r')[-1]
Exemplo n.º 8
0
def read_vasp_out(filename='OUTCAR', index=-1):
    """Import OUTCAR type file.

    Reads unitcell, atom positions, energies, and forces from the OUTCAR file.

    - does not (yet) read any constraints
    """
    import os
    import numpy as np
    from ase_ext.calculators.singlepoint import SinglePointCalculator
    from ase_ext import Atoms, Atom

    if isinstance(filename, str):
        f = open(filename)
    else:  # Assume it's a file-like object
        f = filename
    data = f.readlines()
    natoms = 0
    images = []
    atoms = Atoms(pbc=True)
    energy = 0
    species = []
    species_num = []
    symbols = []
    for n, line in enumerate(data):
        if 'POSCAR:' in line:
            temp = line.split()
            species = temp[1:]
        if 'ions per type' in line:
            temp = line.split()
            for ispecies in range(len(species)):
                species_num += [int(temp[ispecies + 4])]
                natoms += species_num[-1]
                for iatom in range(species_num[-1]):
                    symbols += [species[ispecies]]
        if 'direct lattice vectors' in line:
            cell = []
            for i in range(3):
                temp = data[n + 1 + i].split()
                cell += [[float(temp[0]), float(temp[1]), float(temp[2])]]
            atoms.set_cell(cell)
        if 'FREE ENERGIE OF THE ION-ELECTRON SYSTEM' in line:
            energy = float(data[n + 2].split()[4])
        if 'POSITION          ' in line:
            forces = []
            for iatom in range(natoms):
                temp = data[n + 2 + iatom].split()
                atoms += Atom(symbols[iatom],
                              [float(temp[0]),
                               float(temp[1]),
                               float(temp[2])])
                forces += [[float(temp[3]), float(temp[4]), float(temp[5])]]
                atoms.set_calculator(
                    SinglePointCalculator(energy, forces, None, None, atoms))
            images += [atoms]
            atoms = Atoms(pbc=True)

    # return requested images, code borrowed from ase_ext.io/trajectory.py
    if isinstance(index, int):
        return images[index]
    else:
        step = index.step or 1
        if step > 0:
            start = index.start or 0
            if start < 0:
                start += len(images)
            stop = index.stop or len(images)
            if stop < 0:
                stop += len(images)
        else:
            if index.start is None:
                start = len(images) - 1
            else:
                start = index.start
                if start < 0:
                    start += len(images)
            if index.stop is None:
                stop = -1
            else:
                stop = index.stop
                if stop < 0:
                    stop += len(images)
        return [images[i] for i in range(start, stop, step)]
Exemplo n.º 9
0
import numpy as np
from math import pi, sqrt
from ase_ext import Atoms
from ase_ext.calculators.lj import LennardJones
from ase_ext.optimize.basin import BasinHopping
from ase_ext.io import PickleTrajectory, read
from ase_ext.units import kB

N = 7
R = N**(1. / 3.)
pos = np.random.uniform(-R, R, (N, 3))
s = Atoms('He' + str(N), positions=pos)
s.set_calculator(LennardJones())

ftraj = 'lowest.traj'
traj = PickleTrajectory(ftraj, 'w', s)
bh = BasinHopping(s, temperature=100 * kB, dr=0.5, optimizer_logfile=None)
bh.attach(traj)
bh.run(10)

Emin, smin = bh.get_minimum()

# recalc energy
smin.set_calculator(LennardJones())
E = smin.get_potential_energy()
assert abs(E - Emin) < 1e-15
traj.close()
smim = read(ftraj)
E = smin.get_potential_energy()
assert abs(E - Emin) < 1e-15