def test_get_dQ(self): self.assertEqual(get_dQ(self.gnd_test, self.gnd_test), 0.) self.assertEqual(get_dQ(self.exd_test, self.exd_test), 0.) self.assertEqual(get_dQ(self.gnd_real, self.gnd_real), 0.) self.assertEqual(get_dQ(self.exd_real, self.exd_real), 0.) self.assertAlmostEqual(get_dQ(self.gnd_test, self.exd_test), 0.86945, places=4) self.assertAlmostEqual(get_dQ(self.gnd_real, self.exd_real), 1.68587, places=4)
def test_get_Q_from_struct(self): q = get_Q_from_struct(self.gnd_test, self.exd_test, self.sct_test) self.assertAlmostEqual(q, 0.5 * 0.86945, places=4) q = get_Q_from_struct(self.gnd_real, self.exd_real, str(TEST_FILES / 'POSCAR.C0.gz')) self.assertAlmostEqual(q, 0., places=4) gs, es = get_cc_structures(self.gnd_real, self.exd_real, np.linspace(-0.5, 0.5, 100), remove_zero=False) Q = 1.68587 * np.linspace(-0.5, 0.5, 100) for s, q in zip(gs, Q): tq = get_Q_from_struct(self.gnd_real, self.exd_real, s) self.assertAlmostEqual(tq, q, places=4) for s, q in zip(es, Q + 1.68587): tq = get_Q_from_struct(self.gnd_real, self.exd_real, s) self.assertAlmostEqual(tq, q, places=4) # test when one of the coordinates stays the same sg = pmg.Structure(np.eye(3), ['H'], [[0.0, 0.0, 0.0]]) sq = pmg.Structure(np.eye(3), ['H'], [[0.1, 0.0, 0.1]]) se = pmg.Structure(np.eye(3), ['H'], [[0.2, 0.0, 0.2]]) dQ = get_dQ(sg, se) self.assertAlmostEqual(get_Q_from_struct(sg, se, sq)/dQ, 0.5)