# TURBOMOLE HF single point energy

from chemsh import *
from chemsh.utils import testutils

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


# default: convergence='tightscf'
# setting dummy charge to make sure the user supplied control (which overrides it) is being used
turbomole = TURBOMOLE(frag=water, charge=100, user_control="./user_control.txt")

opt = Opt(
    theory=turbomole,
    algorithm="lbfgs",
    tolerance=0.0003,
    trust_radius="energy",
    maxcycle=1000,
    maxene=100,
    maxstep=1.0,
)

opt.run()

ecalc = opt.result.energy

fname = "h2o_opt_hf"
with open("./tcl_results.dat", "r") as tclres:
    for l in tclres:
        if fname + ".chm" in l:
            eref = float(l.split(":")[-1])


testutils.validate(ecalc, eref)
