File: testvib.py

package info (click to toggle)
cclib 1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 55,300 kB
  • sloc: python: 23,276; makefile: 84; sh: 26
file content (504 lines) | stat: -rw-r--r-- 19,319 bytes parent folder | download
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# -*- 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 vibration output in cclib"""

import os
import unittest

from skip import skipForParser, skipForLogfile


__filedir__ = os.path.realpath(os.path.dirname(__file__))


class GenericIRTest(unittest.TestCase):
    """Generic vibrational frequency unittest"""

    # Unit tests should normally give this value for the largest IR intensity.
    max_IR_intensity = 100

    # Unit tests may give these values for the largest force constant and reduced mass, respectively.
    max_force_constant = 10.0
    max_reduced_mass = 6.9

    # reference zero-point correction from Gaussian 16 dvb_ir.out
    zpve = 0.1771

    def setUp(self) -> None:
        """Initialize the number of vibrational frequencies on a per molecule basis"""
        self.numvib = 3*len(self.data.atomnos) - 6

    def testbasics(self) -> None:
        """Are basic attributes correct?"""
        assert self.data.natom == 20

    @skipForLogfile("FChk/basicGaussian09", "not printed in older versions than 16")
    @skipForLogfile("FChk/basicQChem5.4", "not printed")
    def testvibdisps(self) -> None:
        """Are the dimensions of vibdisps consistent with numvib x N x 3"""
        assert len(self.data.vibfreqs) == self.numvib
        assert self.data.vibdisps.shape == (self.numvib, len(self.data.atomnos), 3)

    @skipForLogfile("FChk/basicGaussian09", "not printed in older versions than 16")
    @skipForLogfile("FChk/basicQChem5.4", "not printed")
    def testlengths(self) -> None:
        """Are the lengths of vibfreqs and vibirs (and if present, vibsyms, vibfconnsts and vibrmasses) correct?"""
        assert len(self.data.vibfreqs) == self.numvib
        if hasattr(self.data, 'vibirs'):
            assert len(self.data.vibirs) == self.numvib
        if hasattr(self.data, 'vibsyms'):
            assert len(self.data.vibsyms) == self.numvib
        if hasattr(self.data, 'vibfconsts'):
            assert len(self.data.vibfconsts) == self.numvib
        if hasattr(self.data, 'vibrmasses'):
            assert len(self.data.vibrmasses) == self.numvib

    @skipForLogfile("FChk/basicGaussian09", "not printed in older versions than 16")
    @skipForLogfile("FChk/basicQChem5.4", "not printed")
    def testfreqval(self) -> None:
        """Is the highest freq value 3630 +/- 200 wavenumber?"""
        assert abs(max(self.data.vibfreqs) - 3630) < 200

    @skipForParser('Psi4', 'Psi cannot print IR intensities')
    @skipForLogfile("FChk/basicGaussian09", "not printed in older versions than 16")
    @skipForLogfile("FChk/basicQChem5.4", "not printed")
    def testirintens(self) -> None:
        """Is the maximum IR intensity 100 +/- 10 km/mol?"""
        assert abs(max(self.data.vibirs) - self.max_IR_intensity) < 10

    @skipForParser('ADF', 'ADF cannot print force constants')
    @skipForParser('DALTON', 'DALTON cannot print force constants')
    @skipForParser('GAMESS', 'GAMESS-US cannot print force constants')
    @skipForParser('GAMESSUK', 'GAMESS-UK cannot print force constants')
    @skipForParser('Molcas', 'Molcas cannot print force constants')
    @skipForParser('Molpro', 'Molpro cannot print force constants')
    @skipForParser('NWChem', 'Not implemented for this parser')
    @skipForParser('ORCA', 'ORCA cannot print force constants')
    @skipForParser('Turbomole', 'Turbomole cannot print force constants')
    @skipForLogfile('Jaguar/Jaguar4.2', 'Data file does not contain force constants')
    @skipForLogfile('Psi4/Psi4-1.0', 'Data file contains vibrational info with cartesian coordinates')
    @skipForLogfile("FChk/basicGaussian09", "not printed in older versions than 16")
    @skipForLogfile("FChk/basicQChem5.4", "not printed")
    def testvibfconsts(self) -> None:
        """Is the maximum force constant 10. +/- 0.1 mDyn/angstrom?"""
        assert abs(max(self.data.vibfconsts) - self.max_force_constant) < 0.1

    @skipForParser('ADF', 'ADF cannot print reduced masses')
    @skipForParser('DALTON', 'DALTON cannot print reduced masses')
    @skipForParser('GAMESSUK', 'GAMESSUK cannot print reduced masses')
    @skipForParser('Molpro', 'Molpro cannot print reduced masses')
    @skipForParser('NWChem', 'Not implemented for this parser')
    @skipForParser('ORCA', 'ORCA cannot print reduced masses')
    @skipForLogfile('GAMESS/PCGAMESS', 'Data file does not contain reduced masses')
    @skipForLogfile('Psi4/Psi4-1.0', 'Data file does not contain reduced masses')
    @skipForLogfile("FChk/basicGaussian09", "not printed in older versions than 16")
    @skipForLogfile("FChk/basicQChem5.4", "not printed")
    def testvibrmasses(self) -> None:
        """Is the maximum reduced mass 6.9 +/- 0.1 daltons?"""
        assert abs(max(self.data.vibrmasses) - self.max_reduced_mass) < 0.1

    @skipForParser("FChk", "not printed")
    @skipForParser('Psi3', 'not implemented yet')
    def testzeropointcorrection(self) -> None:
        """Is the zero-point correction correct?"""
        assert abs(self.data.zpve - self.zpve) < 1.0e-3

    @skipForParser('ADF', 'not implemented yet')
    @skipForParser('GAMESSUK', 'not implemented yet')
    @skipForParser('Gaussian', 'not implemented yet')
    @skipForParser('Jaguar', 'not implemented yet')
    @skipForParser('Molcas', 'not implemented yet')
    @skipForParser('Molpro', 'not implemented yet')
    @skipForParser('ORCA', 'not implemented yet')
    @skipForParser('Psi4', 'not implemented yet')
    @skipForLogfile('QChem/basicQChem5.4/dvb_ir.out', 'needs to be rerun with print level turned up')
    @skipForParser('Turbomole', 'not implemented yet')
    def testhessian(self):
        """Are the dimensions of the molecular Hessian correct?"""
        assert self.data.hessian.shape == (3 * self.data.natom, 3 * self.data.natom)


