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