| 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 unrestrictied single point logfiles in cclib""" |
| 9 |
|
| 10 |
import os |
| 11 |
import unittest |
| 12 |
|
| 13 |
import numpy |
| 14 |
|
| 15 |
from skip import skipForParser |
| 16 |
from skip import skipForLogfile |
| 17 |
|
| 18 |
|
| 19 |
__filedir__ = os.path.realpath(os.path.dirname(__file__)) |
| 20 |
|
| 21 |
|
| 22 |
class GenericSPunTest(unittest.TestCase): |
| 23 |
"""Generic unrestricted single point unittest""" |
| 24 |
|
| 25 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 26 |
def testnatom(self): |
| 27 |
"""Is the number of atoms equal to 20?""" |
| 28 |
self.assertEqual(self.data.natom, 20) |
| 29 |
|
| 30 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 31 |
def testatomnos(self): |
| 32 |
"""Are the atomnos correct?""" |
| 33 |
self.assertTrue(numpy.alltrue([numpy.issubdtype(atomno, numpy.signedinteger) |
| 34 |
for atomno in self.data.atomnos])) |
| 35 |
self.assertEqual(self.data.atomnos.shape, (20,) ) |
| 36 |
self.assertEqual(sum(self.data.atomnos==6) + sum(self.data.atomnos==1), 20) |
| 37 |
|
| 38 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 39 |
def testatomcoords(self): |
| 40 |
"""Are the dimensions of atomcoords 1 x natom x 3?""" |
| 41 |
self.assertEqual(self.data.atomcoords.shape,(1,self.data.natom,3)) |
| 42 |
|
| 43 |
@skipForParser('Jaguar', 'Data file does not contain enough information') |
| 44 |
def testdimmocoeffs(self): |
| 45 |
"""Are the dimensions of mocoeffs equal to 2 x nmo x nbasis?""" |
| 46 |
if hasattr(self.data, "mocoeffs"): |
| 47 |
self.assertIsInstance(self.data.mocoeffs, list) |
| 48 |
self.assertEqual(len(self.data.mocoeffs), 2) |
| 49 |
self.assertEqual(self.data.mocoeffs[0].shape, |
| 50 |
(self.data.nmo, self.data.nbasis)) |
| 51 |
self.assertEqual(self.data.mocoeffs[1].shape, |
| 52 |
(self.data.nmo, self.data.nbasis)) |
| 53 |
|
| 54 |
@skipForParser('Jaguar', 'Data file does not contain enough information') |
| 55 |
@skipForParser('DALTON', 'mocoeffs not implemented yet') |
| 56 |
def testfornsoormo(self): |
| 57 |
"""Do we have NSOs or MOs?""" |
| 58 |
self.assertTrue( |
| 59 |
hasattr(self.data, "nsocoeffs") or hasattr(self.data, "mocoeffs") |
| 60 |
) |
| 61 |
|
| 62 |
def testdimnsoccnos(self): |
| 63 |
"""Are the dimensions of nsooccnos equal to 2 x nmo?""" |
| 64 |
if hasattr(self.data, "nsooccnos"): |
| 65 |
self.assertIsInstance(self.data.nsooccnos, list) |
| 66 |
self.assertIsInstance(self.data.nsooccnos[0], list) |
| 67 |
self.assertIsInstance(self.data.nsooccnos[1], list) |
| 68 |
self.assertEqual(len(self.data.nsooccnos), 2) |
| 69 |
self.assertEqual(len(self.data.nsooccnos[0]), self.data.nmo) |
| 70 |
self.assertEqual(len(self.data.nsooccnos[1]), self.data.nmo) |
| 71 |
|
| 72 |
def testdimnsocoeffs(self): |
| 73 |
"""Are the dimensions of nsocoeffs equal to 2 x nmo x nmo?""" |
| 74 |
if hasattr(self.data, "nsocoeffs"): |
| 75 |
self.assertIsInstance(self.data.nsocoeffs, list) |
| 76 |
self.assertIsInstance(self.data.nsocoeffs[0], numpy.ndarray) |
| 77 |
self.assertIsInstance(self.data.nsocoeffs[1], numpy.ndarray) |
| 78 |
self.assertEqual(len(self.data.nsocoeffs), 2) |
| 79 |
self.assertEqual(self.data.nsocoeffs[0].shape, (self.data.nmo, self.data.nmo)) |
| 80 |
self.assertEqual(self.data.nsocoeffs[1].shape, (self.data.nmo, self.data.nmo)) |
| 81 |
|
| 82 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 83 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 84 |
def testcharge_and_mult(self): |
| 85 |
"""Are the charge and multiplicity correct?""" |
| 86 |
self.assertEqual(self.data.charge, 1) |
| 87 |
self.assertEqual(self.data.mult, 2) |
| 88 |
|
| 89 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 90 |
def testhomos(self): |
| 91 |
"""Are the homos correct?""" |
| 92 |
msg = "%s != array([34,33],'i')" % numpy.array_repr(self.data.homos) |
| 93 |
numpy.testing.assert_array_equal(self.data.homos, numpy.array([34,33],"i"), msg) |
| 94 |
|
| 95 |
def testmoenergies(self): |
| 96 |
"""Are the dims of the moenergies equals to 2 x nmo?""" |
| 97 |
if hasattr(self.data, "moenergies"): |
| 98 |
self.assertEqual(len(self.data.moenergies), 2) |
| 99 |
self.assertEqual(len(self.data.moenergies[0]), self.data.nmo) |
| 100 |
self.assertEqual(len(self.data.moenergies[1]), self.data.nmo) |
| 101 |
|
| 102 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 103 |
@skipForParser('Molpro', '?') |
| 104 |
@skipForParser('ORCA', 'ORCA has no support for symmetry yet') |
| 105 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 106 |
def testmosyms(self): |
| 107 |
"""Are the dims of the mosyms equals to 2 x nmo?""" |
| 108 |
shape = (len(self.data.mosyms), len(self.data.mosyms[0])) |
| 109 |
self.assertEqual(shape, (2, self.data.nmo)) |
| 110 |
|
| 111 |
|
| 112 |
class GenericROSPTest(GenericSPunTest): |
| 113 |
"""Customized restricted open-shell single point unittest""" |
| 114 |
|
| 115 |
@skipForParser('DALTON', 'mocoeffs not implemented yet') |
| 116 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 117 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 118 |
def testdimmocoeffs(self): |
| 119 |
"""Are the dimensions of mocoeffs equal to 1 x nmo x nbasis?""" |
| 120 |
self.assertEqual(type(self.data.mocoeffs), type([])) |
| 121 |
self.assertEqual(len(self.data.mocoeffs), 1) |
| 122 |
self.assertEqual(self.data.mocoeffs[0].shape, |
| 123 |
(self.data.nmo, self.data.nbasis)) |
| 124 |
|
| 125 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 126 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 127 |
def testhomos(self): |
| 128 |
"""Are the HOMO indices equal to 34 and 33 (one more alpha electron |
| 129 |
than beta electron)? |
| 130 |
""" |
| 131 |
msg = "%s != array([34, 33], 'i')" % numpy.array_repr(self.data.homos) |
| 132 |
numpy.testing.assert_array_equal(self.data.homos, numpy.array([34, 33], "i"), msg) |
| 133 |
|
| 134 |
@skipForParser('QChem', 'prints 2 sets of different MO energies?') |
| 135 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 136 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 137 |
def testmoenergies(self): |
| 138 |
"""Are the dims of the moenergies equals to 1 x nmo?""" |
| 139 |
self.assertEqual(len(self.data.moenergies), 1) |
| 140 |
self.assertEqual(len(self.data.moenergies[0]), self.data.nmo) |
| 141 |
|
| 142 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 143 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 144 |
def testmosyms(self): |
| 145 |
"""Are the dims of the mosyms equals to 1 x nmo?""" |
| 146 |
shape = (len(self.data.mosyms), len(self.data.mosyms[0])) |
| 147 |
self.assertEqual(shape, (1, self.data.nmo)) |
| 148 |
|
| 149 |
|
| 150 |
class GamessUK70SPunTest(GenericSPunTest): |
| 151 |
"""Customized unrestricted single point unittest""" |
| 152 |
|
| 153 |
def testdimmocoeffs(self): |
| 154 |
"""Are the dimensions of mocoeffs equal to 2 x (homos+6) x nbasis?""" |
| 155 |
|
| 156 |
self.assertEqual(type(self.data.mocoeffs), type([])) |
| 157 |
self.assertEqual(len(self.data.mocoeffs), 2) |
| 158 |
|
| 159 |
# This is only an issue in version 7.0 (and before?), since in the version 8.0 |
| 160 |
# logfile all eigenvectors are happily printed. |
| 161 |
shape_alpha = (self.data.homos[0]+6, self.data.nbasis) |
| 162 |
shape_beta = (self.data.homos[1]+6, self.data.nbasis) |
| 163 |
self.assertEqual(self.data.mocoeffs[0].shape, shape_alpha) |
| 164 |
self.assertEqual(self.data.mocoeffs[1].shape, shape_beta) |
| 165 |
|
| 166 |
def testnooccnos(self): |
| 167 |
"""Are natural orbital occupation numbers the right size?""" |
| 168 |
self.assertEqual(self.data.nooccnos.shape, (self.data.nmo, )) |
| 169 |
|
| 170 |
|
| 171 |
class GamessUK80SPunTest(GenericSPunTest): |
| 172 |
"""Customized unrestricted single point unittest""" |
| 173 |
|
| 174 |
def testnooccnos(self): |
| 175 |
"""Are natural orbital occupation numbers the right size?""" |
| 176 |
self.assertEqual(self.data.nooccnos.shape, (self.data.nmo, )) |
| 177 |
|
| 178 |
|
| 179 |
class GaussianSPunTest(GenericSPunTest): |
| 180 |
"""Customized unrestricted single point unittest""" |
| 181 |
|
| 182 |
def testatomnos(self): |
| 183 |
"""Does atomnos have the right dimension (20)?""" |
| 184 |
size = len(self.data.atomnos) |
| 185 |
self.assertEqual(size, 20) |
| 186 |
|
| 187 |
|
| 188 |
class JaguarSPunTest(GenericSPunTest): |
| 189 |
"""Customized unrestricted single point unittest""" |
| 190 |
|
| 191 |
def testmoenergies(self): |
| 192 |
"""Are the dims of the moenergies equal to 2 x homos+11?""" |
| 193 |
self.assertEqual(len(self.data.moenergies), 2) |
| 194 |
self.assertEqual(len(self.data.moenergies[0]), self.data.homos[0]+11) |
| 195 |
self.assertEqual(len(self.data.moenergies[1]), self.data.homos[1]+11) |
| 196 |
|
| 197 |
def testmosyms(self): |
| 198 |
"""Are the dims of the mosyms equals to 2 x nmo?""" |
| 199 |
shape0 = (len(self.data.mosyms), len(self.data.mosyms[0])) |
| 200 |
shape1 = (len(self.data.mosyms), len(self.data.mosyms[1])) |
| 201 |
self.assertEqual(shape0, (2, self.data.homos[0]+11)) |
| 202 |
self.assertEqual(shape1, (2, self.data.homos[1]+11)) |
| 203 |
|
| 204 |
|
| 205 |
if __name__=="__main__": |
| 206 |
|
| 207 |
import sys |
| 208 |
sys.path.insert(1, os.path.join(__filedir__, "..")) |
| 209 |
|
| 210 |
from test_data import DataSuite |
| 211 |
suite = DataSuite(['SPun']) |
| 212 |
suite.testall() |