예제 #1
0
def test_ts09():
    from ase import io
    from ase.calculators.vdwcorrection import vdWTkatchenko09prl
    from ase.calculators.emt import EMT
    from ase.build import bulk

    # fake objects for the test
    class FakeHirshfeldPartitioning:
        def __init__(self, calculator):
            self.calculator = calculator

        def initialize(self):
            pass

        def get_effective_volume_ratios(self):
            return [1]

        def get_calculator(self):
            return self.calculator

    class FakeDFTcalculator(EMT):
        def get_xc_functional(self):
            return 'PBE'

    a = 4.05  # Angstrom lattice spacing
    al = bulk('Al', 'fcc', a=a)

    cc = FakeDFTcalculator()
    hp = FakeHirshfeldPartitioning(cc)
    c = vdWTkatchenko09prl(hp, [3])
    al.set_calculator(c)
    al.get_potential_energy()

    fname = 'out.traj'
    al.write(fname)

    # check that the output exists
    io.read(fname)
    # maybe assert something about what we just read?

    p = io.read(fname).get_calculator().parameters
    p['calculator']
    p['xc']
    p['uncorrected_energy']
예제 #2
0
    print >> f, molecule,
    ss = Cluster(Atoms(data[molecule]['symbols'],
		      data[molecule]['positions']))
    # split the structures
    s1 = ss.find_connected(0)
    s2 = ss.find_connected(-1)
    assert(len(ss) == len(s1) + len(s2))
    if xc == 'TS09' or xc == 'TPSS' or xc == 'M06L':
	c = GPAW(xc='PBE', h=h, nbands=-6, occupations=FermiDirac(width=0.1))
    else:
	c = GPAW(xc=xc, h=h, nbands=-6, occupations=FermiDirac(width=0.1))
    E = []
    for s in [s1, s2, ss]:
	s.set_calculator(c)
	s.minimal_box(box, h=h)
	if xc == 'TS09':
	    s.get_potential_energy()
	    cc = vdWTkatchenko09prl(HirshfeldPartitioning(c),
				    vdWradii(s.get_chemical_symbols(), 'PBE'))
	    s.set_calculator(cc)
	if xc == 'TPSS' or xc == 'M06L':
	    ene = s.get_potential_energy()
	    ene += c.get_xc_difference(xc)
	    E.append(ene)
	else:
	    E.append(s.get_potential_energy())
    print >> f, E[0], E[1], E[2],
    print >> f, E[0] + E[1] - E[2]
    f.flush()
f.close()
예제 #3
0
    # split the structures
    s1 = ss.find_connected(0)
    s2 = ss.find_connected(-1)
    assert len(ss) == len(s1) + len(s2)

    c = GPAW(xc='PBE', h=h, nbands=-6,
             occupations=FermiDirac(width=0.1), txt=None)
    cdf = GPAW(xc='vdW-DF', h=h, nbands=-6, occupations=FermiDirac(width=0.1),
               txt=None)

    for s in [s1, s2, ss]:
        s.set_calculator(c)
        s.minimal_box(box, h=h)
        Energy['PBE'].append(s.get_potential_energy())
        cc = vdWTkatchenko09prl(HirshfeldPartitioning(c),
                                vdWradii(s.get_chemical_symbols(), 'PBE'))
        s.set_calculator(cc)
        Energy['TS09'].append(s.get_potential_energy())

        s.set_calculator(cdf)
        Energy['vdW-DF'].append(s.get_potential_energy())

    parprint('Coupled cluster binding energy',
             -data[molecule]['interaction energy CC'] * 1000, 'meV')
    for xc in ['PBE', 'vdW-DF', 'TS09']:
        ene = Energy[xc]
#        print xc, 'energies', ene
        parprint(xc, 'binding energy',
                 (ene[0] + ene[1] - ene[2]) * 1000, 'meV')
예제 #4
0
    return q_a


# spin unpolarized

if 1:
    out_traj = 'LiH.traj'
    out_txt = 'LiH.txt'

    cc = GPAW(h=h, xc='PBE', txt=out_txt)

    # this is needed to initialize txt output
    cc.initialize(s)

    hp = HirshfeldPartitioning(cc)
    c = vdWTkatchenko09prl(hp, vdWradii(s.get_chemical_symbols(), 'PBE'))
    s.set_calculator(c)
    E = s.get_potential_energy()
    F_ac = s.get_forces()
    s.write(out_traj)
    q_a = print_charge_and_check(hp)

    barrier()

    # test I/O, accuracy due to text output
    accuracy = 1.e-5
    for fname in [out_traj, out_txt]:
        print(fname)
        s_out = ase.io.read(fname)
        print(s_out.calc)
        equal(s_out.get_potential_energy(), E, accuracy)