예제 #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
예제 #2
0
def get_atoms():
    atoms = Atoms(symbols='C5H12',
                  pbc=[False, False, False],
                  cell=[
                      [ 16.83752497,   0.        ,   0.        ],
                      [  0.        ,  12.18645905,   0.        ],
                      [  0.        ,   0.        ,  11.83462179]
                  ],
                  positions=[
                      [  5.90380523,   5.65545388,   5.91569796],
                      [  7.15617518,   6.52907738,   5.91569796],
                      [  8.41815022,   5.66384716,   5.92196554],
                      [  9.68108996,   6.52891016,   5.91022362],
                      [ 10.93006206,   5.65545388,   5.91569796],
                      [  5.00000011,   6.30002353,   5.9163716 ],
                      [  5.88571848,   5.0122839 ,   6.82246859],
                      [  5.88625613,   5.01308931,   5.01214155],
                      [  7.14329342,   7.18115393,   6.81640316],
                      [  7.14551332,   7.17200869,   5.00879027],
                      [  8.41609966,   5.00661165,   5.02355167],
                      [  8.41971183,   5.0251482 ,   6.83462168],
                      [  9.69568096,   7.18645894,   6.8078633 ],
                      [  9.68914668,   7.16663649,   5.00000011],
                      [ 10.95518898,   5.02163182,   6.8289018 ],
                      [ 11.83752486,   6.29836826,   5.90274952],
                      [ 10.94464142,   5.00000011,   5.01802495]
                  ])
    return atoms
예제 #3
0
def get_atoms():
    srf = Atoms('Cu64', [(1.2763, 1.2763, 4.0000), (3.8290, 1.2763, 4.0000),
                         (6.3816, 1.2763, 4.0000), (8.9343, 1.2763, 4.0000),
                         (1.2763, 3.8290, 4.0000), (3.8290, 3.8290, 4.0000),
                         (6.3816, 3.8290, 4.0000), (8.9343, 3.8290, 4.0000),
                         (1.2763, 6.3816, 4.0000), (3.8290, 6.3816, 4.0000),
                         (6.3816, 6.3816, 4.0000), (8.9343, 6.3816, 4.0000),
                         (1.2763, 8.9343, 4.0000), (3.8290, 8.9343, 4.0000),
                         (6.3816, 8.9343, 4.0000), (8.9343, 8.9343, 4.0000),
                         (0.0000, 0.0000, 5.8050), (2.5527, 0.0000, 5.8050),
                         (5.1053, 0.0000, 5.8050), (7.6580, 0.0000, 5.8050),
                         (0.0000, 2.5527, 5.8050), (2.5527, 2.5527, 5.8050),
                         (5.1053, 2.5527, 5.8050), (7.6580, 2.5527, 5.8050),
                         (0.0000, 5.1053, 5.8050), (2.5527, 5.1053, 5.8050),
                         (5.1053, 5.1053, 5.8050), (7.6580, 5.1053, 5.8050),
                         (0.0000, 7.6580, 5.8050), (2.5527, 7.6580, 5.8050),
                         (5.1053, 7.6580, 5.8050), (7.6580, 7.6580, 5.8050),
                         (1.2409, 1.2409, 7.6081), (3.7731, 1.2803, 7.6603),
                         (6.3219, 1.3241, 7.6442), (8.8935, 1.2669, 7.6189),
                         (1.2803, 3.7731, 7.6603), (3.8188, 3.8188, 7.5870),
                         (6.3457, 3.8718, 7.6649), (8.9174, 3.8340, 7.5976),
                         (1.3241, 6.3219, 7.6442), (3.8718, 6.3457, 7.6649),
                         (6.3945, 6.3945, 7.6495), (8.9576, 6.3976, 7.6213),
                         (1.2669, 8.8935, 7.6189), (3.8340, 8.9174, 7.5976),
                         (6.3976, 8.9576, 7.6213), (8.9367, 8.9367, 7.6539),
                         (0.0582, 0.0582, 9.4227), (2.5965, -0.2051, 9.4199),
                         (5.1282, 0.0663, 9.4037), (7.6808, -0.0157, 9.4235),
                         (-0.2051, 2.5965, 9.4199), (2.1913, 2.1913, 9.6123),
                         (5.0046, 2.5955, 9.4873), (7.5409, 2.5336, 9.4126),
                         (0.0663, 5.1282, 9.4037), (2.5955, 5.0046, 9.4873),
                         (5.3381, 5.3381, 9.6106), (7.8015, 5.0682, 9.4237),
                         (-0.0157, 7.6808, 9.4235), (2.5336, 7.5409, 9.4126),
                         (5.0682, 7.8015, 9.4237), (7.6155, 7.6155, 9.4317)])
    c2 = Atoms('C2', [(3.2897, 3.2897, 10.6627), (4.2113, 4.2113, 10.6493)])
    srf.extend(c2)
    srf.pbc = (1, 1, 0)
    srf.set_cell([10.2106, 10.2106, 20.6572], scale_atoms=False)

    mask = [a.index < 32 for a in srf]
    c1 = FixedPlane(-1, (1 / np.sqrt(2), 1 / np.sqrt(2), 1))
    c2 = FixedPlane(-2, (1 / np.sqrt(2), 1 / np.sqrt(2), 1))
    constraint = FixAtoms(mask=mask)
    srf.set_constraint([constraint, c1, c2])
    return srf
