File: testScan.py

package info (click to toggle)
cclib 1.8.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,412 kB
  • sloc: python: 23,605; makefile: 75; sh: 31
file content (140 lines) | stat: -rw-r--r-- 5,078 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
# Copyright (c) 2024, 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 cclib

import numpy
import pytest
from skip import skipForParser

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


def is_optnew(optstatus_value) -> bool:
    return optstatus_value & OPT_NEW == OPT_NEW


def is_optdone(optstatus_value) -> bool:
    return optstatus_value & OPT_DONE == OPT_DONE


class GenericUnrelaxedScanTest:
    """Generic unrelaxed potential energy surface scan unittest."""

    @pytest.fixture
    def extra(self) -> int:
        """extra indices"""
        return 0

    @skipForParser("Jaguar", "Not implemented")
    def testscannames(self, data) -> None:
        assert isinstance(data.scannames, list)

    @skipForParser("ORCA", "Not implemented")
    @skipForParser("Jaguar", "Not implemented")
    def testscanenergies(self, data) -> None:
        assert isinstance(data.scanenergies, list)

        # This checks the order of magnitude, and unit conversion if nothing else.
        numpy.testing.assert_array_less(numpy.array(data.scanenergies), -10000)

    @skipForParser("ORCA", "Not implemented")
    @skipForParser("Jaguar", "Not implemented")
    def testscanparm(self, data) -> None:
        assert isinstance(data.scanparm, list)

        # Each parameters should have as many values as there are scan
        # energies, or optimized point on the PES.
        for parm in data.scanparm:
            assert len(parm) == len(data.scanenergies)


class GenericRelaxedScanTest(GenericUnrelaxedScanTest):
    """Generic relaxed potential energy surface scan unittest."""

    @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, data, extra) -> None:
        """Do the number of indices match number of scan points."""
        assert len(data.optdone) == 12 + 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, data) -> None:
        """Do the indices match the results from geovalues."""
        indexes = data.optdone
        geovalues_from_index = data.geovalues[indexes]
        temp = numpy.all(data.geovalues <= data.geotargets, axis=1)
        geovalues = 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, data) -> None:
        """Does optstatus contain expected values?"""
        # The input coordinates were at a stationary point.
        assert is_optdone(data.optstatus[0])

        assert len(data.converged_geometries) == len(data.optdone)
        for idone in data.optdone:
            assert is_optdone(data.optstatus[idone])
            if idone != len(data.optstatus) - 1:
                assert is_optnew(data.optstatus[idone + 1])

    @skipForParser("Jaguar", "Not implemented")
    def testscannames(self, data) -> None:
        assert isinstance(data.scannames, list)

    @skipForParser("Jaguar", "Not implemented")
    @skipForParser("ORCA", "Not implemented")
    def testscanenergies(self, data) -> None:
        assert isinstance(data.scanenergies, list)

        # This checks the order of magnitude, and unit conversion if nothing else.
        numpy.testing.assert_array_less(numpy.array(data.scanenergies), -10000)

    @skipForParser("Jaguar", "Not implemented")
    @skipForParser("ORCA", "Not implemented")
    def testscanparm(self, data) -> None:
        assert isinstance(data.scanparm, list)

        # Each parameters should have as many values as there are scan
        # energies, or optimized point on the PES.
        for parm in data.scanparm:
            assert len(parm) == len(data.scanenergies)


class GaussianUnrelaxedScanTest(GenericUnrelaxedScanTest):
    """Customized unrelaxed potential energy surface scan unittest"""

    @pytest.fixture
    def extra(self) -> int:
        """extra indices"""
        return 1


class GaussianRelaxedScanTest(GenericRelaxedScanTest):
    """Customized relaxed potential energy surface scan unittest"""

    @pytest.fixture
    def extra(self) -> int:
        """extra indices"""
        return 1


class JaguarRelaxedScanTest(GenericRelaxedScanTest):
    """Customized relaxed potential energy surface scan unittest"""

    @pytest.fixture
    def extra(self) -> int:
        """extra indices"""
        return 1