# TURBOMOLE DFT (BLYP) optimisation

from chemsh import *
from chemsh.utils import testutils

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

# default: convergence='tightscf'
turbomole = TURBOMOLE(frag=water, method="dft", functional="b-lyp", basis="SVP")

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

opt.run()

ecalc = opt.result.energy

fname = "h2o_opt_blyp"
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)
