Exemplo n.º 1
0
def calc_me(atoms, nbands):
    """Do the calculation."""
    molecule_name = atoms.get_chemical_formula()
    atoms.set_initial_magnetic_moments([-1.0, 1.0])
    fname = '.'.join([molecule_name, 'PBE-SIN'])
    calc = GPAW(h=0.25,
                xc='PBE',
                eigensolver=CG(niter=5),
                nbands=nbands,
                txt=fname + '.log',
                occupations=FermiDirac(0.0, fixmagmom=True),
                convergence={
                    'energy': 0.005,
                    'bands': nbands,
                    'eigenstates': 1e-4,
                    'density': 1e-3
                })
    atoms.set_calculator(calc)
    try:
        atoms.get_potential_energy()
    except KohnShamConvergenceError:
        pass
    if calc.scf.converged:
        for calcp in calc_parms:
            calc.set(**calcp)
            try:
                calc.calculate(system_changes=[])
            except KohnShamConvergenceError:
                break
        if calc.scf.converged:
            calc.write(fname + '.gpw', mode='all')
Exemplo n.º 2
0
def gw_calc(kptsize=12, ecut=200.0, gwg_and_gw=False, gw_only=True):
    """Calculate the gw bandstructure"""

    calc = GPAW('gs.gpw', txt=None)
    kpts = {'size': (kptsize, kptsize, 1), 'gamma': True}

    calc.set(kpts=kpts, fixdensity=True, txt='gs_gw.txt')
    calc.get_potential_energy()
    calc.diagonalize_full_hamiltonian(ecut=ecut)
    calc.write('gs_gw_nowfs.gpw')
    calc.write('gs_gw.gpw', mode='all')
    lb, ub = get_bandrange(calc)

    calc = G0W0(calc='gs_gw.gpw',
                bands=(lb, ub),
                ecut=ecut,
                ecut_extrapolation=True,
                truncation='2D',
                nblocks=get_nblocks(world.size),
                q0_correction=True,
                filename='g0w0',
                restartfile='g0w0.tmp',
                savepckl=True)

    calc.calculate()
def descriptors(cif):
    f = open('a.cif', 'w')
    f.write(cif)
    f.flush()
    f.close

    a = read('a.cif')
    descriptors_below = []
    descriptors_above = []

    try:
        calc = GPAW(
            mode='lcao',
            xc='PBE',
            maxiter=1,
            # nbands=100,
            # parallel={'domain': 1, 'band': 1},
            # occupations=FermiDirac(width=0.01),
            convergence={'density': 1},
            kpts=[1, 1, 1],
            txt='gs.txt')

        # a.set_calculator(calc)
        calc.calculate(a)
        # a.get_potential_energy()
        ev = pd.DataFrame(calc.get_eigenvalues())
        ef = calc.get_fermi_level()
        ev_below = ev.loc[ev.values <= ef]
        ev_above = ev.loc[ev.values > ef]

        for e in ev_below.values.tolist()[::-1]:
            descriptors_below += e
        if len(ev_below) > 50:
            descriptors_below = descriptors_below[0:50]
        elif len(ev_below) < 50:
            for e in range(50 - len(ev_below)):
                descriptors_below += [0]
        descriptors_below = descriptors_below[::-1]

        for e in ev_above.values.tolist():
            descriptors_above += e
        if len(ev_above) > 50:
            descriptors_above = descriptors_above[0:50]
        elif len(ev_above) < 50:
            for e in range(50 - len(ev_above)):
                descriptors_above += [0]
    except Exception as e:
        print('Problem in material:', e)
    return descriptors_below + descriptors_above
Exemplo n.º 4
0
def calc_gw(mater, ecut=250, band_num=3):
    calc = GPAW(restart=gs_wfs(mater))
    ne = calc.get_number_of_electrons()
    nb = ne // 2
    bands = (nb - band_num, nb + band_num)
    del calc
    calc = G0W0(calc=gs_wfs(mater),
                bands=bands,
                ecut=ecut,
                ecut_extrapolation=True,
                truncation="2D",
                q0_correction=True,
                filename=os.path.join(data_path, mater, "g0w0"),
                restartfile=os.path.join(data_path, mater, "g0w0.tmp"),
                savepckl=True)
    calc.calculate()
