| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# |
| 3 |
# Copyright (c) 2018, 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 configuration interaction (CI) logfiles 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 GenericCISTest(unittest.TestCase): |
| 21 |
"""Generic CIS(RHF)/STO-3G water unittest""" |
| 22 |
|
| 23 |
nstates = 5 |
| 24 |
|
| 25 |
# First four singlet/triplet state excitation energies [wavenumber]. |
| 26 |
# Based on output in GAMESS test. |
| 27 |
etenergies0 = numpy.array([98614.56, 114906.59, 127948.12, 146480.64]) |
| 28 |
etenergies1 = numpy.array([82085.34, 98999.11, 104077.89, 113978.37]) |
| 29 |
|
| 30 |
# First four singlet/triplet state excitation orbitals and coefficients. |
| 31 |
# Tuples: (from MO, to MO, coefficient) - don't need spin indices. |
| 32 |
# Based on output in GAMESS test (using the "dets" algorithm). |
| 33 |
# Note that only coefficients larger than 0.1 are included here, as |
| 34 |
# the Gaussian test does not contain smaller ones. |
| 35 |
# The simple example of water should yield the same first 4 states in all programs. |
| 36 |
# Note that the GAMESS test "water_cis_dets" calculates also triplet states, |
| 37 |
# but the resulting transition dipoles and oscillator strengths are not correct |
| 38 |
# and this file is not tested here (although it probably should be). |
| 39 |
etsecs0 = [ [(4, 5, -1.0)], |
| 40 |
[(4, 6, -1.0)], |
| 41 |
[(3, 5, 0.96689)], |
| 42 |
[(2, 5, 0.4407), (3, 6, 0.89770)] ] |
| 43 |
etsecs1 = [ [(4, 5, 1.0)], |
| 44 |
[(2, 6, -0.231), (3, 5, -0.9676)], |
| 45 |
[(4, 6, 1.0)], |
| 46 |
[(2, 5, -0.536), (3, 6, -0.843)] ] |
| 47 |
|
| 48 |
etsecs_precision = 0.0005 |
| 49 |
|
| 50 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 51 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 52 |
def testetenergiesvalues(self): |
| 53 |
""" Are etenergies within 50 wavenumbers of the correct values?""" |
| 54 |
indices0 = [i for i in range(self.nstates) if self.data.etsyms[i][0] == "S"] |
| 55 |
indices1 = [i for i in range(self.nstates) if self.data.etsyms[i][0] == "T"] |
| 56 |
singlets = [self.data.etenergies[i] for i in indices0] |
| 57 |
triplets = [self.data.etenergies[i] for i in indices1] |
| 58 |
# All programs do singlets. |
| 59 |
singletdiff = singlets[:4] - self.etenergies0 |
| 60 |
self.assertTrue(numpy.alltrue(singletdiff < 50)) |
| 61 |
# Not all programs do triplets (i.e. Jaguar). |
| 62 |
if len(triplets) >= 4: |
| 63 |
tripletdiff = triplets[:4] - self.etenergies1 |
| 64 |
self.assertTrue(numpy.alltrue(tripletdiff < 50)) |
| 65 |
|
| 66 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 67 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 68 |
def testsecs(self): |
| 69 |
"""Is the sum of etsecs close to 1?""" |
| 70 |
etsec = self.data.etsecs[2] # Pick one with several contributors |
| 71 |
sumofsec = sum([z*z for (x, y, z) in etsec]) |
| 72 |
self.assertAlmostEqual(sumofsec, 1.0, delta=0.02) |
| 73 |
|
| 74 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 75 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 76 |
def testetsecsvalues(self): |
| 77 |
""" Are etsecs correct and coefficients close to the correct values?""" |
| 78 |
indices0 = [i for i in range(self.nstates) if self.data.etsyms[i][0] == "S"] |
| 79 |
indices1 = [i for i in range(self.nstates) if self.data.etsyms[i][0] == "T"] |
| 80 |
singlets = [self.data.etsecs[i] for i in indices0] |
| 81 |
triplets = [self.data.etsecs[i] for i in indices1] |
| 82 |
# All programs do singlets. |
| 83 |
for i in range(4): |
| 84 |
for exc in self.etsecs0[i]: |
| 85 |
found = False |
| 86 |
for s in singlets[i]: |
| 87 |
if s[0][0] == exc[0] and s[1][0] == exc[1]: |
| 88 |
found = True |
| 89 |
self.assertAlmostEqual(abs(s[2]), abs(exc[2]), delta=self.etsecs_precision) |
| 90 |
if not found: |
| 91 |
self.fail("Excitation %i->%s not found (singlet state %i)" %(exc[0], exc[1], i)) |
| 92 |
# Not all programs do triplets (i.e. Jaguar). |
| 93 |
if len(triplets) >= 4: |
| 94 |
for i in range(4): |
| 95 |
for exc in self.etsecs1[i]: |
| 96 |
found = False |
| 97 |
for s in triplets[i]: |
| 98 |
if s[0][0] == exc[0] and s[1][0] == exc[1]: |
| 99 |
found = True |
| 100 |
self.assertAlmostEqual(abs(s[2]), abs(exc[2]), delta=self.etsecs_precision) |
| 101 |
if not found: |
| 102 |
self.fail("Excitation %i->%s not found (triplet state %i)" %(exc[0], exc[1], i)) |
| 103 |
|
| 104 |
|
| 105 |
class GAMESSCISTest(GenericCISTest): |
| 106 |
"""Customized CIS(RHF)/STO-3G water unittest""" |
| 107 |
|
| 108 |
def testnocoeffs(self): |
| 109 |
"""Are natural orbital coefficients the right size?""" |
| 110 |
self.assertEqual(self.data.nocoeffs.shape, (self.data.nmo, self.data.nbasis)) |
| 111 |
|
| 112 |
def testnooccnos(self): |
| 113 |
"""Are natural orbital occupation numbers the right size?""" |
| 114 |
self.assertEqual(self.data.nooccnos.shape, (self.data.nmo, )) |
| 115 |
|
| 116 |
|
| 117 |
class GaussianCISTest(GenericCISTest): |
| 118 |
"""Customized CIS(RHF)/STO-3G water unittest""" |
| 119 |
nstates = 10 |
| 120 |
|
| 121 |
def testnocoeffs(self): |
| 122 |
"""Are natural orbital coefficients the right size?""" |
| 123 |
self.assertEqual(self.data.nocoeffs.shape, (self.data.nmo, self.data.nbasis)) |
| 124 |
|
| 125 |
def testnooccnos(self): |
| 126 |
"""Are natural orbital occupation numbers the right size?""" |
| 127 |
self.assertEqual(self.data.nooccnos.shape, (self.data.nmo, )) |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
class Jaguar83CISTest(GenericCISTest): |
| 132 |
"""Customized CIS(RHF)/STO-3G water unittest""" |
| 133 |
|
| 134 |
# The Jaguar8.3 job was created using 6-31G instead of STO-3G. |
| 135 |
etsecs0 = [ [(4, 5, 0.99186)], |
| 136 |
[(4, 6, -0.98594)], |
| 137 |
[(3, 5, -0.98321)], |
| 138 |
[(2, 5, 0.19240), (3, 6, -0.97090)] ] |
| 139 |
etsecs1 = [ [(4, 5, 1.0)], |
| 140 |
[(2, 6, -0.231), (3, 5, -0.9676)], |
| 141 |
[(4, 6, 1.0)], |
| 142 |
[(2, 5, -0.536), (3, 6, -0.843)] ] |
| 143 |
|
| 144 |
|
| 145 |
class QChemCISTest(GenericCISTest): |
| 146 |
"""Customized CIS(RHF)/STO-3G water unittest""" |
| 147 |
nstates = 10 |
| 148 |
|
| 149 |
|
| 150 |
if __name__=="__main__": |
| 151 |
|
| 152 |
import sys |
| 153 |
sys.path.insert(1, os.path.join(__filedir__, "..")) |
| 154 |
|
| 155 |
from test_data import DataSuite |
| 156 |
suite = DataSuite(['CI']) |
| 157 |
suite.testall() |