예제 #4
0
 def get_atoms(self):
     "Make an atoms object from the active image"
     images = self.gui.images
     if images.natoms < 1:
         oops("No atoms present")
         return None
     n = self.getimagenumber()
     return Atoms(positions=images.P[n],
                  symbols=images.Z,
                  cell=images.A[n],
                  pbc=images.pbc)
예제 #5
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
예제 #6
0
def get_atoms_surf():
    a = 2.70
    c = 1.59 * a
    h = 1.85
    d = 1.10

    slab = Atoms('2Cu', [(0., 0., 0.), (1 / 3., 1 / 3., -0.5 * c)],
                 tags=(0, 1),
                 pbc=(1, 1, 0))
    slab.set_cell([(a, 0, 0), (a / 2, 3**0.5 * a / 2, 0), (0, 0, 1)])
    slab = slab.repeat((4, 4, 1))
    mask = [a.tag == 1 for a in slab]
    slab.set_constraint(FixAtoms(mask=mask))
    return slab
예제 #7
0
def get_atoms():
    zpos = cos(134.3 / 2.0 * pi / 180.0) * 1.197
    xpos = sin(134.3 / 2.0 * pi / 180.0) * 1.19
    no2 = Atoms('CO',
                positions=[(-xpos + 1.2, 0, -zpos),
                           (-xpos + 1.2, -1.1, -zpos)])

    # Surface slab
    slab = fcc111('Au', size=(2, 2, 4), vacuum=2 * 5, orthogonal=True)
    slab.center()
    add_adsorbate(slab, no2, 1.5, 'bridge')
    slab.set_pbc((True, True, False))

    #constraints
    constraint = FixAtoms(mask=[(a.tag == 4) or (a.tag == 3) or (a.tag == 2)
                                for a in slab])
    slab.set_constraint(constraint)
    return slab
예제 #8
0
from ase_ext import Atoms
a = Atoms('H2', positions=[(0, 0, 0), (0, 0, 1.1)])

a.pbc[0] = 1
assert a.pbc.any()
assert not a.pbc.all()
a.pbc = 1
assert a.pbc.all()

a.cell = (1, 2, 3)
a.cell *= 2
a.cell[0, 0] = 3
assert not (a.cell.diagonal() - (3, 4, 6)).any()
예제 #9
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]
예제 #10
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)
예제 #11
0
from ase_ext import Atoms
from ase_ext.optimize import QuasiNewton
from ase_ext.neb import NEB
from ase_ext.optimize.mdmin import MDMin
try:
    from asap3 import EMT
except ImportError:
    pass
else:

    a = 3.6
    b = a / 2
    initial = Atoms('Cu4',
                    positions=[(0, 0, 0), (0, b, b), (b, 0, b), (b, b, 0)],
                    cell=(a, a, a),
                    pbc=True)
    initial *= (4, 4, 4)
    del initial[0]
    images = [initial] + [initial.copy() for i in range(6)]
    images[-1].positions[0] = (0, 0, 0)
    for image in images:
        image.set_calculator(EMT())
        #image.set_calculator(ASAP())

    for image in [images[0], images[-1]]:
        QuasiNewton(image).run(fmax=0.01)
    neb = NEB(images)
    neb.interpolate()

    for a in images:
        print(a.positions[0], a.get_potential_energy())