class ADFIRTest(GenericIRTest):
    """Customized vibrational frequency unittest"""

    # ???
    def testzeropointcorrection(self) -> None:
        """Is the zero-point correction correct?"""
        assert abs(self.data.zpve - self.zpve) < 1.0e-2


class FireflyIRTest(GenericIRTest):
    """Customized vibrational frequency unittest"""

    max_IR_intensity = 135
    # ???
    zpve = 0.1935


class GaussianIRTest(GenericIRTest):
    """Customized vibrational frequency unittest"""

    @skipForParser("FChk", "not printed")
    def testvibsyms(self) -> None:
        """Is the length of vibsyms correct?"""
        assert len(self.data.vibsyms) == self.numvib

    @skipForParser("FChk", "not printed")
    def testzeropointcorrection(self) -> None:
        # reference zero-point correction from dvb_ir.out
        zpve = 0.1771
        """Is the zero-point correction correct?"""
        assert abs(self.data.zpve - zpve) < 0.001

    entropy_places = 6
    enthalpy_places = 3
    freeenergy_places = 3

    @skipForParser("FChk", "not printed")
    def testtemperature(self) -> None:
        """Is the temperature 298.15 K?"""
        assert round(abs(298.15 - self.data.temperature), 7) == 0

    @skipForParser("FChk", "not printed")
    def testpressure(self) -> None:
        """Is the pressure 1 atm?"""
        assert round(abs(1 - self.data.pressure), 7) == 0

    @skipForParser("FChk", "not printed")
    def testentropy(self) -> None:
         """Is the entropy reasonable"""
         assert round(abs(0.0001462623335480945 - self.data.entropy), self.entropy_places) == 0

    @skipForParser("FChk", "not printed")
    def testenthalpy(self) -> None:
         """Is the enthalpy reasonable"""
         assert round(abs(-382.12130688525264 - self.data.enthalpy), self.enthalpy_places) == 0

    @skipForParser("FChk", "not printed")
    def testfreeenergy(self) -> None:
         """Is the freeenergy reasonable"""
         assert round(abs(-382.164915 - self.data.freeenergy), self.freeenergy_places) == 0

    @skipForParser("FChk", "not printed")
    def testfreeenergyconsistency(self) -> None:
        """Does G = H - TS hold"""
        assert round(
            abs(
                self.data.enthalpy - self.data.temperature * self.data.entropy -self .data.freeenergy
            ),
            self.freeenergy_places
        ) == 0

