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 Moller-Plesset logfiles in cclib"""
9
10import os
11import unittest
12
13import numpy
14
15__filedir__ = os.path.realpath(os.path.dirname(__file__))
16
17
18class GenericMP2Test(unittest.TestCase):
19    """Generic MP2 unittest"""
20
21    level = 2
22
23    def testsizeandshape(self):
24        """(MP2) Are the dimensions of mpenergies correct?"""
25        self.assertEqual(self.data.mpenergies.shape,
26                         (len(self.data.scfenergies), self.level-1))
27
28    def testsign(self):
29        """Are the Moller-Plesset corrections negative?"""
30        if self.level == 2:
31            corrections = self.data.mpenergies[:,0] - self.data.scfenergies
32        else:
33            corrections = self.data.mpenergies[:,self.level-2] - self.data.mpenergies[:,self.level-3]
34        self.assertTrue(numpy.alltrue(corrections < 0.0))
35
36class GenericMP3Test(GenericMP2Test):
37    """Generic MP3 unittest"""
38    level = 3
39
40class GenericMP4SDQTest(GenericMP2Test):
41    """Generic MP4(SDQ) unittest"""
42    level = 4
43
44class GenericMP4SDTQTest(GenericMP2Test):
45    """Generic MP4(SDTQ) unittest"""
46    level = 4
47
48class GenericMP5Test(GenericMP2Test):
49    """Generic MP5 unittest"""
50    level = 5
51
52
53class GaussianMP2Test(GenericMP2Test):
54    """Customized MP2 unittest"""
55
56    def testnocoeffs(self):
57        """Are natural orbital coefficients the right size?"""
58        self.assertEqual(self.data.nocoeffs.shape, (self.data.nmo, self.data.nbasis))
59
60    def testnocoeffs(self):
61        """Are natural orbital occupation numbers the right size?"""
62        self.assertEqual(self.data.nooccnos.shape, (self.data.nmo, ))
63
64class GaussianMP3Test(GenericMP2Test):
65    """Customized MP3 unittest"""
66    level = 3
67
68class GaussianMP4SDQTest(GenericMP2Test):
69    """Customized MP4-SDQ unittest"""
70    level = 4
71
72class GaussianMP4SDTQTest(GenericMP2Test):
73    """Customized MP4-SDTQ unittest"""
74    level = 4
75
76
77class QChemMP4SDQTest(GenericMP2Test):
78    """Customized MP4-SDQ unittest"""
79    level = 4
80
81class QChemMP4SDTQTest(GenericMP2Test):
82    """Customized MP4-SD(T)Q unittest"""
83    level = 5
84
85
86if __name__=="__main__":
87
88    import sys
89    sys.path.insert(1, os.path.join(__filedir__, ".."))
90
91    from test_data import DataSuite
92    suite = DataSuite(['MP'])
93    suite.testall()
94