def do_nao_ngto_basis(atom, xc, naobasis, gbsfname, label, rmax=100.0):
    # Read Gaussians
    atomgbs, descriptiongbs, gto_k = read_gbs(gbsfname)
    assert atom == atomgbs

    # Generate nao basis
    assert naobasis == 'sz'

    # Choose basis sets without semi-core states XXXXXX
    if atom == 'Ag':
        label = '11.%s' % label
        p = parameters_extra
    else:
        p = parameters

    bm = BasisMaker(atom, label, run=False, gtxt=None, xc=xc)
    bm.generator.run(write_xml=False, use_restart_file=False, **p[atom])
    basis = bm.generate(1, 0, txt=None)

    # Increase basis function max radius
    h = basis.rgd.dr_g
    assert isinstance(h, float)
    assert basis.rgd.r_g[0] == 0.0
    N = int(rmax / h) + 1
    basis.rgd = EquidistantRadialGridDescriptor(h, N)

    # Add NGTOs
    tol = 0.001

    description = []
    msg = 'Augmented with NGTOs'
    description.append(msg)
    description.append('=' * len(msg))
    description.append('')
    msg = 'GTOs from file %s' % os.path.basename(gbsfname)
    description.append(msg)
    description.append('-' * len(msg))
    description.append(descriptiongbs)
    description.append('')
    description.append('NGTO truncation tolerance: %f' % tol)
    description.append('Functions: NGTO(l,alpha)')

    for gto in gto_k:
        l = gto['l']
        assert len(gto['alpha_j']) == 1, \
            'Only non-contracted GTOs supported'
        alpha = gto['alpha_j'][0]
        ngtolabel = 'NGTO(%s,%.7f)' % ('spdfghi'[l], alpha)
        description.append('    ' + ngtolabel)
        add_ngto(basis, l, alpha, tol, ngtolabel)

    basis.generatordata += '\n\n' + '\n'.join(description)

    basis.write_xml()
Exemple #2
0
from __future__ import print_function
from ase.build import molecule
from gpaw import GPAW
from gpaw.poisson import PoissonSolver
from gpaw.atom.basis import BasisMaker
from gpaw.test import equal

# Tests basis set super position error correction

# Compares a single hydrogen atom to a system of one hydrogen atom
# and one ghost hydrogen atom.  The systems should have identical properties,
# i.e. the ghost orbital should have a coefficient of 0.

b = BasisMaker('H').generate(1, 0, energysplit=0.005)

system = molecule('H2')
system.center(vacuum=6.0)


def prepare(setups):
    calc = GPAW(basis={'H': b},
                mode='lcao',
                setups=setups,
                h=0.2,
                poissonsolver=PoissonSolver(nn='M', relax='GS', eps=1e-5),
                spinpol=False,
                nbands=1)
    system.set_calculator(calc)
    return calc

Exemple #3
0
    A[:, 1] = r[gc - 2:gc + 2]**2
    A[:, 2] = A[:, 1]**2
    A[:, 3] = A[:, 1] * A[:, 2]
    a = u[gc - 2:gc + 2] / r[gc - 2:gc + 2]**(l + 1)
    a = solve(A, a)
    r1 = r[:gc]
    r2 = r1**2
    rl1 = r1**(l + 1)
    y = a[0] + r2 * (a[1] + r2 * (a[2] + r2 * (a[3])))
    s[:gc] = rl1 * y


if __name__ == '__main__':
    import os
    from gpaw.atom.basis import BasisMaker
    from gpaw.atom.configurations import parameters

    for xcname in ['LDA', 'PBE', 'RPBE', 'revPBE', 'GLLBSC']:
        for symbol, par in parameters.items():
            filename = symbol + '.' + xcname
            if os.path.isfile(filename) or os.path.isfile(filename + '.gz'):
                continue
            g = Generator(symbol, xcname, scalarrel=True, nofiles=True)
            g.run(exx=True, logderiv=False, use_restart_file=False, **par)

            if xcname == 'PBE':
                bm = BasisMaker(g, name='dzp', run=False)
                basis = bm.generate()
                basis.write_xml()

Exemple #4
0

if rank != 0:
    sys.stdout = devnull 