class JaguarIRTest(GenericIRTest):
    """Customized vibrational frequency unittest"""

    # Jagur outputs vibrational info with cartesian coordinates
    max_force_constant = 3.7
    max_reduced_mass = 2.3

    def testvibsyms(self) -> None:
        """Is the length of vibsyms correct?"""
        assert len(self.data.vibsyms) == self.numvib


class MolcasIRTest(GenericIRTest):
    """Customized vibrational frequency unittest"""

    max_IR_intensity = 65
    zpve = 0.1783

    entropy_places = 6
    enthalpy_places = 3
    freeenergy_places = 3

    def testtemperature(self) -> None:
        """Is the temperature 298.15 K?"""
        assert round(abs(298.15 - self.data.temperature), 7) == 0

    def testpressure(self) -> None:
        """Is the pressure 1 atm?"""
        assert round(abs(1 - self.data.pressure), 7) == 0

    def testentropy(self) -> None:
         """Is the entropy reasonable"""
         assert round(abs(0.00013403320476271246 - self.data.entropy), self.entropy_places) == 0

    def testenthalpy(self) -> None:
         """Is the enthalpy reasonable"""
         assert round(abs(-382.11385 - self .data.enthalpy), self.enthalpy_places) == 0

    def testfreeenergy(self) -> None:
         """Is the freeenergy reasonable"""
         assert round(abs(-382.153812 - self .data.freeenergy), self.freeenergy_places) == 0

    def testfreeenergyconsistency(self) -> None:
        """Does G = H - TS hold"""
        assert round(
            abs(
                self.data.enthalpy - self.data.temperature * self.data.entropy - self.data.freeenergy
            ),
            self.freeenergy_places
        ) == 0

class NWChemIRTest(GenericIRTest):
    """Generic imaginary vibrational frequency unittest"""

    def setUp(self) -> None:
        """Initialize the number of vibrational frequencies on a per molecule basis"""
        self.numvib = 3*len(self.data.atomnos)


class OrcaIRTest(GenericIRTest):
    """Customized vibrational frequency unittest"""

    # ORCA has a bug in the intensities for version < 4.0
    max_IR_intensity = 215
    zpve = 0.1921

    enthalpy_places = 3
    entropy_places = 6
    freeenergy_places = 3

    def testtemperature(self) -> None:
        """Is the temperature 298.15 K?"""
        assert round(abs(298.15 - self.data.temperature), 7) == 0

    def testpressure(self) -> None:
        """Is the pressure 1 atm?"""
        assert round(abs(1 - self.data.pressure), 7) == 0

    def testenthalpy(self) -> None:
         """Is the enthalpy reasonable"""
         assert round(abs(-381.85224835 - self.data.enthalpy), self.enthalpy_places) == 0

    def testentropy(self) -> None:
         """Is the entropy reasonable"""
         assert round(abs(0.00012080325339594164 - self.data.entropy), self.entropy_places) == 0

    def testfreeenergy(self) -> None:
         """Is the freeenergy reasonable"""
         assert round(abs(-381.88826585 - self.data.freeenergy), self.freeenergy_places) == 0

    def testfreeenergyconsistency(self) -> None:
        """Does G = H - TS hold"""
        assert round(
            abs(
                self.data.enthalpy - self.data.temperature * self.data.entropy - self.data.freeenergy
            ),
            self.freeenergy_places
        ) == 0


