# Path: molmod/test/common.py
# class BaseTestCase(unittest.TestCase):
#     def assertArraysEqual(self, a, b):
#         self.assertEqual(a.shape, b.shape, "The array shapes do not match.")
#         assert (a==b).all(), "The array values do not match."
# 
#     def assertArrayConstant(self, arr, const):
#         assert (arr==const).all(), "Some/All array values do not match the constant."
# 
#     def assertArraysAlmostEqual(self, a, b, threshold=1e-6, mean=False, doabs=False):
#         self.assertEqual(a.shape, b.shape, "The array shapes do not match.")
#         if a.shape == (0,):
#             return
#         if mean:
#             abserr = abs(a-b).mean()
#             oom = 0.5*(abs(a).mean()+abs(b).mean())
#         else:
#             abserr = abs(a-b).max()
#             oom = 0.5*(abs(a).max()+abs(b).max())
#         if doabs:
#             assert abserr <= threshold, "The absolute error is larger than the given threshold: %5.3e > %5.3e" % (abserr, threshold)
#         else:
#             relerr = abserr/oom
#             assert relerr <= threshold, "The relative error is larger than the given threshold: %5.3e > %5.3e" % (relerr, threshold)
# 
#     def assertArrayAlmostConstant(self, arr, const, relerr_threshold):
#         error = abs(arr-const).max()
#         oom = const
#         relerr = error/oom
#         assert relerr <= relerr_threshold, "The relative error is larger than the given threshold: %5.3e > %5.3e" % (relerr, relerr_threshold)
# 
#     def assertArrayAlmostZero(self, arr, abserr_threshold):
#         abserr = abs(arr).max()
#         assert abserr <= abserr_threshold, "The absolute error is larger than the given threshold: %5.3e > %5.3e" % (abserr, abserr_threshold)


import pkg_resources
from molmod.test.common import BaseTestCase
from molmod.io import *
from molmod import *


from __future__ import division




__all__ = ["GamessTestCase"]


class GamessTestCase(BaseTestCase):
    def test_punch(self):
        punch = PunchFile(pkg_resources.resource_filename("molmod", "data/test/PCGamess_PUNCH"))
        self.assertEqual(punch.title, "Simple example sample optimization with Hessian output for Toon")
        self.assertEqual(punch.symmetry, "C1")
        self.assertEqual(punch.symbols, ["CL", "H", "H", "H", "H", "F", "F", "F", "F", "H", "F"])
        N = len(punch.symbols)
        self.assertEqual(punch.numbers.shape, (N,))
        self.assertEqual(punch.numbers[0], 17)
        self.assertEqual(punch.numbers[1], 1)
        self.assertEqual(punch.numbers[-1], 9)
        self.assertEqual(punch.coordinates.shape, (N,3))
        self.assertAlmostEqual(punch.coordinates[0,1]/angstrom, -0.1843157808)
        self.assertAlmostEqual(punch.coordinates[3,-1]/angstrom, 1.2926708150)
        self.assertAlmostEqual(punch.coordinates[-1,0]/angstrom, 3.8608437748)
        self.assertAlmostEqual(punch.energy, -959.9675629527)
        self.assertEqual(punch.gradient.shape, (N,3))
        assert abs(punch.gradient[0,1] - 1.5314677838E-05) < 1e-10
        assert abs(punch.gradient[3,-1] - 8.5221217336E-06) < 1e-10
        assert abs(punch.gradient[-1,0] - 2.1211421041E-05) < 1e-10

# Path: molmod/test/common.py
# class BaseTestCase(unittest.TestCase):
#     def assertArraysEqual(self, a, b):
#         self.assertEqual(a.shape, b.shape, "The array shapes do not match.")
#         assert (a==b).all(), "The array values do not match."
# 
#     def assertArrayConstant(self, arr, const):
#         assert (arr==const).all(), "Some/All array values do not match the constant."
# 
#     def assertArraysAlmostEqual(self, a, b, threshold=1e-6, mean=False, doabs=False):
#         self.assertEqual(a.shape, b.shape, "The array shapes do not match.")
#         if a.shape == (0,):
#             return
#         if mean:
#             abserr = abs(a-b).mean()
#             oom = 0.5*(abs(a).mean()+abs(b).mean())
#         else:
#             abserr = abs(a-b).max()
#             oom = 0.5*(abs(a).max()+abs(b).max())
#         if doabs:
#             assert abserr <= threshold, "The absolute error is larger than the given threshold: %5.3e > %5.3e" % (abserr, threshold)
#         else:
#             relerr = abserr/oom
#             assert relerr <= threshold, "The relative error is larger than the given threshold: %5.3e > %5.3e" % (relerr, threshold)
# 
#     def assertArrayAlmostConstant(self, arr, const, relerr_threshold):
#         error = abs(arr-const).max()
#         oom = const
#         relerr = error/oom
#         assert relerr <= relerr_threshold, "The relative error is larger than the given threshold: %5.3e > %5.3e" % (relerr, relerr_threshold)
# 
#     def assertArrayAlmostZero(self, arr, abserr_threshold):
#         abserr = abs(arr).max()
#         assert abserr <= abserr_threshold, "The absolute error is larger than the given threshold: %5.3e > %5.3e" % (abserr, abserr_threshold)


# Path: molmod/io/test/test_gamess.py
import pkg_resources
from molmod.test.common import BaseTestCase
from molmod.io import *
from molmod import *



from __future__ import division




__all__ = ["GamessTestCase"]


class GamessTestCase(BaseTestCase):
    def test_punch(self):
        punch = PunchFile(pkg_resources.resource_filename("molmod", "data/test/PCGamess_PUNCH"))
        self.assertEqual(punch.title, "Simple example sample optimization with Hessian output for Toon")
        self.assertEqual(punch.symmetry, "C1")
        self.assertEqual(punch.symbols, ["CL", "H", "H", "H", "H", "F", "F", "F", "F", "H", "F"])
        N = len(punch.symbols)
        self.assertEqual(punch.numbers.shape, (N,))
        self.assertEqual(punch.numbers[0], 17)
        self.assertEqual(punch.numbers[1], 1)
        self.assertEqual(punch.numbers[-1], 9)
        self.assertEqual(punch.coordinates.shape, (N,3))
        self.assertAlmostEqual(punch.coordinates[0,1]/angstrom, -0.1843157808)
        self.assertAlmostEqual(punch.coordinates[3,-1]/angstrom, 1.2926708150)
        self.assertAlmostEqual(punch.coordinates[-1,0]/angstrom, 3.8608437748)
        self.assertAlmostEqual(punch.energy, -959.9675629527)
        self.assertEqual(punch.gradient.shape, (N,3))
        assert abs(punch.gradient[0,1] - 1.5314677838E-05) < 1e-10
        assert abs(punch.gradient[3,-1] - 8.5221217336E-06) < 1e-10
        assert abs(punch.gradient[-1,0] - 2.1211421041E-05) < 1e-10

        self.assertEqual(punch.hessian.shape, (3*N,3*N))