# TURBOMOLE NO2+ DFT (BLYP) optimisation

from chemsh import *
from chemsh.utils import testutils

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

# default functional is 'blyp'
# default: convergence='tightscf'
turbomole = TURBOMOLE(
    frag=no2, method="dft", use_ri=True, functional="b-lyp", basis="SVP", charge=1
)

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 = "no2p_opt_blyp_ri"
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)
