Ejemplo n.º 1
0
    >>> d = 1.104  # N2 bondlength
    >>> a = Atoms('N2', [(0, 0, 0), (0, 0, d)])
    >>> a = Atoms(numbers=[7, 7], positions=[(0, 0, 0), (0, 0, d)])
    >>> a = Atoms([Atom('N', (0, 0, 0)), Atom('N', (0, 0, d))])

so let's check"""

numbers = [7, 7]
symbols = ["N", "N"]
dummy_array = 2 * [3 * [0.0]]

d = 1.104  # N2 bondlength
a1 = Atoms("N2", [(0, 0, 0), (0, 0, d)])
a2 = Atoms(numbers=[7, 7], positions=[(0, 0, 0), (0, 0, d)])
a3 = Atoms([Atom("N", (0, 0, 0)), Atom("N", (0, 0, d))])


def test_atoms(atoms1=a1, atoms2=a2, atoms3=a3):
    assert atoms1 == atoms2
    assert atoms2 == atoms3


# test redundant keywords
def test_symbols(numbers=numbers, symbols=symbols):
    kw = {"numbers": numbers, "symbols": symbols}
    _test_keywords(**kw)


def test_momenta(numbers=numbers, momenta=dummy_array):
    kw = {"momenta": momenta, "velocities": momenta}
