# TURBOMOLE NO2 doublet UHF optimisation
from chemsh import *
from chemsh.utils import testutils

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

# default: convergence='tightscf'
turbomole = TURBOMOLE(frag=no2, method="hf", basis="SVP", scftype="uhf", mult=2)

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