예제 #12
0
def read_aims(filename):
    """Import FHI-aims geometry type files.

    Reads unitcell, atom positions and constraints from
    a geometry.in file.
    """

    from ase_ext import Atoms
    from ase_ext.constraints import FixAtoms, FixCartesian
    import numpy as np

    atoms = Atoms()
    fd = open(filename, 'r')
    lines = fd.readlines()
    fd.close()
    positions = []
    cell = []
    symbols = []
    fix = []
    fix_cart = []
    xyz = np.array([0, 0, 0])
    i = -1
    n_periodic = -1
    periodic = np.array([False, False, False])
    for n, line in enumerate(lines):
        inp = line.split()
        if inp == []:
            continue
        if inp[0] == 'atom':
            if xyz.all():
                fix.append(i)
            elif xyz.any():
                print(1)
                fix_cart.append(FixCartesian(i, xyz))
            floatvect = float(inp[1]), float(inp[2]), float(inp[3])
            positions.append(floatvect)
            symbols.append(inp[-1])
            i += 1
            xyz = np.array([0, 0, 0])
        elif inp[0] == 'lattice_vector':
            floatvect = float(inp[1]), float(inp[2]), float(inp[3])
            cell.append(floatvect)
            n_periodic = n_periodic + 1
            periodic[n_periodic] = True
        if inp[0] == 'constrain_relaxation':
            if inp[1] == '.true.':
                fix.append(i)
            elif inp[1] == 'x':
                xyz[0] = 1
            elif inp[1] == 'y':
                xyz[1] = 1
            elif inp[1] == 'z':
                xyz[2] = 1
    if xyz.all():
        fix.append(i)
    elif xyz.any():
        fix_cart.append(FixCartesian(i, xyz))
    atoms = Atoms(symbols, positions)
    if periodic.all():
        atoms.set_cell(cell)
        atoms.set_pbc(periodic)
    if len(fix):
        atoms.set_constraint([FixAtoms(indices=fix)] + fix_cart)
    else:
        atoms.set_constraint(fix_cart)
    return atoms
예제 #13
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')
예제 #14
0
from ase_ext import Atoms
from ase_ext.io import read, write

atoms = Atoms('HH', [[.0,.0,.0], [.0,.0,.74]], pbc=True, cell=[5, 5, 5])
atoms.set_initial_magnetic_moments([1, -1])
moms = atoms.get_initial_magnetic_moments()
write('test.traj',atoms)
atoms = read('test.traj')
assert (atoms.get_initial_magnetic_moments() == moms).all()
예제 #15
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)
예제 #16
0
from math import sqrt
from ase_ext import Atoms, Atom
from ase_ext.constraints import FixAtoms
from ase_ext.optimize import QuasiNewton
from ase_ext.io import PickleTrajectory
from ase_ext.neb import NEB
from ase_ext.calculators.emt import EMT

# Distance between Cu atoms on a (111) surface:
a = 3.6
d = a / sqrt(2)
y = d * sqrt(3) / 2
fcc111 = Atoms('Cu',
               cell=[(d, 0, 0), (d / 2, y, 0), (d / 2, y / 3, -a / sqrt(3))],
               pbc=True)
slab = fcc111 * (2, 2, 4)
slab.set_cell([2 * d, 2 * y, 1])
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
예제 #17
0
from ase_ext import Atoms
from ase_ext.calculators.emt import EMT
from ase_ext.optimize import QuasiNewton

n2 = Atoms('N2', positions=[(0, 0, 0), (0, 0, 1.1)], calculator=EMT())
QuasiNewton(n2).run(0.01)
print(n2.get_distance(0, 1), n2.get_potential_energy())
예제 #18
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
예제 #19
0
import numpy as np
from ase_ext import Atoms
from ase_ext.io import write, read

a = 5.0
d = 1.9
c = a / 2
atoms = Atoms('AuH',
              positions=[(c, c, 0), (c, c, d)],
              cell=(a, a, 2 * d),
              pbc=(0, 0, 1))
extra = np.array([2.3, 4.2])
atoms.set_array("extra", extra)
atoms *= (1, 1, 2)
images = [atoms.copy(), atoms.copy()]
r = ['xyz', 'traj', 'cube', 'pdb', 'cfg', 'struct']
w = r + ['xsf']
try:
    import matplotlib
except ImportError:
    pass
else:
    w += ['png', 'eps']

