| 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 the CDA method in cclib""" |
| 9 |
|
| 10 |
from __future__ import print_function |
| 11 |
|
| 12 |
import sys |
| 13 |
import os |
| 14 |
import logging |
| 15 |
import unittest |
| 16 |
|
| 17 |
import numpy |
| 18 |
|
| 19 |
sys.path.insert(1, "..") |
| 20 |
|
| 21 |
from ..test_data import getdatafile |
| 22 |
from cclib.method import CDA |
| 23 |
from cclib.parser import Gaussian |
| 24 |
|
| 25 |
|
| 26 |
def main(log=True): |
| 27 |
data1, logfile1 = getdatafile(Gaussian, "CDA", ["BH3CO-sp.log"]) |
| 28 |
data2, logfile2 = getdatafile(Gaussian, "CDA", ["BH3.log"]) |
| 29 |
data3, logfile3 = getdatafile(Gaussian, "CDA", ["CO.log"]) |
| 30 |
fa = CDA(data1) |
| 31 |
if not log: |
| 32 |
fa.logger.setLevel(logging.ERROR) |
| 33 |
fa.calculate([data2, data3]) |
| 34 |
|
| 35 |
return fa |
| 36 |
|
| 37 |
|
| 38 |
def printResults(): |
| 39 |
fa = main() |
| 40 |
|
| 41 |
print(" d b r") |
| 42 |
print("---------------------------") |
| 43 |
|
| 44 |
spin = 0 |
| 45 |
for i in range(len(fa.donations[0])): |
| 46 |
|
| 47 |
print("%2i: %7.3f %7.3f %7.3f" % (i, |
| 48 |
fa.donations[spin][i], |
| 49 |
fa.bdonations[spin][i], |
| 50 |
fa.repulsions[spin][i])) |
| 51 |
|
| 52 |
|
| 53 |
print("---------------------------") |
| 54 |
print("T: %7.3f %7.3f %7.3f" % (fa.donations[0].sum(), |
| 55 |
fa.bdonations[0].sum(), |
| 56 |
fa.repulsions[0].sum())) |
| 57 |
print("\n\n") |
| 58 |
|
| 59 |
|
| 60 |
class CDATest(unittest.TestCase): |
| 61 |
|
| 62 |
def runTest(self): |
| 63 |
"""Testing CDA results against Frenking's code""" |
| 64 |
fa = main(log=False) |
| 65 |
|
| 66 |
donation = fa.donations[0].sum() |
| 67 |
bdonation = fa.bdonations[0].sum() |
| 68 |
repulsion = fa.repulsions[0].sum() |
| 69 |
|
| 70 |
self.assertAlmostEqual(donation, 0.181, 3) |
| 71 |
self.assertAlmostEqual(bdonation, 0.471, 3) |
| 72 |
self.assertAlmostEqual(repulsion, -0.334, 3) |
| 73 |
|
| 74 |
|
| 75 |
if __name__ == "__main__": |
| 76 |
printResults() |
| 77 |
unittest.TextTestRunner(verbosity=2).run(unittest.makeSuite(CDATest)) |