class QChemIRTest(GenericIRTest):
    """Customized vibrational frequency unittest"""

    enthalpy_places = 3
    entropy_places = 6
    freeenergy_places = 3

    @skipForParser("FChk", "not printed")
    def testtemperature(self) -> None:
        """Is the temperature 298.15 K?"""
        assert 298.15 == self.data.temperature

    @skipForParser("FChk", "not printed")
    def testpressure(self) -> None:
        """Is the pressure 1 atm?"""
        assert round(abs(1 - self.data.pressure), 7) == 0

    @skipForParser("FChk", "not printed")
    def testenthalpy(self) -> None:
         """Is the enthalpy reasonable"""
         assert round(abs(0.1871270552135131 - self.data.enthalpy), self.enthalpy_places) == 0

    @skipForParser("FChk", "not printed")
    def testentropy(self) -> None:
         """Is the entropy reasonable"""
         assert round(abs(0.00014667348271900577 - self.data.entropy), self.entropy_places) == 0

    @skipForParser("FChk", "not printed")
    def testfreeenergy(self) -> None:
         """Is the freeenergy reasonable"""
         assert round(abs(0.14339635634084155 - self.data.freeenergy), self.freeenergy_places) == 0

    # Molecular mass of DVB in mD.
    molecularmass = 130078.25

    @skipForParser("FChk", "not printed")
    def testatommasses(self) -> None:
        """Do the atom masses sum up to the molecular mass (130078.25+-0.1mD)?"""
        mm = 1000 * sum(self.data.atommasses)
        assert abs(mm - 130078.25) < 0.1, f"Molecule mass: {mm:f} not 130078 +- 0.1mD"

    def testhessian(self) -> None:
        """Do the frequencies from the Hessian match the printed frequencies?"""

    @skipForParser("FChk", "not printed")
    def testfreeenergyconsistency(self) -> None:
        """Does G = H - TS hold"""
        assert round(
            abs(
                self.data.enthalpy - self.data.temperature * self.data.entropy - self.data.freeenergy
            ),
            self.freeenergy_places
        ) == 0


class GamessIRTest(GenericIRTest):
    """Customized vibrational frequency unittest"""
    # Molecular mass of DVB in mD.
    molecularmass = 130078.25
    enthalpy_places = 3
    entropy_places = 6
    freeenergy_places = 3

    def testatommasses(self) -> None:
        """Do the atom masses sum up to the molecular mass (130078.25+-0.1mD)?"""
        mm = 1000 * sum(self.data.atommasses)
        assert abs(mm - 130078.25) < 0.1, f"Molecule mass: {mm:f} not 130078 +- 0.1mD"

    def testtemperature(self) -> None:
        """Is the temperature 298.15 K?"""
        assert round(abs(298.15 - self.data.temperature), 7) == 0

    def testpressure(self) -> None:
        """Is the pressure 1 atm?"""
        assert round(abs(1 - self.data.pressure), 7) == 0

    def testenthalpy(self) -> None:
         """Is the enthalpy reasonable"""
         assert round(abs(-381.86372805188300 - self.data.enthalpy), self.enthalpy_places) == 0

    def testentropy(self) -> None:
         """Is the entropy reasonable"""
         assert round(abs(0.00014875961938 - self.data.entropy), self.entropy_places) == 0

    def testfreeenergy(self) -> None:
         """Is the freeenergy reasonable"""
         assert round(abs(-381.90808120060200 - self.data.freeenergy), self.freeenergy_places) == 0

    def testfreeenergyconsistency(self) -> None:
        """Does G = H - TS hold"""
        assert round(
            abs(
                self.data.enthalpy - self.data.temperature * self.data.entropy - self.data.freeenergy
            ),
            self.freeenergy_places
        ) == 0


