''' Geometry Optimisation of water molecule '''

# NB At present this is too slow to add to the standard test suite
# (it take approx. 10 minutes to run on 1 core)

from chemsh       import *
from chemsh.utils import testutils
from datetime import datetime 
from chemsh.data import unitconvert

begin=datetime.now()

water = Fragment(coords='water_opt.cjson')
#water = Fragment(coords='water_opt_frac.cjson')

obj = CP2K(frag=water, functional='pbe',
basis={'H': 'DZVP-GTH-PADE','O':'DZVP-GTH-PADE'},
ngrids=5,pseudopotential='GTH-BLYP',
grid_cutoff = 200,
grid_real_cutoff = 30,
)

opt = Opt(theory=obj, 
 algorithm='lbfgs',maxcycle=100,
trust_radius='energy', gradients=True)
          
#opt.run(dryrun='True')
opt.run()

ecalc = opt.result.energy[0]

end=datetime.now()
print(f'Total elapsed time={(end-begin)}') 
print(f'Optimised Energy:{ecalc} Hartree')
print(f'Optimised Energy:{ecalc*unitconvert.Ha2eV} eV')

eref = -17.162094139
testutils.validate(ecalc, eref)
