| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# |
| 3 |
# Copyright (c) 2018, 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 Volume and related methods in cclib""" |
| 9 |
|
| 10 |
from __future__ import print_function |
| 11 |
|
| 12 |
import sys |
| 13 |
import unittest |
| 14 |
|
| 15 |
from cclib.method import volume |
| 16 |
from cclib.parser import Gaussian |
| 17 |
|
| 18 |
sys.path.insert(1, "..") |
| 19 |
|
| 20 |
from ..test_data import getdatafile |
| 21 |
|
| 22 |
|
| 23 |
class VolumeTest(unittest.TestCase): |
| 24 |
|
| 25 |
def test_scinotation(self): |
| 26 |
"""Does the scientific notation writer work as expected?""" |
| 27 |
|
| 28 |
self.assertEqual(volume.scinotation(1./654), ' 1.52905E-03') |
| 29 |
self.assertEqual(volume.scinotation(-1./654), '-1.52905E-03') |
| 30 |
|
| 31 |
def test_wavefunction(self): |
| 32 |
"""Does the volume occupied by the HOMO integrate to the correct |
| 33 |
values? |
| 34 |
""" |
| 35 |
|
| 36 |
data_basis, _ = getdatafile(Gaussian, "basicGaussian09", ["dvb_sp.out"]) |
| 37 |
data_sp, _ = getdatafile(Gaussian, "basicGaussian09", ["dvb_sp.out"]) |
| 38 |
|
| 39 |
vol = volume.Volume((-3.0, -6.0, -2.0), (3.0, 6.0, 2.0), (0.25, 0.25, 0.25)) |
| 40 |
|
| 41 |
wavefn = volume.wavefunction(data_sp.atomcoords[0], |
| 42 |
data_sp.mocoeffs[0][data_sp.homos[0]], |
| 43 |
data_basis.gbasis, vol) |
| 44 |
integral = wavefn.integrate() |
| 45 |
integral_square = wavefn.integrate_square() |
| 46 |
|
| 47 |
self.assertTrue(abs(integral) < 1e-6) # not necessarily true for all wavefns |
| 48 |
self.assertTrue(abs(integral_square - 1.00) < 1e-3) # true for all wavefns |
| 49 |
print(integral, integral_square) |
| 50 |
|
| 51 |
def test_density(self): |
| 52 |
"""Does the volume occupied by the combined electron density integrate |
| 53 |
to the correct value? |
| 54 |
""" |
| 55 |
|
| 56 |
data_basis, _ = getdatafile(Gaussian, "basicGaussian09", ["dvb_sp.out"]) |
| 57 |
data_sp, _ = getdatafile(Gaussian, "basicGaussian09", ["dvb_sp.out"]) |
| 58 |
|
| 59 |
vol = volume.Volume((-3.0, -6.0, -2.0), (3.0, 6.0, 2.0), (0.25, 0.25, 0.25)) |
| 60 |
|
| 61 |
frontierorbs = [data_sp.mocoeffs[0][(data_sp.homos[0] - 3):(data_sp.homos[0] + 1)]] |
| 62 |
density = volume.electrondensity(data_sp.atomcoords[0], |
| 63 |
frontierorbs, data_basis.gbasis, vol) |
| 64 |
integral = density.integrate() |
| 65 |
|
| 66 |
self.assertTrue(abs(integral - 8.00) < 1e-2) |
| 67 |
print("Combined Density of 4 Frontier orbitals=", integral) |