# DFTB++ SCC single point energy

from chemsh       import *
from chemsh.utils import testutils

water = Fragment(coords="water_dimer.cjson")

dftbplus = DFTBplus(frag=water, skf_path="slakos/mio-1-1/", dispersion='MBD')

sp = SP(theory=dftbplus)

# This test is not supported by all builds of DFTB+
try:
    sp.run()
except SystemExit:
    # Look for "Program must be compiled with the mbd library for MBD-dispersion"
    outFile = open('dftb_in.out')
    for line in outFile.readlines():
        if "Program must be compiled with the mbd library for MBD-dispersion" in line:
            print(" >>> Unsupported test: DFTB+ must be compiled with MBD.", flush=True)
            testutils.setUnsupported()
            exit()

ecalc = sp.result.energy

# Test result from standalone DFTB+
eref = -8.1580237312


testutils.validate(ecalc, eref)