Ejemplo n.º 2
0
    def unitcell(self, latx, laty):
        pos2 = np.array([
            0.34109, 1.18154, 0, 7.16273, 4.33233, 0, 4.77515, 3.74156, 0,
            5.11624, 2.36309, 0, 2.38758, 3.15078, 0, 5.45733, 6.10465, 0,
            7.50382, 2.95387, 0, 3.41082, 4.13541, 0, 2.72866, 1.77231, 0,
            0.68216, 4.92311, 0, 8.18599, 5.31696, 0, 4.09299, 1.37846, 0,
            8.18599, 0.19692, 0, 6.82166, 0.59078, 0, 2.04649, 14.76931, 0,
            3.41082, 14.37546, 0, 5.45733, 11.22468, 0, 1.36433, 12.40622, 0,
            0.68216, 10.04313, 0, 0.34109, 11.42161, 0, 6.13949, 13.58776, 0,
            3.06975, 10.6339, 0, 2.72866, 12.01237, 0, 7.8449, 11.81546, 0,
            5.11624, 12.60315, 0, 7.50382, 13.19392, 0, 8.52706, 9.0585, 0,
            6.82166, 10.83083, 0, 6.48057, 7.08926, 0, 3.75191, 7.87696, 0,
            4.77515, 8.86159, 0, 6.13949, 8.46774, 0, 1.70542, 5.90772, 0,
            1.36433, 7.2862, 0, 4.09299, 6.4985, 0, 2.04649, 9.64928, 0, 0,
            2.56002, 0, 0, 7.68004, 0, 9.8914, 3.54463, 0, 14.66656, 4.72618,
            0, 13.6433, 3.74156, 0, 14.32548, 6.10465, 0, 16.37197, 2.95387, 0,
            11.9379, 5.51387, 0, 12.27897, 4.13541, 0, 11.59681, 1.77231, 0,
            9.55032, 4.92311, 0, 17.05414, 5.31696, 0, 16.71305, 6.69542, 0,
            12.96114, 1.37846, 0, 10.57357, 0.7877, 0, 17.05414, 0.19692, 0,
            15.34872, 1.96924, 0, 15.68981, 0.59078, 0, 10.91464, 14.76931, 0,
            17.39521, 14.17854, 0, 12.27897, 14.37546, 0, 14.32548, 11.22468,
            0, 12.62006, 12.997, 0, 10.23248, 12.40622, 0, 9.8914, 13.7847, 0,
            9.55032, 10.04313, 0, 15.00764, 13.58776, 0, 11.59681, 12.01237, 0,
            14.66656, 14.96624, 0, 16.37197, 13.19392, 0, 15.68981, 10.83083,
            0, 13.6433, 8.86159, 0, 15.00764, 8.46774, 0, 16.03088, 9.45235, 0,
            10.23248, 7.2862, 0, 12.96114, 6.4985, 0, 11.25573, 8.27081, 0,
            10.91464, 9.64928, 0, 8.86815, 2.56002, 0, 8.86815, 7.68004, 0,
            13.30223, 0, 0, 13.30223, 10.24006, 0, 1.02325, 18.90472, 0,
            5.7984, 20.08626, 0, 4.77515, 19.10165, 0, 5.45733, 21.46474, 0,
            7.50382, 18.31395, 0, 3.06975, 20.87396, 0, 3.41082, 19.4955, 0,
            2.72866, 17.1324, 0, 0.68216, 20.28319, 0, 8.18599, 20.67704, 0,
            7.8449, 22.0555, 0, 4.09299, 16.73855, 0, 1.70542, 16.14778, 0,
            8.18599, 15.557, 0, 6.48057, 17.32933, 0, 6.82166, 15.95087, 0,
            2.04649, 30.12939, 0, 8.52706, 29.53863, 0, 3.41082, 29.73555, 0,
            5.45733, 26.58476, 0, 3.75191, 28.35709, 0, 1.36433, 27.76631, 0,
            1.02325, 29.14478, 0, 0.68216, 25.40322, 0, 6.13949, 28.94785, 0,
            2.72866, 27.37246, 0, 5.7984, 30.32633, 0, 7.50382, 28.554, 0,
            6.82166, 26.19091, 0, 4.77515, 24.22167, 0, 6.13949, 23.82783, 0,
            7.16273, 24.81244, 0, 1.36433, 22.64628, 0, 4.09299, 21.85859, 0,
            2.38758, 23.6309, 0, 2.04649, 25.00937, 0, 0, 17.92011, 0, 0,
            23.04013, 0, 4.43408, 15.36009, 0, 4.43408, 25.60015, 0, 9.20924,
            16.54163, 0, 16.03088, 19.69242, 0, 13.6433, 19.10165, 0, 13.98439,
            17.72318, 0, 11.25573, 18.51087, 0, 14.32548, 21.46474, 0,
            16.37197, 18.31395, 0, 12.27897, 19.4955, 0, 11.59681, 17.1324, 0,
            9.55032, 20.28319, 0, 17.05414, 20.67704, 0, 12.96114, 16.73855, 0,
            17.05414, 15.557, 0, 15.68981, 15.95087, 0, 10.91464, 30.12939, 0,
            12.27897, 29.73555, 0, 14.32548, 26.58476, 0, 10.23248, 27.76631,
            0, 9.55032, 25.40322, 0, 9.20924, 26.78169, 0, 15.00764, 28.94785,
            0, 11.9379, 25.99398, 0, 11.59681, 27.37246, 0, 16.71305, 27.17554,
            0, 13.98439, 27.96324, 0, 16.37197, 28.554, 0, 17.39521, 24.41859,
            0, 15.68981, 26.19091, 0, 15.34872, 22.44935, 0, 12.62006,
            23.23705, 0, 13.6433, 24.22167, 0, 15.00764, 23.82783, 0, 10.57357,
            21.26781, 0, 10.23248, 22.64628, 0, 12.96114, 21.85859, 0,
            10.91464, 25.00937, 0, 8.86815, 17.92011, 0, 8.86815, 23.04013, 0,
            1.02325, 3.54463, 0, 5.7984, 4.72618, 0, 3.06975, 5.51387, 0,
            7.8449, 6.69542, 0, 1.70542, 0.7877, 0, 6.48057, 1.96924, 0,
            8.52706, 14.17854, 0, 3.75191, 12.997, 0, 1.02325, 13.7847, 0,
            5.7984, 14.96624, 0, 7.16273, 9.45235, 0, 2.38758, 8.27081, 0,
            4.43408, 0, 0, 4.43408, 10.24006, 0, 9.20924, 1.18154, 0, 16.03088,
            4.33233, 0, 13.98439, 2.36309, 0, 11.25573, 3.15078, 0, 9.20924,
            11.42161, 0, 11.9379, 10.6339, 0, 16.71305, 11.81546, 0, 13.98439,
            12.60315, 0, 17.39521, 9.0585, 0, 15.34872, 7.08926, 0, 12.62006,
            7.87696, 0, 10.57357, 5.90772, 0, 0.34109, 16.54163, 0, 7.16273,
            19.69242, 0, 5.11624, 17.72318, 0, 2.38758, 18.51087, 0, 0.34109,
            26.78169, 0, 3.06975, 25.99398, 0, 7.8449, 27.17554, 0, 5.11624,
            27.96324, 0, 8.52706, 24.41859, 0, 6.48057, 22.44935, 0, 3.75191,
            23.23705, 0, 1.70542, 21.26781, 0, 9.8914, 18.90472, 0, 14.66656,
            20.08626, 0, 11.9379, 20.87396, 0, 16.71305, 22.0555, 0, 10.57357,
            16.14778, 0, 15.34872, 17.32933, 0, 17.39521, 29.53863, 0,
            12.62006, 28.35709, 0, 9.8914, 29.14478, 0, 14.66656, 30.32633, 0,
            16.03088, 24.81244, 0, 11.25573, 23.6309, 0, 13.30223, 15.36009, 0,
            13.30223, 25.60015, 0
        ]).reshape(-1, 3) / 1.42
        pos1 = [6.928400, 13.000369, 0.000000, 7.794450, 16.500469, 0.000000]
        phi = pi / 2 - atan((pos1[4] - pos1[1]) / (pos1[3] - pos1[0]))
        cbond = np.linalg.norm((pos1[4] - pos1[1], pos1[3] - pos1[0], 0))
        dx = sqrt(3) * cbond * 2
        dy = 3 * cbond * 2
        atoms = Atoms()

        for i, coord in enumerate(pos2):
            ele = ['C', 'N'][i < 156]
            atom = Atom(ele, coord)
            atoms.append(atom)
        #atoms.rotate('z',phi)
        atoms.set_cell([dx, dy, 10.0])
        col = atoms.repeat((latx, laty, 1))
        return col
