Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_hessian(self):
for calc in [{(1, 1): LennardJonesQuadratic(1, 1, 3), (1, 2): LennardJonesQuadratic(1.5, 0.8, 2.4), (2, 2): LennardJonesQuadratic(0.5, 0.88, 2.64)}]:
atoms = io.read("KA256_Min.xyz")
atoms.center(vacuum=5.0)
b = calculator.PairPotential(calc)
H_analytical = b.calculate_hessian_matrix(atoms, "dense")
# Numerical
ph = Phonons(atoms, b, supercell=(1, 1, 1), delta=0.001)
ph.run()
ph.read(acoustic=False)
ph.clean()
H_numerical = ph.get_force_constant()[0, :, :]
self.assertArrayAlmostEqual(H_analytical, H_numerical, tol=0.03)
###
def test_symmetry(self):
for calc in [{(1, 1): LennardJonesQuadratic(1, 1, 3), (1, 2): LennardJonesQuadratic(1.5, 0.8, 2.4), (2, 2): LennardJonesQuadratic(0.5, 0.88, 2.64)}]:
a = io.read('KA256_Min.xyz')
a.center(vacuum=5.0)
b = calculator.PairPotential(calc)
H = b.calculate_hessian_matrix(a, "dense")
self.assertArrayAlmostEqual(np.sum(np.abs(H-H.T)), 0, tol=0)
def test_forces(self):
for calc in [PairPotential({(1, 1): LennardJonesQuadratic(1, 1, 3), (1, 2): LennardJonesQuadratic(1.5, 0.8, 2.4), (2, 2): LennardJonesQuadratic(0.5, 0.88, 2.64)})]:
a = io.read('KA256.xyz')
a.center(vacuum=5.0)
a.set_calculator(calc)
f = a.get_forces()
fn = calc.calculate_numerical_forces(a, d=0.0001)
self.assertArrayAlmostEqual(f, fn, tol=self.tol)