| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# |
| 3 |
# Copyright (c) 2017, the cclib development team |
| 4 |
# |
| 5 |
# This file is part of cclib (http://cclib.github.io) and is distributed under |
| 6 |
# the terms of the BSD 3-Clause License. |
| 7 |
|
| 8 |
"""Test logfiles with (non)linear response output in cclib""" |
| 9 |
|
| 10 |
import os |
| 11 |
import unittest |
| 12 |
|
| 13 |
import numpy |
| 14 |
|
| 15 |
from skip import skipForParser |
| 16 |
|
| 17 |
__filedir__ = os.path.realpath(os.path.dirname(__file__)) |
| 18 |
|
| 19 |
|
| 20 |
class GenericPolarTest(unittest.TestCase): |
| 21 |
"""Generic static polarizability unittest""" |
| 22 |
|
| 23 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 24 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 25 |
def testshape(self): |
| 26 |
"""Is the dimension of the polarizability tensor 3 x 3?""" |
| 27 |
self.assertEqual(len(self.data.polarizabilities), 1) |
| 28 |
self.assertEqual(self.data.polarizabilities[0].shape, (3, 3)) |
| 29 |
|
| 30 |
|
| 31 |
class ReferencePolarTest(GenericPolarTest): |
| 32 |
"""Customized static polarizability unittest""" |
| 33 |
|
| 34 |
# Reference values are from DALTON2015/Trp_polar_abalnr.out |
| 35 |
isotropic = 74.12424 |
| 36 |
principal_components = [30.29431523, 91.5361917, 100.54220307] |
| 37 |
isotropic_delta = 0.01 |
| 38 |
principal_components_delta = 0.01 |
| 39 |
|
| 40 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 41 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 42 |
def testisotropic(self): |
| 43 |
"""Is the isotropic polarizability (average of the diagonal elements) |
| 44 |
+/- 0.01 from a reference? |
| 45 |
""" |
| 46 |
isotropic = numpy.average(numpy.diag(self.data.polarizabilities[0])) |
| 47 |
self.assertAlmostEqual(isotropic, self.isotropic, delta=self.isotropic_delta) |
| 48 |
|
| 49 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 50 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 51 |
def testprincomponents(self): |
| 52 |
"""Are each of the principal components (eigenvalues) of the |
| 53 |
polarizability tensor +/- 0.01 from a reference? |
| 54 |
""" |
| 55 |
principal_components = numpy.linalg.eigvalsh(self.data.polarizabilities[0]) |
| 56 |
for c in range(3): |
| 57 |
self.assertAlmostEqual(principal_components[c], |
| 58 |
self.principal_components[c], |
| 59 |
delta=self.principal_components_delta) |
| 60 |
|
| 61 |
|
| 62 |
if __name__=="__main__": |
| 63 |
|
| 64 |
import sys |
| 65 |
sys.path.insert(1, os.path.join(__filedir__, "..")) |
| 66 |
|
| 67 |
from test_data import DataSuite |
| 68 |
suite = DataSuite(['Polar']) |
| 69 |
suite.testall() |