import os
import numpy as np
import unittest
import epolar3
import tconfig
import config
import induce

path = os.path.abspath(os.path.dirname(__file__))

key = f'{path}/testitems/water21test.key'
xyz = f'{path}/testitems/waterwater.xyz'

class TestEPolar(unittest.TestCase):

    def test_epolar3a(self):

        kep = -0.96210636
        keinter = -0.96210636
        knep = 9

        tconfig.setup(key, xyz, dloop=True)

        config.rotmat(tconfig.ATOMID)

        config.dfield0(tconfig.ATOMID)

        induce.induce0m(tconfig.ATOMID)

        config.param_dict['epolar3a'] = True

        ep, einter, nep = epolar3.epolar3(tconfig.ATOMID)

        self.assertEqual(round(kep,4), round(ep,4))
        self.assertEqual(round(keinter,4), round(einter,4))
        self.assertEqual(knep, nep)

    def test_epolar3m(self):

        kep = -0.96210636
        knep = 27

        tconfig.setup(key, xyz, dloop=True)

        config.rotmat(tconfig.ATOMID)

        config.dfield0(tconfig.ATOMID)

        induce.induce0m(tconfig.ATOMID)

        ep, einter, nep = epolar3.epolar3m(tconfig.ATOMID)

        self.assertEqual(round(kep,4), round(ep,4))
        self.assertEqual(knep, nep)
