Ejemplo n.º 1
0
        em = f(rc)
        R_pv[0, v] += eps
        F = -(ep - em) / (2 * eps) * h**3
        equal(F, -F_pv[0, v], 1e-9)

# High-level test:
lih = Atoms('LiH')
lih[1].y += 1.64
lih.center(vacuum=3)

pos = lih.cell.sum(axis=0)
print(pos)
pc = PointChargePotential([-1.0], [pos])
lih.calc = GPAW(external=pc, txt='lih-pc.txt')
f1 = lih.get_forces()
fpc1 = pc.get_forces(lih.calc)
print(fpc1)
print(fpc1 + f1.sum(0))

f2 = [[numeric_force(lih, a, v) for v in range(3)] for a in range(2)]
print(f1)
print(f1 - f2)
assert abs(f1 - f2).max() < 2e-3

x = 0.0001
for v in range(3):
    pos[v] += x
    pc.set_positions([pos])
    ep = lih.get_potential_energy()
    pos[v] -= 2 * x
    pc.set_positions([pos])
Ejemplo n.º 2
0
calc = GPAW(nbands=1, h=0.2, charge=1, txt='H.txt')
H.set_calculator(calc)
e0 = H.get_potential_energy()
assert abs(e0 + calc.get_reference_energy()) < 0.014

# Test the point charge potential with a smooth cutoff:
pcp = PointChargePotential([-1], rc2=5.5, width=1.5)
calc.set(external=pcp)
E = []
F = []
D = np.linspace(2, 6, 30)
for d in D:
    pcp.set_positions([[a / 2, a / 2, a / 2 + d]])
    e = H.get_potential_energy() - e0
    f1 = H.get_forces()
    f2 = pcp.get_forces(calc)
    eref = -1 / d * Bohr * Hartree
    print(d, e, eref, abs(f1 + f2).max())
    if d < 4.0:
        error = e + 1 / d * Bohr * Hartree
        assert abs(error) < 0.01, error
    assert abs(f1 + f2).max() < 0.01
    E.append(e)
    F.append(f1[0, 2])

E = np.array(E)
FF = (E[2:] - E[:-2]) / (D[2] - D[0])  # numerical force
print(abs(F[1:-1] - FF).max())
assert abs(F[1:-1] - FF).max() < 0.1

if not True: