Пример #1
0
def get_atoms():
    atoms = Atoms([
        Atom('Pd', [5.078689759346383, 5.410678028467162, 4.000000000000000]),
        Atom('Pd', [7.522055777772603, 4.000000000000000, 4.000000000000000]),
        Atom('Pd', [7.522055777772603, 6.821356056934325, 4.000000000000000]),
        Atom('Pd', [6.707600438297196, 5.410678028467162, 6.303627574066606]),
        Atom('N', [4.807604264052752, 5.728625577716107, 5.919407072553396]),
        Atom('H', [4.000000000000000, 5.965167390141987, 6.490469524180266]),
    ])

    constraint = FixAtoms(mask=[a.symbol == 'Pd' for a in atoms])
    atoms.set_constraint(constraint)
    atoms.center(vacuum=4.0)
    atoms.set_pbc(False)
    return atoms
Пример #2
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')
Пример #3
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)]
Пример #4
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')
Пример #5
0
from ase_ext import Atom, Atoms
from ase_ext.calculators.lj import LennardJones
from ase_ext.constraints import FixBondLength

dimer = Atoms([Atom('X',
                    (0, 0, 0)), Atom('X', (0, 0, 1))],
              calculator=LennardJones(),
              constraint=FixBondLength(0, 1))
print(dimer.get_forces())
print(dimer.positions)
dimer.positions[:] += 0.1
print(dimer.positions)
dimer.positions[:, 2] += 5.1
print(dimer.positions)
dimer.positions[:] = [(1, 2, 3), (4, 5, 6)]
print(dimer.positions)
dimer.set_positions([(1, 2, 3), (4, 5, 6.2)])
print(dimer.positions)
Пример #6
0
import numpy as np
from ase_ext import Atoms, Atom

a = Atoms([Atom('Cu')])
a.positions[:] += 1.0
print(a.get_positions(), a.positions)
a = a + a
a += a
a.append(Atom('C'))
a += Atoms([])
a += Atom('H', magmom=1)
print(a.get_initial_magnetic_moments())
print(a[0].number)
print(a[[0, 1]].get_atomic_numbers())
print(a[np.array([1, 1, 0, 0, 1], bool)].get_atomic_numbers())
print(a[::2].get_atomic_numbers())
print(a.get_chemical_symbols())
del a[2]
print(a.get_chemical_symbols())
del a[-2:]
print(a.get_chemical_symbols())
Пример #7
0
from math import pi, sqrt
from ase_ext import Atoms, Atom

d = 1.14
a = Atoms([Atom('C', (0, 0, 0)), Atom('O', (d, 0, 0))])
a.rotate_euler(phi=pi / 2, theta=pi / 4, psi=pi)
for p in a[0].position:
    assert p == 0.0
assert abs(a[1].position[0]) < 1e-15
d2 = d / sqrt(2)
assert abs(a[1].position[1] - d2) < 1e-15
assert abs(a[1].position[2] - d2) < 1e-15
Пример #8
0
slab.set_pbc((1, 1, 0))
slab.set_calculator(EMT())
Z = slab.get_positions()[:, 2]
indices = [i for i, z in enumerate(Z) if z < Z.mean()]
constraint = FixAtoms(indices=indices)
slab.set_constraint(constraint)
dyn = QuasiNewton(slab)
dyn.run(fmax=0.05)
Z = slab.get_positions()[:, 2]
print(Z[0] - Z[1])
print(Z[1] - Z[2])
print(Z[2] - Z[3])

b = 1.2
h = 2.0
slab += Atom('C', (d, 2 * y / 3, h))
slab += Atom('O', (3 * d / 2, y / 3, h))
traj = PickleTrajectory('initial.traj', 'w', slab)
dyn = QuasiNewton(slab)
dyn.attach(traj.write)
dyn.run(fmax=0.05)
#view(slab)
# Make band:
images = [slab.copy() for i in range(6)]
neb = NEB(images, climb=True)

# Set constraints and calculator:
for image in images:
    image.set_calculator(EMT())
    image.set_constraint(constraint)
Пример #9
0
from ase_ext import Atom, Atoms

m = Atoms('H2')
a = m[0]
b = Atom('H')
for c in [a, b]:
    assert c.x == 0
    c.z = 24.0
    assert c.position[2] == 24.0
    assert c.symbol == 'H'
    c.number = 92
    assert c.symbol == 'U'
    c.symbol = 'Fe'
    assert c.number == 26
    c.tag = 42
    assert c.tag == 42
    c.momentum = (1,2,3)
assert m[0].tag == 42
momenta = m.get_momenta()
m = Atoms('LiH')
for a in m:
    print(a.symbol)
for a in m:  
    if a.symbol == 'H':
        a.z = 0.75
assert m.get_distance(0, 1) == 0.75
a = m.pop()
m += a
del m[:1]
print(m)
Пример #10
0
from ase_ext.constraints import FixAtoms
from ase_ext.vibrations import Vibrations
from ase_ext.calculators.emt import EMT
from ase_ext.optimize import QuasiNewton