for format in w:
    print(format, 'O', end=' ')
    fname1 = 'io-test.1.' + format
    fname2 = 'io-test.2.' + format
    write(fname1, atoms, format=format)
    if format not in ['cube', 'png', 'eps', 'cfg', 'struct']:
        write(fname2, images, format=format)
예제 #20
0
from ase_ext import Atoms
from ase_ext.calculators.emt import EMT
from ase_ext.optimize import QuasiNewton
from ase_ext.vibrations import Vibrations
from ase_ext.thermochemistry import IdealGasThermo

n2 = Atoms('N2', positions=[(0, 0, 0), (0, 0, 1.1)], calculator=EMT())
QuasiNewton(n2).run(fmax=0.01)
vib = Vibrations(n2)
vib.run()
print(vib.get_frequencies())
vib.summary()
print(vib.get_mode(-1))
vib.write_mode(-1, nimages=20)
vib_energies = vib.get_energies()

thermo = IdealGasThermo(vib_energies=vib_energies,
                        geometry='linear',
                        atoms=n2,
                        symmetrynumber=2,
                        spin=0)
thermo.get_free_energy(temperature=298.15, pressure=2 * 101325.)
예제 #21
0
import numpy.random as random
import numpy as np
from ase_ext import Atoms
from ase_ext.calculators.neighborlist import NeighborList

atoms = Atoms(numbers=list(range(10)),
              cell=[(0.2, 1.2, 1.4), (1.4, 0.1, 1.6), (1.3, 2.0, -0.1)])
atoms.set_scaled_positions(3 * random.random((10, 3)) - 1)


def count(nl, atoms):
    c = np.zeros(len(atoms), int)
    R = atoms.get_positions()
    cell = atoms.get_cell()
    d = 0.0
    for a in range(len(atoms)):
        i, offsets = nl.get_neighbors(a)
        for j in i:
            c[j] += 1
        c[a] += len(i)
        d += (((R[i] + np.dot(offsets, cell) - R[a])**2).sum(1)**0.5).sum()
    return d, c


for sorted in [False, True]:
    for p1 in range(2):
        for p2 in range(2):
            for p3 in range(2):
                print(p1, p2, p3)
                atoms.set_pbc((p1, p2, p3))
                nl = NeighborList(atoms.numbers * 0.2 + 0.5,
예제 #22
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')
예제 #23
0
from ase_ext import Atoms
from ase_ext.calculators.emt import EMT
from ase_ext.constraints import FixBondLength
from ase_ext.io import PickleTrajectory
from ase_ext.optimize import BFGS

a = 3.6
b = a / 2
cu = Atoms('Cu2Ag',
           positions=[(0, 0, 0), (b, b, 0), (a, a, b)],
           calculator=EMT())
e0 = cu.get_potential_energy()
print(e0)

d0 = cu.get_distance(0, 1)
cu.set_constraint(FixBondLength(0, 1))
t = PickleTrajectory('cu2ag.traj', 'w', cu)
qn = BFGS(cu)
qn.attach(t.write)


def f():
    print(cu.get_distance(0, 1))


qn.attach(f)
qn.run(fmax=0.01)
assert abs(cu.get_distance(0, 1) - d0) < 1e-14
예제 #24
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)
예제 #25
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)]
예제 #26
0
from ase_ext import Atoms
print(Atoms())
print(Atoms('H2O'))
#...
예제 #27
0
vcmd = os.getenv('VASP_COMMAND')
vscr = os.getenv('VASP_SCRIPT')
if vcmd == None and vscr == None:
    raise NotAvailable('Neither VASP_COMMAND nor VASP_SCRIPT defined')

from ase_ext import Atoms
from ase_ext.calculators.vasp import Vasp
import numpy as np

def array_almost_equal(a1, a2, tol=np.finfo(type(1.0)).eps):
    """Replacement for old numpy.testing.utils.array_almost_equal."""
    return (np.abs(a1 - a2) < tol).all()

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
예제 #28
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())
예제 #29
0
import numpy as np
from ase_ext import Atoms
from ase_ext.calculators.emt import EMT
from ase_ext.io import PickleTrajectory

Cu = Atoms('Cu', pbc=(1, 0, 0), calculator=EMT())
traj = PickleTrajectory('Cu.traj', 'w')
for a in np.linspace(2.0, 4.0, 20):
    Cu.set_cell([a, 1, 1], scale_atoms=True)
    traj.write(Cu)
예제 #30
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