Exemplo n.º 5
0
def calc_gw(mater, band_num=3):
    if not os.path.exists(es_wfs(mater)):
        calc_es(mater)
    calc = GPAW(restart=gs_wfs(mater))
    ne = calc.get_number_of_electrons()
    nb = int(ne // 2)
    bands = (nb - band_num, nb + band_num)
    print(bands)
    del calc
    calc = G0W0(
        calc=es_wfs(mater),
        nbands=nbs,
        bands=bands,
        nblocksmax=True,
        # ecut_extrapolation=True,
        truncation="2D",
        q0_correction=True,
        filename=os.path.join(data_path, mater, "g0w0"),
        restartfile=os.path.join(data_path, mater, "g0w0.tmp"),
        savepckl=True)
    calc.calculate()
Exemplo n.º 6
0
from gpaw.cluster import Cluster
from gpaw.test import equal

fname='H2_PBE.gpw'
fwfname='H2_wf_PBE.gpw'
txt = None

# write first if needed
try:
    c = GPAW(fname, txt=txt)
    c = GPAW(fwfname, txt=txt)
except:
    s = Cluster([Atom('H'), Atom('H', [0,0,1])])
    s.minimal_box(3.)
    c = GPAW(xc='PBE', h=.3, convergence={'density':1e-3, 'eigenstates':1e-3})
    c.calculate(s)
    c.write(fname)
    c.write(fwfname, 'all')

# full information
c = GPAW(fwfname, txt=txt)
E_PBE = c.get_potential_energy()
try: # number of iterations needed in restart
    niter_PBE = c.get_number_of_iterations()
except: pass
dE = c.get_xc_difference('TPSS')
E_1 = E_PBE + dE
print "E PBE, TPSS=", E_PBE, E_1

# no wfs
c = GPAW(fname, txt=txt)
ex = PointCharges()
ex.read('i' + fname)
ex.write('o' + fname)

convergence = {
    'eigenstates': 1.e-4 * 40 * 1.5**3,
    'density': 1.e-2,
    'energy': 0.1
}

# without potential
if True:
    if txt:
        print('\n################## no potential')
    c00 = GPAW(h=0.3, nbands=-1, convergence=convergence, txt=txt)
    c00.calculate(H2)
    eps00_n = c00.get_eigenvalues()

# 0 potential
if True:
    if txt:
        print('\n################## 0 potential')
    cp0 = ConstantPotential(0.0)
    c01 = GPAW(h=0.3,
               nbands=-2,
               external=cp0,
               convergence=convergence,
               txt=txt)
    c01.calculate(H2)

# 1 potential
from ase import Atoms
from gpaw import GPAW
from gpaw.lrtddft import LrTDDFT

# Na2 cluster
atoms = Atoms(symbols='Na2', 
              positions=[(0, 0, 0), (3.0, 0, 0)],
              pbc=False)
atoms.center(vacuum=6.0)

# Standard ground state calculation with empty states
calc = GPAW(nbands=100, h=0.4, setups={'Na': '1'})
atoms.set_calculator(calc)
energy = atoms.get_potential_energy()

calc.set(convergence={'bands' : 90}, 
         fixdensity=True,
         eigensolver='cg')
calc.calculate()

calc.write('na2_gs_casida.gpw', mode='all')

# Standard Casida calculation
calc = GPAW('na2_gs_casida.gpw')
istart = 0
jend = 90
lr = LrTDDFT(calc, xc='LDA', istart=istart, jend=jend)
lr.diagonalize()
lr.write('na2_lr.dat.gz')
Exemplo n.º 9
0
for atom in e_HOMO_cs.keys():
    e_ref = e_HOMO_cs[atom]
    # generate setup for the atom
    if rank == 0 and not setups.has_key(atom):
        g = Generator(atom, 'LB94', nofiles=True, txt=txt)
        g.run(**parameters[atom])
        setups[atom] = 1
    barrier()
    
    SS = Atoms([Atom(atom)], cell=(7, 7, 7), pbc=False)
    SS.center()
    c = GPAW(h=.3, xc='LB94', nbands=-2, txt=txt)
    if atom in ['Mg']:
        c.set(eigensolver='cg')
    c.calculate(SS)
    # find H**O energy
    eps_n = c.get_eigenvalues(kpt=0, spin=0) / 27.211
    f_n   = c.get_occupation_numbers(kpt=0, spin=0)
    for e, f in zip(eps_n, f_n):
        if f < 0.99:
            break
        e_homo = e
    e_homo = int( e_homo * 10000 + .5 ) / 10.
    diff = e_ref + e_homo
    print('%2s %8g %6.1f %4.1f' % (atom, e_ref, -e_homo, diff))
    assert abs(diff) < 7


# H**O energy in mHa and magn. mom. for open shell atoms
e_HOMO_os = { 'He': [851, 0], # added for cross check
Exemplo n.º 10
0
for atom in e_HOMO_cs.keys():
    e_ref = e_HOMO_cs[atom]
    # generate setup for the atom
    if rank == 0 and not setups.has_key(atom):
        g = Generator(atom, 'LB94', nofiles=True, txt=txt)
        g.run(**parameters[atom])
        setups[atom] = 1
    barrier()
    
    SS = Atoms([Atom(atom)], cell=(7, 7, 7), pbc=False)
    SS.center()
    c = GPAW(h=.3, xc='LB94', nbands=-2, txt=txt)
    if atom in ['Mg']:
        c.set(eigensolver='cg')
    c.calculate(SS)
    # find H**O energy
    eps_n = c.get_eigenvalues(kpt=0, spin=0) / 27.211
    f_n   = c.get_occupation_numbers(kpt=0, spin=0)
    for e, f in zip(eps_n, f_n):
        if f < 0.99:
            break
        e_homo = e
    e_homo = int( e_homo * 10000 + .5 ) / 10.
    diff = e_ref + e_homo
    print '%2s %8g %6.1f %4.1f' % (atom, e_ref, -e_homo, diff)
    assert abs(diff) < 7


# H**O energy in mHa and magn. mom. for open shell atoms
e_HOMO_os = { 'He': [851, 0], # added for cross check
Exemplo n.º 11
0
h=.4
q=3
spin=True

s = Atoms([Atom('Fe')])
s.center(vacuum=2.5)
convergence={'eigenstates':0.01, 'density':0.1, 'energy':0.1}

# use Hunds rules

c = GPAW(charge=q, h=h, nbands=5,
         hund=True,
         eigensolver='rmm-diis',
         occupations=FermiDirac(width=0.1),
         convergence=convergence
         )
c.calculate(s)
equal(c.get_magnetic_moment(0), 5, 0.1)

# set magnetic moment

mm = [5]
s.set_initial_magnetic_moments(mm)
c = GPAW(charge=q, h=h, nbands=5,
         occupations=FermiDirac(width=0.1, fixmagmom=True),
         convergence=convergence
         )
c.calculate(s)
equal(c.get_magnetic_moment(0), 5, 0.1)
Exemplo n.º 12
0
txt = 'mgga_sc.txt'

s = Cluster([Atom('H')])
s.minimal_box(4., h=h)
s.set_initial_magnetic_moments([1])
# see https://trac.fysik.dtu.dk/projects/gpaw/ticket/244
s.set_cell((8.400000, 8.400000, 8.400000))

c = GPAW(xc='TPSS',
         h=h,
         nbands=5,
         txt=txt,
         eigensolver='rmm-diis',
         fixmom=True,
         maxiter=300)
c.calculate(s)

cpbe = GPAW(xc='PBE',
            h=h,
            nbands=5,
            txt=txt,
            eigensolver='rmm-diis',
            fixmom=True,
            maxiter=300)
cpbe.calculate(s)
cpbe.set(xc='TPSS')
cpbe.calculate()

print("Energy difference",
      (cpbe.get_potential_energy() - c.get_potential_energy()))
equal(cpbe.get_potential_energy(), c.get_potential_energy(), 0.002)
Exemplo n.º 13
0
"""Test Hirshfeld for spin/no spin consitency"""
from ase import Atom
from gpaw import GPAW
from ase.parallel import parprint
from gpaw.analyse.hirshfeld import HirshfeldPartitioning
from gpaw import FermiDirac
from gpaw.cluster import Cluster
from gpaw.test import equal

h = 0.25
box = 3

atoms = Cluster()
atoms.append(Atom('H'))
atoms.minimal_box(box)

volumes = []
for spinpol in [False, True]:
    calc = GPAW(h=h,
                occupations=FermiDirac(0.1, fixmagmom=True),
                experimental={'niter_fixdensity': 2},
                spinpol=spinpol)
    calc.calculate(atoms)
    volumes.append(HirshfeldPartitioning(calc).get_effective_volume_ratios())
parprint(volumes)
equal(volumes[0][0], volumes[1][0], 4e-9)
Exemplo n.º 14
0
h = 0.4
box = 2
nbands = 4
txt = '-'
txt = None
np.set_printoptions(precision=3, suppress=True)

H2 = Cluster(molecule('H2'))
H2.minimal_box(box, h)

c1 = GPAW(h=h,
          txt=txt,
          eigensolver='dav',
          nbands=nbands,
          convergence={'eigenstates': nbands})
c1.calculate(H2)
lr1 = LrTDDFT(c1)

parprint('sanity --------')
ov = Overlap(c1).pseudo(c1)
parprint('pseudo(normalized):\n', ov)
ov = Overlap(c1).pseudo(c1, False)
parprint('pseudo(not normalized):\n', ov)
ov = Overlap(c1).full(c1)
parprint('full:\n', ov)
equal(ov[0], np.eye(ov[0].shape[0], dtype=ov.dtype), 1e-10)


def show(c2):
    c2.calculate(H2)
    ov = Overlap(c1).pseudo(c2)
Exemplo n.º 15
0
    # Wigner-Seitz ----------------------------------------

    if 1:
        ws = WignerSeitz(calc.density.finegd, mol, calc)

        vr = ws.get_effective_volume_ratios()
        parprint('Wigner-Seitz:', vr)
        if len(lastres):
            equal(vr, lastres.pop(0), 1.e-10)
        results.append(vr)

    return results

# calculate
parprint('fresh:')
mol = Cluster(molecule('H2O'))
mol.minimal_box(3, h=h)
calc = GPAW(nbands=6,
            h = h, 
            txt=None)
calc.calculate(mol)
calc.write(gpwname)
lastres = run()

# load previous calculation
parprint('reloaded:')
calc = GPAW(gpwname, txt=None)
mol = calc.get_atoms()
run(lastres)
Exemplo n.º 16
0
from gpaw.cluster import Cluster
from gpaw.test import equal

h=0.40
txt = None
txt = 'mgga_sc.txt'

s = Cluster([Atom('H')])
s.minimal_box(4., h=h)
s.set_initial_magnetic_moments([1])
# see https://trac.fysik.dtu.dk/projects/gpaw/ticket/244
s.set_cell((8.400000,8.400000,8.400000))

c = GPAW(xc='TPSS', h=h, nbands=5, txt=txt, 
         eigensolver='rmm-diis',
         fixmom=True,
         maxiter=300)
c.calculate(s)

cpbe = GPAW(xc='PBE', h=h, nbands=5, txt=txt,
            eigensolver='rmm-diis',
            fixmom=True,
            maxiter=300)
cpbe.calculate(s)
cpbe.set(xc='TPSS')
cpbe.calculate()

print "Energy difference", (cpbe.get_potential_energy() - 
                            c.get_potential_energy())
equal(cpbe.get_potential_energy(), c.get_potential_energy(), 0.002)
Exemplo n.º 17
0
from ase import Atoms
from gpaw import GPAW
from gpaw.lrtddft import LrTDDFT

# Na2 cluster
atoms = Atoms(symbols='Na2', positions=[(0, 0, 0), (3.0, 0, 0)], pbc=False)
atoms.center(vacuum=6.0)

# Standard ground state calculation with empty states
calc = GPAW(nbands=100, h=0.4, setups={'Na': '1'})
atoms.set_calculator(calc)
energy = atoms.get_potential_energy()

calc.set(convergence={'bands': 90}, fixdensity=True, eigensolver='cg')
calc.calculate()

calc.write('na2_gs_casida.gpw', mode='all')

# Standard Casida calculation
calc = GPAW('na2_gs_casida.gpw')
istart = 0
jend = 90
lr = LrTDDFT(calc, xc='LDA', istart=istart, jend=jend)
lr.diagonalize()
lr.write('na2_lr.dat.gz')
Exemplo n.º 18
0
    lr_vspin = LrTDDFT(calc, xc=xc, nspins=2)
    singlet, triplet = lr_vspin.singlets_triplets()
    lr_vspin.diagonalize()
    # the triplet is lower, so that the second is the first singlet
    # excited state
    t2 = lr_vspin[1]

    print 'with virtual/wo spin t2, t1=', t2.get_energy(), t1 .get_energy()
    equal(t1.get_energy(), t2.get_energy(), 5.e-7)

    if not load:
        c_spin = GPAW(xc='PBE', nbands=2, 
                      spinpol=True, parallel={'domain': world.size},
                      txt=txt)
        H2.set_calculator(c_spin)
        c_spin.calculate(H2)
##        c_spin.write('H2spin.gpw', 'all')
    else:
        c_spin = GPAW('H2spin.gpw', txt=txt)
    lr_spin = LrTDDFT(c_spin, xc=xc)
    lr_spin.diagonalize()
    for i in range(2):
        print 'i, real, virtual spin: ', i, lr_vspin[i], lr_spin[i]
        equal(lr_vspin[i].get_energy(), lr_spin[i].get_energy(), 5.e-6)

    # singlet/triplet separation
    precision = 1.e-5
    singlet.diagonalize()
    equal(singlet[0].get_energy(), lr_spin[1].get_energy(), precision)
    equal(singlet[0].get_oscillator_strength()[0],
          lr_spin[1].get_oscillator_strength()[0], precision)
Exemplo n.º 19
0
nbands = 4

unocc = True
load = False

# usual calculation
fname = 'Be2.gpw'
if not load:
    xco = HybridXC(xc)
    cocc = GPAW(h=0.3,
                eigensolver='rmm-diis',
                xc=xco,
                nbands=nbands,
                convergence={'eigenstates': 1e-4},
                txt=txt)
    cocc.calculate(loa)
else:
    cocc = GPAW(fname)
    cocc.converge_wave_functions()
fo_n = 1. * cocc.get_occupation_numbers()
eo_n = 1. * cocc.get_eigenvalues()

if unocc:
    # apply Fock opeartor also to unoccupied orbitals
    xcu = HybridXC(xc, unocc=True)
    cunocc = GPAW(h=0.3,
                  eigensolver='rmm-diis',
                  xc=xcu,
                  nbands=nbands,
                  convergence={'eigenstates': 1e-4},
                  txt=txt)
Exemplo n.º 20
0
    gd = lr.calculator.density.gd
    finegd = lr.calculator.density.finegd
    ddiff = gd.integrate(abs(den - den_vspin))
    parprint('   density integral, difference=',
             gd.integrate(den), gd.integrate(den_vspin), ddiff)
    parprint('   aed density integral',
             finegd.integrate(ex.get_all_electron_density() * Bohr**3),
             finegd.integrate(ex_vspin.get_all_electron_density() * Bohr**3))
    assert(ddiff < 1.e-4)

    if not load:
        c_spin = GPAW(xc='PBE', nbands=2, 
                      spinpol=True, parallel={'domain': world.size},
                      txt=txt)
        H2.set_calculator(c_spin)
        c_spin.calculate(H2)
##        c_spin.write('H2spin.gpw', 'all')
    else:
        c_spin = GPAW('H2spin.gpw', txt=txt)
    lr_spin = LrTDDFT(c_spin, xc=xc)
    lr_spin.diagonalize()
    for i in range(2):
        parprint('i, real, virtual spin: ', i, lr_vspin[i], lr_spin[i])
        equal(lr_vspin[i].get_energy(), lr_spin[i].get_energy(), 6.e-6)
        ex_vspin = ExcitedState(lr_vspin, i)
        den_vspin = ex_vspin.get_pseudo_density() * Bohr**3
        ex_spin = ExcitedState(lr_spin, i)
        den_spin = ex_spin.get_pseudo_density() * Bohr**3
        ddiff = gd.integrate(abs(den_vspin - den_spin))
        parprint('   density integral, difference=',
                 gd.integrate(den_vspin), gd.integrate(den_spin),
Exemplo n.º 21
0
        if len(lastres):
            equal(vr, lastres.pop(0), 1.e-10)
        results.append(vr)

    return results


mol = Cluster(molecule('H2O'))
mol.minimal_box(2.5, h=h)

# calculate
if 1:
    parprint('### fresh:')
    calc = GPAW(nbands=6, h=h, txt=None)
if 1:
    calc.calculate(mol)
    calc.write(gpwname)
    lastres = run()

# load previous calculation
if 1:
    parprint('### reloaded:')
    calc = GPAW(gpwname, txt=None)
    mol = calc.get_atoms()
    run(lastres)

# periodic modulo test
parprint('### periodic:')
mol.set_pbc(True)
mol.translate(-mol[0].position)
mol.translate([-1.e-24, 0, 0])
    )
    f.close()
world.barrier()

ex = PointCharges()
ex.read("i" + fname)
ex.write("o" + fname)

convergence = {"eigenstates": 1.0e-4 * 40 * 1.5 ** 3, "density": 1.0e-2, "energy": 0.1}

# without potential
if True:
    if txt:
        print("\n################## no potential")
    c00 = GPAW(h=0.3, nbands=-1, convergence=convergence, txt=txt)
    c00.calculate(H2)
    eps00_n = c00.get_eigenvalues()

# 0 potential
if True:
    if txt:
        print("\n################## 0 potential")
    cp0 = ConstantPotential(0.0)
    c01 = GPAW(h=0.3, nbands=-2, external=cp0, convergence=convergence, txt=txt)
    c01.calculate(H2)

# 1 potential
if True:
    if txt:
        print("################## 1 potential")
    cp1 = ConstantPotential(-1.0 / Hartree)
Exemplo n.º 23
0
loa = Atoms("Be2", [(0, 0, 0), (2.45, 0, 0)], cell=[5.9, 4.8, 5.0])
loa.center()

txt = None
xc = "PBE0"
nbands = 4

unocc = True
load = False

# usual calculation
fname = "Be2.gpw"
if not load:
    xco = HybridXC(xc)
    cocc = GPAW(h=0.3, eigensolver="rmm-diis", xc=xco, nbands=nbands, convergence={"eigenstates": 1e-4}, txt=txt)
    cocc.calculate(loa)
else:
    cocc = GPAW(fname)
    cocc.converge_wave_functions()
fo_n = 1.0 * cocc.get_occupation_numbers()
eo_n = 1.0 * cocc.get_eigenvalues()

if unocc:
    # apply Fock opeartor also to unoccupied orbitals
    xcu = HybridXC(xc, unocc=True)
    cunocc = GPAW(h=0.3, eigensolver="rmm-diis", xc=xcu, nbands=nbands, convergence={"eigenstates": 1e-4}, txt=txt)
    cunocc.calculate(loa)

    parprint("     HF occ          HF unocc      diff")
    parprint(
        "Energy %10.4f   %10.4f %10.4f"