# Distance between Cu atoms on a (100) surface:
d = 3.6 / sqrt(2)
initial = Atoms('Cu',
                positions=[(0, 0, 0)],
                cell=(d, d, 1.0),
                pbc=(True, True, False))
initial *= (2, 2, 1)  # 2x2 (100) surface-cell

# Approximate height of Ag atom on Cu(100) surfece:
h0 = 2.0
initial += Atom('Ag', (d / 2, d / 2, h0))

if 0:
    view(initial)

# Make band:
images = [initial.copy() for i in range(6)]
neb = NEB(images, climb=True)

# Set constraints and calculator:
constraint = FixAtoms(list(range(len(initial) - 1)))
for image in images:
    image.set_calculator(EMT())
    image.set_constraint(constraint)

# Displace last image:
Пример #11
0
from ase_ext import Atoms, Atom, view
from gpaw import GPAW

logo = """\
 H   HH HHH
H H H   H
HHH  H  HH
H H   H H
H H HH  HHH"""

d = 0.8
atoms = Atoms()
for y, line in enumerate(logo.split('\n')):
    for x, c in enumerate(line):
        if c == 'H':
            atoms.append(Atom('H', [d * x, -d * y, 0]))
atoms.center(vacuum=2.0)
view(atoms)

if 0:
    calc = GPAW(nbands=30)
    atoms.set_calculator(calc)
    atoms.get_potential_energy()
    calc.write('ase-logo.gpw')
else:
    calc = GPAW('ase-logo.gpw', txt=None)

density = calc.get_pseudo_density()
image = density[..., density.shape[2] // 2]

if 1: # scale colors to wiki background / foreground
Пример #12
0
slab.set_pbc((1, 1, 0))
slab.set_calculator(EMT())
Z = slab.get_positions()[:, 2]
indices = [i for i, z in enumerate(Z) if z < Z.mean()]
constraint = FixAtoms(indices=indices)
slab.set_constraint(constraint)
dyn = QuasiNewton(slab)
dyn.run(fmax=0.05)
Z = slab.get_positions()[:, 2]
print(Z[0] - Z[1])
print(Z[1] - Z[2])
print(Z[2] - Z[3])

b = 1.2
h = 1.5
slab += Atom('C', (d / 2, -b / 2, h))
slab += Atom('O', (d / 2, +b / 2, h))
s = slab.copy()
dyn = QuasiNewton(slab)
dyn.run(fmax=0.05)
#view(slab)

# Make band:
images = [slab]
for i in range(6):
    image = slab.copy()
    image.set_constraint(constraint)
    image.set_calculator(EMT())
    images.append(image)
image[-2].position = image[-1].position
image[-1].x = d
Пример #13
0
initial.set_pbc((1, 1, 0))
initial.set_calculator(EMT())
Z = initial.get_positions()[:, 2]
indices = [i for i, z in enumerate(Z) if z < Z.mean()]
constraint = FixAtoms(indices=indices)
initial.set_constraint(constraint)
dyn = Optimizer(initial)
dyn.run(fmax=0.05)
Z = initial.get_positions()[:, 2]
print(Z[0] - Z[1])
print(Z[1] - Z[2])
print(Z[2] - Z[3])

b = 1.2
h = 1.5
initial += Atom('C', (d / 2, -b / 2, h))
initial += Atom('O', (d / 2, +b / 2, h))
s = initial.copy()
dyn = Optimizer(initial)
dyn.run(fmax=0.05)
#view(initial)

# create final
final = initial.copy()
final.set_calculator(EMT())
final.set_constraint(constraint)
final[-2].position = final[-1].position
final[-1].x = d
final[-1].y = d / sqrt(3)
dyn = Optimizer(final)
dyn.run(fmax=0.1)
Пример #14
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)]
Пример #15
0
h2 = d * sqrt(2.0 / 3)
initial = Atoms(
    symbols='Pt',
    positions=[
        (0, 0, 0)
    ],  #(1.37,0.79,2.24),(2.74,1.58,4.48),(0,0,6.72),(1.37,0.79,8.96),(2.74,1.58,11.2)],
    cell=([(d, 0, 0), (d / 2, h1, 0), (d / 2, h1 / 3, -h2)]),
    pbc=(True, True, True))
initial *= (7, 8, 6)  # 5x5 (100) surface-cell
cell = initial.get_cell()
cell[2] = (0, 0, 22)
initial.set_cell(cell)
#initial.set_pbc((True,True,False))
# Approximate height of Ag atom on Cu(100) surfece:
h0 = 2.2373
initial += Atom('Pt', (10.96, 11.074, h0))
initial += Atom('Pt', (13.7, 11.074, h0))
initial += Atom('Pt', (9.59, 8.701, h0))
initial += Atom('Pt', (12.33, 8.701, h0))
initial += Atom('Pt', (15.07, 8.701, h0))
initial += Atom('Pt', (10.96, 6.328, h0))
initial += Atom('Pt', (13.7, 6.328, h0))

if 0:
    view(initial)

# Make band:
images = [initial.copy() for i in range(7)]
neb = NEB(images)

# Set constraints and calculator:
Пример #16
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