#!/usr/bin/env python

import os
import sys
import shutil

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from runtest_dirac import Filter, TestRun

test = TestRun(__file__, sys.argv)

my_scratchdir = os.path.join(os.getcwd(), 'eomcc_scratchdir')
if os.path.lexists(my_scratchdir):
   shutil.rmtree(my_scratchdir)

f = Filter()
f.add(from_string = ' Energy eigenvalues in atomic units',
      to_re       = 'Relative real eigenvalues in other units;',
      rel_tolerance = 1.0e-5)

test.run(['eom_ip.inp', 'eom_ip_restart.inp'], ['h2o.xyz'], f, args='--mw=110 --keep_scratch --scratchful='+my_scratchdir)

shutil.rmtree(my_scratchdir)

f = Filter()
f.add(from_string = ' Energy eigenvalues in atomic units',
      to_re       = 'Relative real eigenvalues in other units;',
      rel_tolerance = 1.0e-5)

test.run(['eom_ee.inp', 'eom_ee_restart.inp'], ['h2o.xyz'], f, args='--mw=110 --keep_scratch --scratchful='+my_scratchdir)

shutil.rmtree(my_scratchdir)

f = Filter()
f.add(from_string = ' Overview of calculated energies',
      to_string   = '@ Total CCSD-T  energy',
      rel_tolerance   = 1.0e-7)

test.run(['ccsd.inp'], ['h2o.xyz'], f, args='--mw=110 --keep_scratch --scratchful='+my_scratchdir)

f = Filter()
f.add(from_string = ' Energy eigenvalues in atomic units',
      to_re       = 'Relative real eigenvalues in other units;',
      rel_tolerance = 1.0e-5)

test.run(['eom_ee_restart_from_gs.inp'], ['h2o.xyz'], f, args='--mw=110 --keep_scratch --scratchful='+my_scratchdir)

shutil.rmtree(my_scratchdir)

#
#test.run(['eom_ea.inp', 'eom_ea_restart.inp'], ['h2o.xyz'], f, args='--mw=110 --keep_scratch --scratchful='+my_scratchdir)
#
#files_to_delete = os.listdir(my_scratchdir)
#for f in files_to_delete:
#   os.unlink(os.path.join(my_scratchdir,f))
#os.rmdir(my_scratchdir)
#

f = Filter()
f.add(from_string = ' Energy eigenvalues in atomic units',
      to_re       = 'Relative real eigenvalues in other units;',
      rel_tolerance = 1.0e-5)

test.run(['eom_ee_linear_0g.inp', 'eom_ee_linear_0g_restart.inp'], ['f2.xyz'], f, args='--mw=110 --keep_scratch --scratchful='+my_scratchdir)

shutil.rmtree(my_scratchdir)

sys.exit(test.return_code)