GS = 1
GS2 = 1
OpticalLimit = 1

nband = 60


if GS:

    # Gs calculation one
    basis = BasisMaker('C').generate(2, 1) # dzp

    kpts = (20,20,7)
    a=1.42
    c=3.355

    # AB stack
    atoms = Atoms('C4',[
                  (1/3.0,1/3.0,0),
                  (2/3.0,2/3.0,0),
                  (0.   ,0.   ,0.5),
                  (1/3.0,1/3.0,0.5)
                  ],
                  pbc=(1,1,1))
    atoms.set_cell([(sqrt(3)*a/2.0,3/2.0*a,0),
                    (-sqrt(3)*a/2.0,3/2.0*a,0),
Exemple #5
0
# by setting the fd boolean below.
#
# The purpose is to test domain decomposition with large cells.  The basis
# functions of one atom are defined to not overlap the rightmost domain
# for z-decompositions of two or more slices.  This will change the set
# of atomic indices stored in BasisFunctions objects and other things
#
# This test also ensures that lcao forces are tested with non-pbc.
import numpy as np
from numpy import array
from ase import Atoms
from ase.units import Bohr
from gpaw import GPAW
from gpaw.atom.basis import BasisMaker

hbasis = BasisMaker('H').generate(1, 0, energysplit=1.8, tailnorm=0.03**.5)
basis = {'H' : hbasis}

atom = Atoms('H')
atom.center(vacuum=.8)
system = atom.repeat((1, 1, 4))

rc = hbasis.bf_j[0].rc

system.center(vacuum=2.5)

calc = GPAW(h=0.23,
            mode='lcao',
            basis=basis,
            convergence={'density':1e-4, 'energy': 1e-7},
            )
Exemple #6
0
    A[:, 1] = r[gc - 2:gc + 2]**2
    A[:, 2] = A[:, 1]**2
    A[:, 3] = A[:, 1] * A[:, 2]
    a = u[gc - 2:gc + 2] / r[gc - 2:gc + 2]**(l + 1)
    a = solve(A, a)
    r1 = r[:gc]
    r2 = r1**2
    rl1 = r1**(l + 1)
    y = a[0] + r2 * (a[1] + r2 * (a[2] + r2 * (a[3])))
    s[:gc] = rl1 * y


if __name__ == '__main__':
    import os
    from gpaw.xc_functional import XCFunctional
    from gpaw.atom.basis import BasisMaker
    from gpaw.atom.configurations import parameters

    for xcname in ['LDA', 'PBE', 'RPBE', 'revPBE']:
        for symbol, par in parameters.items():
            filename = symbol + '.' + XCFunctional(xcname).get_name()
            if os.path.isfile(filename):
                continue
            g = Generator(symbol, xcname, scalarrel=True, nofiles=True)
            g.run(exx=True, logderiv=False, use_restart_file=False, **par)

            if xcname == 'PBE':
                bm = BasisMaker(g, name='dzp', run=False)
                basis = bm.generate()
                basis.write_xml()
Exemple #7
0
from gpaw.atom.generator import Generator
from gpaw.atom.configurations import parameters
from gpaw.atom.basis import BasisMaker

symbol = 'Au'
args = parameters[symbol]  # Dictionary of default setup parameters
args['rcut'] = 2.6  # Set cutoff of augmentation sphere

generator = Generator(symbol, 'RPBE')
generator.N *= 2  # Increase grid resolution
generator.run(write_xml=False, **args)

bm = BasisMaker(generator, name='special', run=False)

# Create double-zeta RPBE basis where p orbital is considered a valence state
# (ordinary dzp basis would use a smaller p-type Gaussian for polarization)
# The list jvalues indicates which states should be included, and the
# ordering corresponds to the valence states in the setup.
basis = bm.generate(zetacount=2,
                    polarizationcount=0,
                    energysplit=0.1,
                    jvalues=[0, 1, 2],
                    rcutmax=12.0)

basis.write_xml()  # Dump to file 'Au.special.basis'
Exemple #8
0
from gpaw.atom.generator import Generator
from gpaw.atom.configurations import parameters
from gpaw.atom.basis import BasisMaker

symbol = 'Au'
args = parameters[symbol] # Dictionary of default setup parameters
args['rcut'] = 2.6 # Set cutoff of augmentation sphere

generator = Generator(symbol, 'RPBE')
generator.N *= 2 # Increase grid resolution
generator.run(write_xml=False, **args)

bm = BasisMaker(generator, name='special', run=False)

# Create double-zeta RPBE basis where p orbital is considered a valence state
# (ordinary dzp basis would use a smaller p-type Gaussian for polarization)
basis = bm.generate(zetacount=2, polarizationcount=0,
                    energysplit=0.1, lvalues=[0, 1, 2],
                    rcutmax=12.0)

basis.write_xml() # Dump to file 'Au.special.basis'
Exemple #9
0
def main():
    parser = build_parser()
    opts, args = parser.parse_args()
    #if __name__ == '__main__' and len(args) == 0:
    #    parser.print_help()
    #    sys.exit(0)

    from gpaw.atom.basis import BasisMaker
    from gpaw import ConvergenceError
    from gpaw.basis_data import parse_basis_name

    zetacount, polcount, basistype = parse_basis_name(opts.type)
    referencefiles = [None] * len(args)
    reference_atom_indices = [None] * len(args)
    if polcount > 0:
        symbols = []
        for i, arg in enumerate(args):
            # Parse argument as <symbol>:<reference-file>:<nuclear index>.
            symbol_and_file = arg.split(':')
            symbol = symbol_and_file[0]
            symbols.append(symbol)
            if len(symbol_and_file) > 1:
                referencefiles[i] = symbol_and_file[1]  # filename
            if len(symbol_and_file) == 3:
                reference_atom_indices[i] = int(symbol_and_file[2])
    else:
        symbols = args

    if opts.name is not None:
        name = '%s.%s' % (opts.name, basistype)
    else:
        name = basistype

    for symbol, referencefile, referenceindex in zip(symbols, referencefiles,
                                                     reference_atom_indices):
        try:
            bm = BasisMaker(symbol,
                            name,
                            gtxt=None,
                            non_relativistic_guess=opts.non_relativistic_guess,
                            xc=opts.xcfunctional)
        except ConvergenceError:
            if opts.non_relativistic_guess:
                print(very_bad_density_warning, file=sys.stderr)
                import traceback
                traceback.print_exc()
            else:
                print(bad_density_warning, file=sys.stderr)
            continue

        tailnorm = [float(norm) for norm in opts.tailnorm.split(',')]
        vconf_args = None
        if not opts.vconf_sharp_confinement:
            vconf_args = opts.vconf_amplitude, opts.vconf_rstart_rel

        jvalues = None
        if opts.jvalues:
            jvalues = [int(j) for j in opts.jvalues.split(',')]

        basis = bm.generate(zetacount,
                            polcount,
                            tailnorm=tailnorm,
                            energysplit=opts.energy_shift,
                            referencefile=referencefile,
                            referenceindex=referenceindex,
                            rcutpol_rel=opts.rcut_pol_rel,
                            rcutmax=opts.rcut_max,
                            rcharpol_rel=opts.rchar_pol_rel,
                            vconf_args=vconf_args,
                            l_pol=opts.lpol,
                            jvalues=jvalues)
        basis.write_xml()
Exemple #10
0
import cPickle as pickle
import numpy as np
from ase import Atoms
from gpaw import GPAW, restart, setup_paths
from gpaw.lcao.tools import get_lcao_hamiltonian
from gpaw.mpi import world
from gpaw.atom.basis import BasisMaker
from gpaw.test import equal

if world.rank == 0:
    basis = BasisMaker('Li', 'szp').generate(1, 1)
    basis.write_xml()
world.barrier()
if setup_paths[0] != '.':
    setup_paths.insert(0, '.')

if 1:
    a = 2.7
    bulk = Atoms('Li', pbc=True, cell=[a, a, a])
    calc = GPAW(gpts=(8, 8, 8), kpts=(4, 4, 4), mode='lcao', basis='szp')
    bulk.set_calculator(calc)
    e = bulk.get_potential_energy()
    niter = calc.get_number_of_iterations()
    calc.write('temp.gpw')

atoms, calc = restart('temp.gpw')
H_skMM, S_kMM = get_lcao_hamiltonian(calc)
eigs = calc.get_eigenvalues(kpt=2)

if world.rank == 0:
    eigs2 = np.linalg.eigvals(np.linalg.solve(S_kMM[2], H_skMM[0, 2])).real
Exemple #11
0
# This test calculates derivatives of lcao overlap matrices such as
#
#   a          ~a
#  P      =  < p  | Phi   >
#   i mu        i      mu
#
# and compares to finite difference results.

from ase.data.molecules import molecule
from ase.units import Bohr
from gpaw import GPAW
from gpaw.atom.basis import BasisMaker

obasis = BasisMaker('O').generate(2, 1)
hbasis = BasisMaker('H').generate(2, 1)
basis = {'O': obasis, 'H': hbasis}

system1 = molecule('H2O')
system1.center(vacuum=2.0)
system1.positions[1] -= 0.2

system2 = system1.copy()
system2.set_cell((3., 3., 3.))
system2.set_pbc(1)


def runcheck(system, dR, kpts=None):
    calc = GPAW(mode='lcao', basis=basis, txt=None)
    system.set_calculator(calc)

    calc.initialize(system)
Exemple #12
0
import cPickle as pickle
import numpy as np
from ase import Atoms
from gpaw import GPAW, setup_paths, FermiDirac
from gpaw.transport.jstm import STM, dump_hs, dump_lead_hs
from gpaw.atom.basis import BasisMaker
from gpaw.mpi import world
from gpaw.test import equal

if world.rank == 0:
    basis = BasisMaker('H', 'sz').generate(1, 0)
    basis.write_xml()
world.barrier()
if setup_paths[0] != '.':
    setup_paths.insert(0, '.')

# GPAW calculations
a = 0.75  # Bond length
cell = np.diag([5, 5, 12 * a])

atoms = Atoms('H12', pbc=(1, 1, 1), cell=cell)
atoms.positions[:, 2] = [i * a for i in range(12)]

calc = GPAW(h=0.2,
            occupations=FermiDirac(width=0.1),
            mode='lcao',
            basis='sz',
            usesymm=False)

# Lead calculation
lead = atoms.copy()
Exemple #13
0
from gpaw.atom.generator import Generator
from gpaw.atom.basis import BasisMaker
args = {'core': '[Kr]', 'rcut': 2.45}
generator = Generator('Ag', 'GLLBSC', scalarrel=True)
generator.N *= 2  # Increase grid resolution
generator.run(**args)
bm = BasisMaker(generator, name='GLLBSC', run=False)
basis = bm.generate(
    zetacount=2,
    polarizationcount=0,
    energysplit=0.07,
    jvalues=[0, 1, 2],  # include d, s and p
    rcutmax=12.0)
basis.write_xml()
Exemple #14
0
# This tests calculates the force on the atoms of a
# slightly distorted Silicon primitive cell.
#
# If the test fails, set the fd boolean below to enable a (costly) finite
# difference check.

import numpy as np
from ase import Atoms
from gpaw import GPAW
from gpaw.atom.basis import BasisMaker
from gpaw.test import equal

sibasis = BasisMaker('Si').generate(2, 1, energysplit=0.3, tailnorm=0.03**.5)
basis = {'Si' : sibasis}

a = 5.475
system = Atoms(symbols='Si2', pbc=True,
               cell=0.5 * a * np.array([(1, 1, 0),
                                        (1, 0, 1),
                                        (0, 1, 1)]),
               scaled_positions=[(0.0, 0.0, 0.0),
                                 (0.23, 0.23, 0.23)])

calc = GPAW(h=0.2,
            mode='lcao',
            basis=basis,
            kpts=(2,2,2),
            convergence={'density':1e-5, 'energy': 1e-6}
            )
system.set_calculator(calc)
from __future__ import print_function
# This tests calculates the force on the atoms of a small molecule.
#
# If the test fails, set the fd boolean below to enable a (costly) finite
# difference check.

import numpy as np
from ase.structure import molecule
from gpaw import GPAW
from gpaw.atom.basis import BasisMaker

obasis = BasisMaker('O').generate(2, 1, energysplit=0.3, tailnorm=0.03**.5)
hbasis = BasisMaker('H').generate(2, 1, energysplit=0.3, tailnorm=0.03**.5)
basis = {'O': obasis, 'H': hbasis}

system = molecule('H2O')
system.center(vacuum=1.5)
system.rattle(stdev=.2, seed=42)
system.set_pbc(1)

calc = GPAW(h=0.2,
            mode='lcao',
            basis=basis,
            kpts=[(0., 0., 0.), (.3, .1, .4)],
            convergence={
                'density': 1e-5,
                'energy': 1e-6
            })

system.set_calculator(calc)
Exemple #16
0
import cPickle as pickle
import numpy as np
from ase import Atoms
from gpaw import GPAW, setup_paths, FermiDirac
from gpaw.transport.jstm import STM, dump_hs, dump_lead_hs
from gpaw.atom.basis import BasisMaker
from gpaw.mpi import world
from gpaw.test import equal

if world.rank == 0:
    basis = BasisMaker('H', 'sz').generate(1, 0)
    basis.write_xml()
world.barrier()
if setup_paths[0] != '.':
    setup_paths.insert(0, '.')

# GPAW calculations
a = 0.75 # Bond length
cell = np.diag([5, 5, 12 * a])

atoms = Atoms('H12', pbc=(1, 1, 1), cell=cell)
atoms.positions[:, 2] = [i * a for i in range(12)]

calc = GPAW(h=0.2,
            occupations=FermiDirac(width=0.1),
            mode='lcao',
            basis='sz',
            usesymm=False)

# Lead calculation
lead = atoms.copy()
def main():
    parser = build_parser()
    opts, args = parser.parse_args()
    #if __name__ == '__main__' and len(args) == 0:
    #    parser.print_help()
    #    sys.exit(0)

    from gpaw.atom.basis import BasisMaker
    from gpaw import ConvergenceError
    from gpaw.basis_data import parse_basis_name

    zetacount, polcount, basistype = parse_basis_name(opts.type)
    referencefiles = [None] * len(args)
    reference_atom_indices = [None] * len(args)
    if polcount > 0:
        symbols = []
        for i, arg in enumerate(args):
            # Parse argument as <symbol>:<reference-file>:<nuclear index>.
            symbol_and_file = arg.split(':')
            symbol = symbol_and_file[0]
            symbols.append(symbol)
            if len(symbol_and_file) > 1:
                referencefiles[i] = symbol_and_file[1] # filename
            if len(symbol_and_file) == 3:
                reference_atom_indices[i] = int(symbol_and_file[2])
    else:
        symbols = args

    if opts.name is not None:
        name = '%s.%s' % (opts.name, basistype)
    else:
        name = basistype

    for symbol, referencefile, referenceindex in zip(symbols, referencefiles,
                                                     reference_atom_indices):
        try:
            bm = BasisMaker(symbol, name, gtxt=None,
                            non_relativistic_guess=opts.non_relativistic_guess,
                            xc=opts.xcfunctional)
        except ConvergenceError:
            if opts.non_relativistic_guess:
                print(very_bad_density_warning, file=sys.stderr)
                import traceback
                traceback.print_exc()
            else:
                print(bad_density_warning, file=sys.stderr)
            continue

        tailnorm = [float(norm) for norm in opts.tailnorm.split(',')]
        vconf_args = None
        if not opts.vconf_sharp_confinement:
            vconf_args = opts.vconf_amplitude, opts.vconf_rstart_rel

        jvalues = None
        if opts.jvalues:
            jvalues = [int(j) for j in opts.jvalues.split(',')]

        basis = bm.generate(zetacount, polcount,
                            tailnorm=tailnorm,
                            energysplit=opts.energy_shift,
                            referencefile=referencefile,
                            referenceindex=referenceindex,
                            rcutpol_rel=opts.rcut_pol_rel,
                            rcutmax=opts.rcut_max,
                            rcharpol_rel=opts.rchar_pol_rel,
                            vconf_args=vconf_args,
                            l_pol=opts.lpol,
                            jvalues=jvalues)
        basis.write_xml()
Exemple #18
0
from ase import Atoms
from gpaw import FermiDirac, Mixer
from gpaw.transport.calculator import Transport
from gpaw.atom.basis import BasisMaker
from gpaw.poisson import PoissonSolver
import pickle

a = 3.6
L = 7.00

basis = BasisMaker('Na').generate(1, 1, energysplit=0.3)

atoms = Atoms('Na12', pbc=(1, 1, 1), cell=[L, L, 12 * a])
atoms.positions[:12, 2] = [i * a for i in range(12)]
atoms.positions[:, :2] = L / 2.
atoms.center()
pl_atoms1 = range(4)
pl_atoms2 = range(8, 12)
pl_cell1 = (L, L, 4 * a)
pl_cell2 = pl_cell1

t = Transport(h=0.3,
              xc='LDA',
              basis={'Na': basis},
              kpts=(2, 2, 1),
              occupations=FermiDirac(0.1),
              mode='lcao',
              poissonsolver=PoissonSolver(nn=2, relax='GS'),
              txt='Na_lcao.txt',
              mixer=Mixer(0.1, 5, weight=100.0),
              guess_steps=10,
Exemple #19
0
def main():
    parser = OptionParser(usage='%prog [OPTION...] [SYMBOL...]',
                          description=description)
    parser.add_option('--xc',
                      metavar='FUNCTIONAL',
                      default='PBE',
                      help='generate basis sets for FUNCTIONAL[=%default]')
    parser.add_option('--from',
                      metavar='SYMBOL',
                      dest='_from',
                      help='generate starting from SYMBOL if generating '
                      'for all elements')
    opts, symbols = parser.parse_args()

    if len(symbols) == 0:
        symbols = sorted(parameters.keys())
        othersymbols = []
        for symbol in parameters_extra:
            name = parameters_extra[symbol]['name']
            code = '%s.%s' % (symbol, name)
            othersymbols.append(code)
        trouble = set(['Os.8', 'Ta.5', 'V.5', 'W.6', 'Ir.9'])
        othersymbols = [
            symbol for symbol in othersymbols if symbol not in trouble
        ]
        symbols.extend(sorted(othersymbols))

        if opts._from:
            index = symbols.index(opts._from)
            symbols = symbols[index:]

    specifications = []
    for sym in symbols:
        try:
            s = SetupData(sym, opts.xc)
        except RuntimeError as e:
            if str(e).startswith('Could not find'):
                #print 'No %s' % sym
                continue
            else:
                raise

        # One could include basis functions also for the ``virtual'' states
        # (marked with negative n)

        jvalues = []
        jextra = []
        for j in range(len(s.f_j)):
            if s.eps_j[j] < 0:
                jvalues.append(j)
                if s.f_j[j] == 0.0 and s.n_j[j] > 0:
                    jextra.append(j)
        if len(jextra) > 0:
            specifications.append(BasisSpecification(s, jvalues, jextra))
            #print sym, jvalues
        # XXX check whether automatic settings coincide with those of official
        # setups distribution
        #bm = BasisMaker(sym, ''

    if world.rank == 0:
        print('Generating basis sets for: %s' %
              ' '.join(spec.setup.symbol for spec in specifications))
    sys.stdout.flush()
    world.barrier()

    for i, spec in enumerate(specifications):
        if i % world.size != world.rank:
            continue
        if world.size > 1:
            print(world.rank, spec)
        else:
            print(spec)
        gtxt = None

        # XXX figure out how to accept Ag.11
        tokens = spec.setup.symbol.split('.')
        sym = tokens[0]

        if len(tokens) == 1:
            p = parameters
            name = 'pvalence'
        elif len(tokens) == 2:
            p = parameters_extra
            name = '%s.pvalence' % tokens[1]
        else:
            raise ValueError('Strange setup specification')

        type = 'dz'  # XXXXXXXXX
        bm = BasisMaker(sym,
                        '%s.%s' % (name, type),
                        run=False,
                        gtxt=gtxt,
                        xc=opts.xc)
        bm.generator.run(write_xml=False, use_restart_file=False, **p[sym])
        basis = bm.generate(2, 0, txt=None, jvalues=spec.jvalues)
        basis.write_xml()