| 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 single point time-dependent logfiles in cclib""" |
| 9 |
|
| 10 |
import os |
| 11 |
import unittest |
| 12 |
|
| 13 |
import numpy |
| 14 |
|
| 15 |
from skip import skipForParser |
| 16 |
|
| 17 |
|
| 18 |
__filedir__ = os.path.realpath(os.path.dirname(__file__)) |
| 19 |
|
| 20 |
|
| 21 |
class GenericTDTest(unittest.TestCase): |
| 22 |
"""Generic time-dependent HF/DFT unittest""" |
| 23 |
|
| 24 |
number = 5 |
| 25 |
expected_l_max = 41000 |
| 26 |
|
| 27 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 28 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 29 |
def testenergies(self): |
| 30 |
"""Is the l_max reasonable?""" |
| 31 |
|
| 32 |
self.assertEqual(len(self.data.etenergies), self.number) |
| 33 |
|
| 34 |
# Note that if all oscillator strengths are zero (like for triplets) |
| 35 |
# then this will simply pick out the first energy. |
| 36 |
idx_lambdamax = numpy.argmax(self.data.etoscs) |
| 37 |
self.assertAlmostEqual(self.data.etenergies[idx_lambdamax], self.expected_l_max, delta=5000) |
| 38 |
|
| 39 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 40 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 41 |
def testoscs(self): |
| 42 |
"""Is the maximum of etoscs in the right range?""" |
| 43 |
self.assertEqual(len(self.data.etoscs), self.number) |
| 44 |
self.assertAlmostEqual(max(self.data.etoscs), 0.67, delta=0.1) |
| 45 |
|
| 46 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 47 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 48 |
def testsecs(self): |
| 49 |
"""Is the sum of etsecs close to 1?""" |
| 50 |
self.assertEqual(len(self.data.etsecs), self.number) |
| 51 |
lowestEtrans = self.data.etsecs[numpy.argmin(self.data.etenergies)] |
| 52 |
sumofsec = sum([z*z for (x, y, z) in lowestEtrans]) |
| 53 |
self.assertAlmostEqual(sumofsec, 1.0, delta=0.16) |
| 54 |
|
| 55 |
@skipForParser('DALTON', 'This is true for calculations without symmetry, but not with?') |
| 56 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 57 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 58 |
def testsecs_transition(self): |
| 59 |
"""Is the lowest E transition from the HOMO or to the LUMO?""" |
| 60 |
lowestEtrans = self.data.etsecs[numpy.argmin(self.data.etenergies)] |
| 61 |
t = list(reversed(sorted([(c*c, s, e) for (s, e, c) in lowestEtrans]))) |
| 62 |
self.assertTrue(t[0][1][0] == self.data.homos[0] or |
| 63 |
t[0][2][0] == self.data.homos[0] + 1, t[0]) |
| 64 |
|
| 65 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 66 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 67 |
def testsymsnumber(self): |
| 68 |
"""Is the length of etsyms correct?""" |
| 69 |
self.assertEqual(len(self.data.etsyms), self.number) |
| 70 |
|
| 71 |
@skipForParser('ADF', 'etrotats are not yet implemented') |
| 72 |
@skipForParser('DALTON', 'etrotats are not yet implemented') |
| 73 |
@skipForParser('GAMESS', 'etrotats are not yet implemented') |
| 74 |
@skipForParser('GAMESSUK', 'etrotats are not yet implemented') |
| 75 |
@skipForParser('Jaguar', 'etrotats are not yet implemented') |
| 76 |
@skipForParser('QChem', 'Q-Chem cannot calculate rotatory strengths') |
| 77 |
def testrotatsnumber(self): |
| 78 |
"""Is the length of etrotats correct?""" |
| 79 |
self.assertEqual(len(self.data.etrotats), self.number) |
| 80 |
|
| 81 |
class ADFTDDFTTest(GenericTDTest): |
| 82 |
"""Customized time-dependent DFT unittest""" |
| 83 |
number = 5 |
| 84 |
|
| 85 |
def testsecs(self): |
| 86 |
"""Is the sum of etsecs close to 1?""" |
| 87 |
self.assertEqual(len(self.data.etsecs), self.number) |
| 88 |
lowestEtrans = self.data.etsecs[1] |
| 89 |
|
| 90 |
#ADF squares the etsecs |
| 91 |
sumofsec = sum([z for (x, y, z) in lowestEtrans]) |
| 92 |
self.assertAlmostEqual(sumofsec, 1.0, delta=0.16) |
| 93 |
|
| 94 |
|
| 95 |
class DALTONTDTest(GenericTDTest): |
| 96 |
"""Customized time-dependent HF/DFT unittest""" |
| 97 |
|
| 98 |
number = 20 |
| 99 |
|
| 100 |
|
| 101 |
class GaussianTDDFTTest(GenericTDTest): |
| 102 |
"""Customized time-dependent HF/DFT unittest""" |
| 103 |
|
| 104 |
expected_l_max = 48000 |
| 105 |
|
| 106 |
|
| 107 |
class GAMESSUSTDDFTTest(GenericTDTest): |
| 108 |
"""Customized time-dependent HF/DFT unittest""" |
| 109 |
number = 10 |
| 110 |
|
| 111 |
|
| 112 |
class JaguarTDDFTTest(GenericTDTest): |
| 113 |
"""Customized time-dependent HF/DFT unittest""" |
| 114 |
|
| 115 |
expected_l_max = 48000 |
| 116 |
|
| 117 |
def testoscs(self): |
| 118 |
"""Is the maximum of etoscs in the right range?""" |
| 119 |
self.assertEqual(len(self.data.etoscs), self.number) |
| 120 |
self.assertAlmostEqual(max(self.data.etoscs), 1.0, delta=0.2) |
| 121 |
|
| 122 |
|
| 123 |
class OrcaTDDFTTest(GenericTDTest): |
| 124 |
"""Customized time-dependent HF/DFT unittest""" |
| 125 |
|
| 126 |
number = 10 |
| 127 |
expected_l_max = 48000 |
| 128 |
|
| 129 |
def testoscs(self): |
| 130 |
"""Is the maximum of etoscs in the right range?""" |
| 131 |
self.assertEqual(len(self.data.etoscs), self.number) |
| 132 |
self.assertAlmostEqual(max(self.data.etoscs), .09, delta=0.01) |
| 133 |
|
| 134 |
|
| 135 |
class QChemTDDFTTest(GenericTDTest): |
| 136 |
"""Customized time-dependent HF/DFT unittest""" |
| 137 |
|
| 138 |
number = 10 |
| 139 |
expected_l_max = 48000 |
| 140 |
|
| 141 |
def testoscs(self): |
| 142 |
"""Is the maximum of etoscs in the right range?""" |
| 143 |
self.assertEqual(len(self.data.etoscs), self.number) |
| 144 |
self.assertAlmostEqual(max(self.data.etoscs), 0.9, delta=0.1) |
| 145 |
|
| 146 |
|
| 147 |
class GenericTDDFTtrpTest(GenericTDTest): |
| 148 |
"""Generic time-dependent HF/DFT (triplet) unittest""" |
| 149 |
|
| 150 |
number = 5 |
| 151 |
expected_l_max = 24500 |
| 152 |
|
| 153 |
def testoscs(self): |
| 154 |
"""Triplet excitations should be disallowed.""" |
| 155 |
self.assertEqual(len(self.data.etoscs), self.number) |
| 156 |
self.assertAlmostEqual(max(self.data.etoscs), 0.0, delta=0.01) |
| 157 |
|
| 158 |
|
| 159 |
class OrcaROCISTest(GenericTDTest): |
| 160 |
"""Customized test for ROCIS""" |
| 161 |
number = 57 |
| 162 |
expected_l_max = 2316970.8 |
| 163 |
n_spectra = 8 |
| 164 |
|
| 165 |
def testoscs(self): |
| 166 |
"""Is the maximum of etoscs in the right range?""" |
| 167 |
self.assertEqual(len(self.data.etoscs), self.number) |
| 168 |
self.assertAlmostEqual(max(self.data.etoscs), 0.015, delta=0.1) |
| 169 |
|
| 170 |
def testTransprop(self): |
| 171 |
"""Check the number of spectra parsed""" |
| 172 |
self.assertEqual(len(self.data.transprop), self.n_spectra) |
| 173 |
tddft_length = 'ABSORPTION SPECTRUM VIA TRANSITION ELECTRIC DIPOLE MOMENTS' |
| 174 |
self.assertIn(tddft_length, self.data.transprop) |
| 175 |
|
| 176 |
def testsymsnumber(self): |
| 177 |
"""ORCA ROCIS has no symmetry""" |
| 178 |
pass |
| 179 |
|
| 180 |
def testsecs(self): |
| 181 |
"""ROCIS does not form singly excited configurations (secs)""" |
| 182 |
pass |
| 183 |
|
| 184 |
def testsecs_transition(self): |
| 185 |
"""ROCIS does not form singly excited configurations (secs)""" |
| 186 |
pass |
| 187 |
|
| 188 |
def testrotatsnumber(self): |
| 189 |
"""ROCIS does not calculate rotatory strengths""" |
| 190 |
pass |
| 191 |
|
| 192 |
|
| 193 |
class OrcaROCIS40Test(OrcaROCISTest): |
| 194 |
"""Customized test for ROCIS""" |
| 195 |
# In ORCA 4.0, an additional spectrum ("COMBINED ELECTRIC DIPOLE + |
| 196 |
# MAGNETIC DIPOLE + ELECTRIC QUADRUPOLE SPECTRUM (Origin Independent, |
| 197 |
# Length Representation)") was present that is not in ORCA 4.1. |
| 198 |
n_spectra = 9 |
| 199 |
|
| 200 |
|
| 201 |
if __name__ =="__main__": |
| 202 |
|
| 203 |
import sys |
| 204 |
sys.path.insert(1, os.path.join(__filedir__, "..")) |
| 205 |
|
| 206 |
from test_data import DataSuite |
| 207 |
suite = DataSuite(['TD']) |
| 208 |
suite.testall() |