Ejemplo n.º 3
0
from jasp import *
from ase import Atom, Atoms
from ase.io import write
from enthought.mayavi import mlab
from ase.data import vdw_radii
from ase.data.colors import cpk_colors
atoms = Atoms([
    Atom('C', [0.0000, 0.0000, -0.8088]),
    Atom('Br', [0.0000, 0.0000, 1.1146]),
    Atom('F', [0.0000, 1.2455, -1.2651]),
    Atom('F', [1.0787, -0.6228, -1.2651]),
    Atom('F', [-1.0787, -0.6228, -1.2651])
],
              cell=(10, 10, 10))
atoms.center()
with jasp('molecules/CF3Br',
          encut=350,
          xc='PBE',
          ibrion=1,
          nsw=50,
          lvtot=True,
          lvhar=True,
          atoms=atoms) as calc:
    calc.set_nbands(f=2)
    calc.calculate()
    x, y, z, lp = calc.get_local_potential()
    x, y, z, cd = calc.get_charge_density()
mlab.figure(1, bgcolor=(1, 1, 1))  # make a white figure
# plot the atoms as spheres
for atom in atoms:
    mlab.points3d(
Ejemplo n.º 4
0
from ase.test import NotAvailable

import numpy as np
import ase.io.netcdftrajectory as netcdftrajectory

if not netcdftrajectory.have_nc:
    raise NotAvailable('No NetCDF module available (netCDF4-python, '
                       'scipy.io.netcdf)')

import os
from ase import Atom, Atoms
from ase.io import NetCDFTrajectory

co = Atoms([Atom('C', (0, 0, 0)), Atom('O', (0, 0, 1.2))],
           cell=[3, 3, 3],
           pbc=True)
traj = NetCDFTrajectory('1.nc', 'w', co)
for i in range(5):
    co.positions[:, 2] += 0.1
    traj.write()
del traj
if netcdftrajectory.have_nc == netcdftrajectory.NC_IS_NETCDF4:
    traj = NetCDFTrajectory('1.nc', 'a')
    co = traj[-1]
    print(co.positions)
    co.positions[:] += 1
    traj.write(co)
    del traj
    t = NetCDFTrajectory('1.nc', 'a')
else:
    t = NetCDFTrajectory('1.nc', 'r')
Ejemplo n.º 5
0
from ase import Atom, Atoms
from gpaw import GPAW
from gpaw.test import equal

a = 4.05
d = a / 2**0.5
bulk = Atoms([Atom('Al', (0, 0, 0)), Atom('Al', (0.5, 0.5, 0.5))], pbc=True)
bulk.set_cell((d, d, a), scale_atoms=True)
h = 0.25
calc = GPAW(h=h, nbands=2 * 8, kpts=(2, 2, 2), convergence={'energy': 1e-5})
bulk.set_calculator(calc)
e0 = bulk.get_potential_energy()
niter0 = calc.get_number_of_iterations()
calc = GPAW(h=h,
            nbands=2 * 8,
            kpts=(2, 2, 2),
            convergence={'energy': 1e-5},
            eigensolver='cg')
bulk.set_calculator(calc)
e1 = bulk.get_potential_energy()
niter1 = calc.get_number_of_iterations()
equal(e0, e1, 3.6e-5)

energy_tolerance = 0.00004
niter_tolerance = 0
equal(e0, -6.97626, energy_tolerance)
assert 16 <= niter0 <= 22, niter0
equal(e1, -6.97627, energy_tolerance)
assert 12 <= niter1 <= 17, niter1
Ejemplo n.º 6
0
# 12-ZGNR with adsorbed H at both edges.
# "ZGNR12.py" should be run first!

from ase.io import read
from ase import Atom
from ase.structure import graphene_nanoribbon
from ase.optimize import QuasiNewton
from gpaw import GPAW

GNR = read('ZGNR12.traj')
pos = GNR[22].get_position() + [-1.05, 0.0, 0.0]
GNR.append(Atom('H', pos))
pos = GNR[1].get_position() + [1.05, 0.0, 0.0]
GNR.append(Atom('H', pos))
GNR.set_pbc((0, 0, 1))
kpts = (1, 1, 10)
calc = GPAW(kpts=kpts, spinpol=True)
GNR.set_calculator(calc)
dyn = QuasiNewton(GNR, trajectory='GNR_H.traj')
dyn.run(fmax=0.05)
Ejemplo n.º 7
0
from math import pi, cos, sin
from ase import Atom, Atoms
from ase.parallel import rank, barrier
from gpaw import GPAW
from gpaw.test import equal, gen
import numpy as np

# Generate setup for oxygen with half a core-hole:
gen('O', name='hch1s', corehole=(1, 0, 0.5))

if 1:
    a = 5.0
    d = 0.9575
    t = pi / 180 * 104.51
    H2O = Atoms([
        Atom('O', (0, 0, 0)),
        Atom('H', (d, 0, 0)),
        Atom('H', (d * cos(t), d * sin(t), 0))
    ],
                cell=(a, a, a),
                pbc=False)
    H2O.center()
    calc = GPAW(nbands=10, h=0.2, setups={'O': 'hch1s'})
    H2O.set_calculator(calc)
    e = H2O.get_potential_energy()
    niter = calc.get_number_of_iterations()
    calc.write('h2o.gpw')
else:
    calc = GPAW('h2o.gpw')
    calc.initialize_positions()
Ejemplo n.º 8
0
from ase import Atoms, Atom
from ase.io import write
# define an Atoms object
atoms = Atoms([Atom('C', [0., 0., 0.]),
               Atom('O', [1.1, 0., 0.])],
              cell=(10, 10, 10))
print 'V = {0:1.0f} Angstrom^3'.format(atoms.get_volume())
write('images/simple-cubic-cell.png', atoms, show_unit_cell=2)
Ejemplo n.º 9
0
import numpy as np
from ase import Atom, Atoms
from gpaw import GPAW
from gpaw.test import equal
from gpaw.lrtddft import LrTDDFT

txt = '-'
txt = None
load = True
load = False

R = 0.7  # approx. experimental bond length
a = 4.0
c = 5.0
H2 = Atoms([
    Atom('H', (a / 2, a / 2, (c - R) / 2)),
    Atom('H', (a / 2, a / 2, (c + R) / 2))
],
           cell=(a, a, c))

calc = GPAW(xc='PBE', nbands=2, spinpol=False, txt=txt)
H2.set_calculator(calc)
H2.get_potential_energy()
calc.write('H2saved_wfs.gpw', 'all')
calc.write('H2saved.gpw')
wfs_error = calc.wfs.eigensolver.error

xc = 'LDA'

#print "-> starting directly after a gs calculation"
lr = LrTDDFT(calc, xc=xc, txt='-')
Ejemplo n.º 10
0
from ase.constraints import FixAtoms
from matplotlib import mlab
from numpy import *
from ase.utils.eos import EquationOfState
from ase.lattice.cubic import BodyCenteredCubic
from ase import Atom

a = 5.7885 / 2

cell = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
atoms = BodyCenteredCubic('Fe', directions=cell)
atoms.set_initial_magnetic_moments([5, 5])
atoms.set_cell([a, a, a], scale_atoms=True)
#atoms.set_cell([a,a,a])

carbon = Atom('C', position=(0, 0.5 * a, 0.5 * a), charge=0.4)

atoms = atoms * (2, 2, 2) + carbon

constraint = FixAtoms(indices=[8, 10])

atoms.set_constraint(constraint)

init = atoms.copy()

final = atoms.copy()
final[-1].position = [0, 0.5 * a, (0.5 + 0.25) * a]

for i in range(0, 18):
    os.system('mkdir {:02d}'.format(i))
    os.chdir('{:02d}'.format(i))