| 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 scan logfiles in cclib""" |
| 9 |
|
| 10 |
import os |
| 11 |
import unittest |
| 12 |
|
| 13 |
import numpy |
| 14 |
import cclib |
| 15 |
|
| 16 |
from skip import skipForParser |
| 17 |
|
| 18 |
|
| 19 |
__filedir__ = os.path.realpath(os.path.dirname(__file__)) |
| 20 |
|
| 21 |
|
| 22 |
OPT_DONE = cclib.parser.data.ccData.OPT_DONE |
| 23 |
OPT_NEW = cclib.parser.data.ccData.OPT_NEW |
| 24 |
|
| 25 |
|
| 26 |
class GenericScanTestBase(unittest.TestCase): |
| 27 |
"""Base relaxed potential energy surface scan unittest.""" |
| 28 |
|
| 29 |
def assertOptNew(self, optstatus_value): |
| 30 |
return optstatus_value & OPT_NEW == OPT_NEW |
| 31 |
|
| 32 |
def assertOptDone(self, optstatus_value): |
| 33 |
return optstatus_value & OPT_DONE == OPT_DONE |
| 34 |
|
| 35 |
|
| 36 |
class GenericScanTest_optdone_bool(GenericScanTestBase): |
| 37 |
"""Generic relaxed potential energy surface scan unittest.""" |
| 38 |
|
| 39 |
datatype = cclib.parser.data.ccData_optdone_bool |
| 40 |
|
| 41 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 42 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 43 |
def testoptdone(self): |
| 44 |
"""Is the optimization finished?""" |
| 45 |
self.assertIsInstance(self.data.optdone, bool) |
| 46 |
self.assertEqual(self.data.optdone, True) |
| 47 |
|
| 48 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 49 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 50 |
def testindices(self): |
| 51 |
"""Do the indices match the results from geovalues.""" |
| 52 |
assert self.data.optdone and numpy.all(self.data.geovalues[-1] <= self.data.geotargets) |
| 53 |
|
| 54 |
@skipForParser("Jaguar", "Not implemented") |
| 55 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 56 |
@skipForParser("ORCA", "Not implemented") |
| 57 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 58 |
def testoptstatus(self): |
| 59 |
"""Does optstatus contain expected values?""" |
| 60 |
|
| 61 |
# The input and final coordinates were at a stationary points. |
| 62 |
self.assertOptNew(self.data.optstatus[0]) |
| 63 |
self.assertOptDone(self.data.optstatus[0]) |
| 64 |
self.assertOptDone(self.data.optstatus[-1]) |
| 65 |
|
| 66 |
|
| 67 |
class GenericScanTest(GenericScanTestBase): |
| 68 |
"""Generic relaxed potential energy surface scan unittest.""" |
| 69 |
|
| 70 |
# extra indices |
| 71 |
extra = 0 |
| 72 |
|
| 73 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 74 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 75 |
def testnumindices(self): |
| 76 |
"""Do the number of indices match number of scan points.""" |
| 77 |
self.assertEqual(len(self.data.optdone), 12 + self.extra) |
| 78 |
|
| 79 |
@skipForParser("Jaguar", "Does not work as expected") |
| 80 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 81 |
@skipForParser("ORCA", "Does not work as expected") |
| 82 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 83 |
def testindices(self): |
| 84 |
"""Do the indices match the results from geovalues.""" |
| 85 |
indexes = self.data.optdone |
| 86 |
geovalues_from_index = self.data.geovalues[indexes] |
| 87 |
temp = numpy.all(self.data.geovalues <= self.data.geotargets, axis=1) |
| 88 |
geovalues = self.data.geovalues[temp] |
| 89 |
numpy.testing.assert_array_equal(geovalues, geovalues_from_index) |
| 90 |
|
| 91 |
@skipForParser("Jaguar", "Not implemented") |
| 92 |
@skipForParser('Molcas','The parser is still being developed so we skip this test') |
| 93 |
@skipForParser("ORCA", "Not implemented") |
| 94 |
@skipForParser('Turbomole','The parser is still being developed so we skip this test') |
| 95 |
def testoptstatus(self): |
| 96 |
"""Does optstatus contain expected values?""" |
| 97 |
OPT_NEW = self.data.OPT_NEW |
| 98 |
OPT_DONE = self.data.OPT_DONE |
| 99 |
# The input coordinates were at a stationary point. |
| 100 |
self.assertOptDone(self.data.optstatus[0]) |
| 101 |
|
| 102 |
self.assertEqual(len(self.data.converged_geometries), len(self.data.optdone)) |
| 103 |
for idone in self.data.optdone: |
| 104 |
self.assertOptDone(self.data.optstatus[idone]) |
| 105 |
if idone != len(self.data.optstatus) - 1: |
| 106 |
self.assertOptNew(self.data.optstatus[idone+1]) |
| 107 |
|
| 108 |
|
| 109 |
class GaussianScanTest(GenericScanTest): |
| 110 |
"""Customized relaxed potential energy surface scan unittest""" |
| 111 |
extra = 1 |
| 112 |
|
| 113 |
|
| 114 |
class JaguarScanTest(GenericScanTest): |
| 115 |
"""Customized relaxed potential energy surface scan unittest""" |
| 116 |
extra = 1 |
| 117 |
|
| 118 |
|
| 119 |
class OrcaScanTest(GenericScanTest): |
| 120 |
"""Customized relaxed potential energy surface scan unittest""" |
| 121 |
extra = 1 |
| 122 |
|
| 123 |
|
| 124 |
if __name__=="__main__": |
| 125 |
|
| 126 |
import sys |
| 127 |
sys.path.insert(1, os.path.join(__filedir__, "..")) |
| 128 |
|
| 129 |
from test_data import DataSuite |
| 130 |
suite = DataSuite(['Scan']) |
| 131 |
suite.testall() |