File: testScan.py

package info (click to toggle)
cclib-data 1.6.2-2
  • links: PTS, VCS
  • area: non-free
  • in suites: bookworm, bullseye, sid
  • size: 87,912 kB
  • sloc: python: 16,440; sh: 131; makefile: 79; cpp: 31
file content (131 lines) | stat: -rw-r--r-- 4,972 bytes parent folder | download | duplicates (2)
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
# -*- coding: utf-8 -*-
#
# Copyright (c) 2017, 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 scan logfiles in cclib"""

import os
import unittest

import numpy
import cclib

from skip import skipForParser


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


OPT_DONE = cclib.parser.data.ccData.OPT_DONE
OPT_NEW = cclib.parser.data.ccData.OPT_NEW


class GenericScanTestBase(unittest.TestCase):
    """Base relaxed potential energy surface scan unittest."""

    def assertOptNew(self, optstatus_value):
        return optstatus_value & OPT_NEW == OPT_NEW

    def assertOptDone(self, optstatus_value):
        return optstatus_value & OPT_DONE == OPT_DONE


class GenericScanTest_optdone_bool(GenericScanTestBase):
    """Generic relaxed potential energy surface scan unittest."""

    datatype = cclib.parser.data.ccData_optdone_bool

    @skipForParser('Turbomole','The parser is still being developed so we skip this test')
    @skipForParser('Molcas','The parser is still being developed so we skip this test')
    def testoptdone(self):
        """Is the optimization finished?"""
        self.assertIsInstance(self.data.optdone, bool)
        self.assertEqual(self.data.optdone, True)

    @skipForParser('Turbomole','The parser is still being developed so we skip this test')
    @skipForParser('Molcas','The parser is still being developed so we skip this test')
    def testindices(self):
        """Do the indices match the results from geovalues."""
        assert self.data.optdone and numpy.all(self.data.geovalues[-1] <= self.data.geotargets)

    @skipForParser("Jaguar", "Not implemented")
    @skipForParser('Molcas','The parser is still being developed so we skip this test')
    @skipForParser("ORCA", "Not implemented")
    @skipForParser('Turbomole','The parser is still being developed so we skip this test')
    def testoptstatus(self):
        """Does optstatus contain expected values?"""

        # The input and final coordinates were at a stationary points.
        self.assertOptNew(self.data.optstatus[0])
        self.assertOptDone(self.data.optstatus[0])
        self.assertOptDone(self.data.optstatus[-1])


class GenericScanTest(GenericScanTestBase):
    """Generic relaxed potential energy surface scan unittest."""

    # extra indices
    extra = 0
    
    @skipForParser('Molcas','The parser is still being developed so we skip this test')
    @skipForParser('Turbomole','The parser is still being developed so we skip this test')
    def testnumindices(self):
        """Do the number of indices match number of scan points."""
        self.assertEqual(len(self.data.optdone), 12 + self.extra)

    @skipForParser("Jaguar", "Does not work as expected")    
    @skipForParser('Molcas','The parser is still being developed so we skip this test')
    @skipForParser("ORCA", "Does not work as expected")
    @skipForParser('Turbomole','The parser is still being developed so we skip this test')
    def testindices(self):
        """Do the indices match the results from geovalues."""
        indexes = self.data.optdone
        geovalues_from_index = self.data.geovalues[indexes]
        temp = numpy.all(self.data.geovalues <= self.data.geotargets, axis=1)
        geovalues = self.data.geovalues[temp]
        numpy.testing.assert_array_equal(geovalues, geovalues_from_index)

    @skipForParser("Jaguar", "Not implemented")
    @skipForParser('Molcas','The parser is still being developed so we skip this test')
    @skipForParser("ORCA", "Not implemented")
    @skipForParser('Turbomole','The parser is still being developed so we skip this test')
    def testoptstatus(self):
        """Does optstatus contain expected values?"""
        OPT_NEW = self.data.OPT_NEW
        OPT_DONE = self.data.OPT_DONE
        # The input coordinates were at a stationary point.
        self.assertOptDone(self.data.optstatus[0])

        self.assertEqual(len(self.data.converged_geometries), len(self.data.optdone))
        for idone in self.data.optdone:
            self.assertOptDone(self.data.optstatus[idone])
            if idone != len(self.data.optstatus) - 1:
                self.assertOptNew(self.data.optstatus[idone+1])


class GaussianScanTest(GenericScanTest):
    """Customized relaxed potential energy surface scan unittest"""
    extra = 1


class JaguarScanTest(GenericScanTest):
    """Customized relaxed potential energy surface scan unittest"""
    extra = 1


class OrcaScanTest(GenericScanTest):
    """Customized relaxed potential energy surface scan unittest"""
    extra = 1


if __name__=="__main__":

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

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