# 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 unittest
import pkg_resources
from molmod.test.common import BaseTestCase
from molmod.io import *
from molmod import *
# --


from __future__ import division





__all__ = ["ATRJTestCase"]


class ATRJTestCase(BaseTestCase):
    def test_load(self):
        # A) normal
        atrj_reader = ATRJReader(pkg_resources.resource_filename("molmod", "data/test/bartek.atrj"))
        self.assertEqual(atrj_reader.num_atoms, 1293)
        frames = list(atrj_reader)
        self.assertEqual(len(frames), 3)
        # check time
        self.assertAlmostEqual(frames[0].time/picosecond, 1.0)
        self.assertAlmostEqual(frames[1].time/picosecond, 2.0)
        self.assertAlmostEqual(frames[2].time/picosecond, 3.0)
        # check step
        self.assertAlmostEqual(frames[0].step, 1000)
        self.assertAlmostEqual(frames[1].step, 2000)
        self.assertAlmostEqual(frames[2].step, 3000)
        # check total energy
        self.assertAlmostEqual(frames[0].total_energy/kcalmol, 3.4186035768405162e2)
        self.assertAlmostEqual(frames[1].total_energy/kcalmol, 3.3443356630787252e2)

# 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_atrj.py
import unittest
import pkg_resources
from molmod.test.common import BaseTestCase
from molmod.io import *
from molmod import *

# --


from __future__ import division





__all__ = ["ATRJTestCase"]


class ATRJTestCase(BaseTestCase):
    def test_load(self):
        # A) normal
        atrj_reader = ATRJReader(pkg_resources.resource_filename("molmod", "data/test/bartek.atrj"))
        self.assertEqual(atrj_reader.num_atoms, 1293)
        frames = list(atrj_reader)
        self.assertEqual(len(frames), 3)
        # check time
        self.assertAlmostEqual(frames[0].time/picosecond, 1.0)
        self.assertAlmostEqual(frames[1].time/picosecond, 2.0)
        self.assertAlmostEqual(frames[2].time/picosecond, 3.0)
        # check step
        self.assertAlmostEqual(frames[0].step, 1000)
        self.assertAlmostEqual(frames[1].step, 2000)
        self.assertAlmostEqual(frames[2].step, 3000)
        # check total energy
        self.assertAlmostEqual(frames[0].total_energy/kcalmol, 3.4186035768405162e2)
        self.assertAlmostEqual(frames[1].total_energy/kcalmol, 3.3443356630787252e2)

        self.assertAlmostEqual(frames[2].total_energy/kcalmol, 3.3613629561285467e2)