| 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 logfiles with vibration output in cclib""" |
| 9 |
|
| 10 |
import os |
| 11 |
import unittest |
| 12 |
|
| 13 |
from skip import skipForParser |
| 14 |
|
| 15 |
|
| 16 |
__filedir__ = os.path.realpath(os.path.dirname(__file__)) |
| 17 |
|
| 18 |
|
| 19 |
class GenericIRTest(unittest.TestCase): |
| 20 |
"""Generic vibrational frequency unittest""" |
| 21 |
|
| 22 |
# Unit tests should normally give this value for the largest IR intensity. |
| 23 |
max_IR_intensity = 100 |
| 24 |
|
| 25 |
def setUp(self): |
| 26 |
"""Initialize the number of vibrational frequencies on a per molecule basis""" |
| 27 |
self.numvib = 3*len(self.data.atomnos) - 6 |
| 28 |
|
| 29 |
def testbasics(self): |
| 30 |
"""Are basic attributes correct?""" |
| 31 |
self.assertEqual(self.data.natom, 20) |
| 32 |
|
| 33 |
def testvibdisps(self): |
| 34 |
"""Are the dimensions of vibdisps consistent with numvib x N x 3""" |
| 35 |
self.assertEqual(len(self.data.vibfreqs), self.numvib) |
| 36 |
self.assertEqual(self.data.vibdisps.shape, |
| 37 |
(self.numvib, len(self.data.atomnos), 3)) |
| 38 |
|
| 39 |
def testlengths(self): |
| 40 |
"""Are the lengths of vibfreqs and vibirs (and if present, vibsyms) correct?""" |
| 41 |
self.assertEqual(len(self.data.vibfreqs), self.numvib) |
| 42 |
if hasattr(self.data, 'vibirs'): |
| 43 |
self.assertEqual(len(self.data.vibirs), self.numvib) |
| 44 |
if hasattr(self.data, 'vibsyms'): |
| 45 |
self.assertEqual(len(self.data.vibsyms), self.numvib) |
| 46 |
|
| 47 |
def testfreqval(self): |
| 48 |
"""Is the highest freq value 3630 +/- 200 wavenumber?""" |
| 49 |
self.assertAlmostEqual(max(self.data.vibfreqs), 3630, delta=200) |
| 50 |
|
| 51 |
@skipForParser('Psi4', 'Psi cannot print IR intensities') |
| 52 |
def testirintens(self): |
| 53 |
"""Is the maximum IR intensity 100 +/- 10 km/mol?""" |
| 54 |
self.assertAlmostEqual(max(self.data.vibirs), self.max_IR_intensity, delta=10) |
| 55 |
|
| 56 |
|
| 57 |
class FireflyIRTest(GenericIRTest): |
| 58 |
"""Customized vibrational frequency unittest""" |
| 59 |
|
| 60 |
max_IR_intensity = 135 |
| 61 |
|
| 62 |
|
| 63 |
class GaussianIRTest(GenericIRTest): |
| 64 |
"""Customized vibrational frequency unittest""" |
| 65 |
|
| 66 |
def testvibsyms(self): |
| 67 |
"""Is the length of vibsyms correct?""" |
| 68 |
self.assertEqual(len(self.data.vibsyms), self.numvib) |
| 69 |
|
| 70 |
|
| 71 |
class JaguarIRTest(GenericIRTest): |
| 72 |
"""Customized vibrational frequency unittest""" |
| 73 |
|
| 74 |
def testvibsyms(self): |
| 75 |
"""Is the length of vibsyms correct?""" |
| 76 |
self.assertEqual(len(self.data.vibsyms), self.numvib) |
| 77 |
|
| 78 |
|
| 79 |
class MolcasIRTest(GenericIRTest): |
| 80 |
"""Customized vibrational frequency unittest""" |
| 81 |
|
| 82 |
max_IR_intensity = 65 |
| 83 |
|
| 84 |
entropy_places = 3 |
| 85 |
enthalpy_places = 3 |
| 86 |
freeenergy_places = 3 |
| 87 |
|
| 88 |
def testtemperature(self): |
| 89 |
"""Is the temperature 298.15 K?""" |
| 90 |
self.assertAlmostEqual(298.15, self.data.temperature) |
| 91 |
|
| 92 |
def testpressure(self): |
| 93 |
"""Is the pressure 1 atm?""" |
| 94 |
self.assertAlmostEqual(1, self.data.pressure) |
| 95 |
|
| 96 |
def testentropy(self): |
| 97 |
"""Is the entropy reasonable""" |
| 98 |
self.assertAlmostEqual(0.13403144, self.data.entropy, self.entropy_places) |
| 99 |
|
| 100 |
def testenthalpy(self): |
| 101 |
"""Is the enthalpy reasonable""" |
| 102 |
self.assertAlmostEqual(-382.11385, self.data.enthalpy, self.enthalpy_places) |
| 103 |
|
| 104 |
def testfreeenergy(self): |
| 105 |
"""Is the freeenergy reasonable""" |
| 106 |
self.assertAlmostEqual(-382.153812, self.data.freeenergy, self.freeenergy_places) |
| 107 |
|
| 108 |
|
| 109 |
class OrcaIRTest(GenericIRTest): |
| 110 |
"""Customized vibrational frequency unittest""" |
| 111 |
|
| 112 |
# ORCA has a bug in the intensities for version < 4.0 |
| 113 |
max_IR_intensity = 215 |
| 114 |
|
| 115 |
enthalpy_places = 3 |
| 116 |
entropy_places = 3 |
| 117 |
freeenergy_places = 3 |
| 118 |
|
| 119 |
def testtemperature(self): |
| 120 |
"""Is the temperature 298.15 K?""" |
| 121 |
self.assertAlmostEqual(298.15, self.data.temperature) |
| 122 |
|
| 123 |
def testpressure(self): |
| 124 |
"""Is the pressure 1 atm?""" |
| 125 |
self.assertAlmostEqual(1, self.data.pressure) |
| 126 |
|
| 127 |
def testenthalpy(self): |
| 128 |
"""Is the enthalpy reasonable""" |
| 129 |
self.assertAlmostEqual(-381.85224835, self.data.enthalpy, self.enthalpy_places) |
| 130 |
|
| 131 |
def testentropy(self): |
| 132 |
"""Is the entropy reasonable""" |
| 133 |
self.assertAlmostEqual(0.03601749, self.data.entropy, self.entropy_places) |
| 134 |
|
| 135 |
def testfreeenergy(self): |
| 136 |
"""Is the freeenergy reasonable""" |
| 137 |
self.assertAlmostEqual(-381.88826585, self.data.freeenergy, self.freeenergy_places) |
| 138 |
|
| 139 |
|
| 140 |
class QChemIRTest(GenericIRTest): |
| 141 |
"""Customized vibrational frequency unittest""" |
| 142 |
|
| 143 |
def testtemperature(self): |
| 144 |
"""Is the temperature 298.15 K?""" |
| 145 |
self.assertEqual(298.15, self.data.temperature) |
| 146 |
|
| 147 |
# def testenthalpy(self): |
| 148 |
# """Is the enthalpy ...""" |
| 149 |
# self.assertInside(self.data.enthalpy, ) |
| 150 |
|
| 151 |
# def testentropy(self): |
| 152 |
# """Is the entropy ...""" |
| 153 |
# self.assertInside(self.data.entropy, ) |
| 154 |
|
| 155 |
# def testfreeenergy(self): |
| 156 |
# """Is the free energy ...""" |
| 157 |
# self.assertInside(self.data.freeenergy, ) |
| 158 |
|
| 159 |
# Molecular mass of DVB in mD. |
| 160 |
molecularmass = 130078.25 |
| 161 |
|
| 162 |
def testatommasses(self): |
| 163 |
"""Do the atom masses sum up to the molecular mass (130078.25+-0.1mD)?""" |
| 164 |
mm = 1000*sum(self.data.atommasses) |
| 165 |
self.assertAlmostEqual(mm, 130078.25, delta=0.1, msg = "Molecule mass: %f not 130078 +- 0.1mD" % mm) |
| 166 |
|
| 167 |
def testhessian(self): |
| 168 |
"""Do the frequencies from the Hessian match the printed frequencies?""" |
| 169 |
|
| 170 |
|
| 171 |
class GamessIRTest(GenericIRTest): |
| 172 |
"""Customized vibrational frequency unittest""" |
| 173 |
# Molecular mass of DVB in mD. |
| 174 |
molecularmass = 130078.25 |
| 175 |
|
| 176 |
def testatommasses(self): |
| 177 |
"""Do the atom masses sum up to the molecular mass (130078.25+-0.1mD)?""" |
| 178 |
mm = 1000*sum(self.data.atommasses) |
| 179 |
self.assertAlmostEqual(mm, 130078.25, delta=0.1, msg = "Molecule mass: %f not 130078 +- 0.1mD" % mm) |
| 180 |
|
| 181 |
|
| 182 |
class GenericIRimgTest(unittest.TestCase): |
| 183 |
"""Generic imaginary vibrational frequency unittest""" |
| 184 |
|
| 185 |
def setUp(self): |
| 186 |
"""Initialize the number of vibrational frequencies on a per molecule basis""" |
| 187 |
self.numvib = 3*len(self.data.atomnos) - 6 |
| 188 |
|
| 189 |
def testvibdisps(self): |
| 190 |
"""Are the dimensions of vibdisps consistent with numvib x N x 3""" |
| 191 |
self.assertEqual(self.data.vibdisps.shape, |
| 192 |
(self.numvib, len(self.data.atomnos), 3)) |
| 193 |
|
| 194 |
def testlengths(self): |
| 195 |
"""Are the lengths of vibfreqs and vibirs correct?""" |
| 196 |
self.assertEqual(len(self.data.vibfreqs), self.numvib) |
| 197 |
self.assertEqual(len(self.data.vibirs), self.numvib) |
| 198 |
|
| 199 |
def testfreqval(self): |
| 200 |
"""Is the lowest freq value negative?""" |
| 201 |
self.assertTrue(self.data.vibfreqs[0] < 0) |
| 202 |
|
| 203 |
## def testmaxvibdisps(self): |
| 204 |
## """What is the maximum value of displacement for a H vs a C?""" |
| 205 |
## Cvibdisps = compress(self.data.atomnos==6, self.data.vibdisps, 1) |
| 206 |
## Hvibdisps = compress(self.data.atomnos==1, self.data.vibdisps, 1) |
| 207 |
## self.assertEqual(max(abs(Cvibdisps).flat), 1.0) |
| 208 |
|
| 209 |
|
| 210 |
class GenericRamanTest(unittest.TestCase): |
| 211 |
"""Generic Raman unittest""" |
| 212 |
|
| 213 |
# This value is in amu. |
| 214 |
max_raman_intensity = 575 |
| 215 |
|
| 216 |
def setUp(self): |
| 217 |
"""Initialize the number of vibrational frequencies on a per molecule basis""" |
| 218 |
self.numvib = 3*len(self.data.atomnos) - 6 |
| 219 |
|
| 220 |
def testlengths(self): |
| 221 |
"""Is the length of vibramans correct?""" |
| 222 |
self.assertEqual(len(self.data.vibramans), self.numvib) |
| 223 |
|
| 224 |
# The tolerance for this number has been increased, since ORCA |
| 225 |
# failed to make it inside +/-5, but it would be nice in the future |
| 226 |
# to determine is it's not too much work whether this is due to |
| 227 |
# algorithmic differences, or to differences in the input basis set |
| 228 |
# or coordinates. The first would be OK, but in the second case the |
| 229 |
# unit test jobs should be made more comparable. With cclib, we first |
| 230 |
# of all want to succeed in parsing, but would also like to remain |
| 231 |
# as comparable between programs as possible (for these tests). |
| 232 |
# Note also that this value is adjusted for Gaussian and DALTON - why? |
| 233 |
def testramanintens(self): |
| 234 |
"""Is the maximum Raman intensity correct?""" |
| 235 |
self.assertAlmostEqual(max(self.data.vibramans), self.max_raman_intensity, delta=8) |
| 236 |
|
| 237 |
# We used to test this, but it seems to vary wildly between |
| 238 |
# programs... perhaps we could use it if we knew why... |
| 239 |
#self.assertInside(self.data.vibramans[1], 2.6872, 0.0001) |
| 240 |
|
| 241 |
def testvibdisps(self): |
| 242 |
"""Is the length and value of vibdisps correct?""" |
| 243 |
assert hasattr(self.data, "vibdisps") |
| 244 |
assert len(self.data.vibdisps) == 54 |
| 245 |
|
| 246 |
|
| 247 |
class DALTONRamanTest(GenericRamanTest): |
| 248 |
"""Customized Raman unittest""" |
| 249 |
|
| 250 |
max_raman_intensity = 745 |
| 251 |
|
| 252 |
|
| 253 |
class GaussianRamanTest(GenericRamanTest): |
| 254 |
"""Customized Raman unittest""" |
| 255 |
|
| 256 |
max_raman_intensity = 1066 |
| 257 |
|
| 258 |
|
| 259 |
class OrcaRamanTest(GenericRamanTest): |
| 260 |
"""Customized Raman unittest""" |
| 261 |
|
| 262 |
max_raman_intensity = 1048 |
| 263 |
|
| 264 |
|
| 265 |
class QChemRamanTest(GenericRamanTest): |
| 266 |
"""Customized Raman unittest""" |
| 267 |
|
| 268 |
max_raman_intensity = 588 |
| 269 |
|
| 270 |
|
| 271 |
if __name__=="__main__": |
| 272 |
|
| 273 |
import sys |
| 274 |
sys.path.insert(1, os.path.join(__filedir__, "..")) |
| 275 |
|
| 276 |
from test_data import DataSuite |
| 277 |
suite = DataSuite(['vib']) |
| 278 |
suite.testall() |