class Psi4IRTest(GenericIRTest):
    """Customized vibrational frequency unittest"""

    # RHF is used for Psi4 IR test data instead of B3LYP
    max_force_constant = 9.37
    zpve = 0.1917


class TurbomoleIRTest(GenericIRTest):
    """Customized vibrational frequency unittest"""

    # ???
    zpve = 0.1725


class GenericIRimgTest(unittest.TestCase):
    """Generic imaginary vibrational frequency unittest"""

    def setUp(self) -> None:
        """Initialize the number of vibrational frequencies on a per molecule basis"""
        self.numvib = 3*len(self.data.atomnos) - 6

    def testvibdisps(self) -> None:
        """Are the dimensions of vibdisps consistent with numvib x N x 3"""
        assert self.data.vibdisps.shape == (self.numvib, len(self.data.atomnos), 3)

    def testlengths(self) -> None:
        """Are the lengths of vibfreqs and vibirs correct?"""
        assert len(self.data.vibfreqs) == self.numvib
        assert len(self.data.vibirs) == self.numvib

    def testfreqval(self) -> None:
        """Is the lowest freq value negative?"""
        assert self.data.vibfreqs[0] < 0

##    def testmaxvibdisps(self):
##        """What is the maximum value of displacement for a H vs a C?"""
##        Cvibdisps = compress(self.data.atomnos==6, self.data.vibdisps, 1)
##        Hvibdisps = compress(self.data.atomnos==1, self.data.vibdisps, 1)
##        self.assertEqual(max(abs(Cvibdisps).flat), 1.0)


class GenericRamanTest(unittest.TestCase):
    """Generic Raman unittest"""

    # This value is in amu.
    max_raman_intensity = 575

    def setUp(self) -> None:
        """Initialize the number of vibrational frequencies on a per molecule basis"""
        self.numvib = 3*len(self.data.atomnos) - 6

    def testlengths(self) -> None:
        """Is the length of vibramans correct?"""
        assert len(self.data.vibramans) == self.numvib

    # The tolerance for this number has been increased, since ORCA
    # failed to make it inside +/-5, but it would be nice in the future
    # to determine is it's not too much work whether this is due to
    # algorithmic differences, or to differences in the input basis set
    # or coordinates. The first would be OK, but in the second case the
    # unit test jobs should be made more comparable. With cclib, we first
    # of all want to succeed in parsing, but would also like to remain
    # as comparable between programs as possible (for these tests).
    # Note also that this value is adjusted for Gaussian and DALTON - why?
    def testramanintens(self) -> None:
        """Is the maximum Raman intensity correct?"""
        assert abs(max(self.data.vibramans) - self.max_raman_intensity) < 8

        # We used to test this, but it seems to vary wildly between
        # programs... perhaps we could use it if we knew why...
        #self.assertInside(self.data.vibramans[1], 2.6872, 0.0001)

    def testvibdisps(self) -> None:
        """Is the length and value of vibdisps correct?"""
        assert hasattr(self.data, "vibdisps")
        assert len(self.data.vibdisps) == 54


class DALTONRamanTest(GenericRamanTest):
    """Customized Raman unittest"""

    max_raman_intensity = 745


class GaussianRamanTest(GenericRamanTest):
    """Customized Raman unittest"""

    max_raman_intensity = 1066


class OrcaRamanTest(GenericRamanTest):
    """Customized Raman unittest"""

    max_raman_intensity = 1045


class QChemRamanTest(GenericRamanTest):
    """Customized Raman unittest"""

    max_raman_intensity = 588

if __name__=="__main__":

    import sys
    sys.path.insert(1, os.path.join(__filedir__, ".."))

    from test_data import DataSuite
    suite = DataSuite(['vib'])
    suite.testall()