'''Geometry Optimisation of Silicon '''
from datetime import datetime 
from chemsh       import *
from chemsh.utils import testutils
from chemsh.data import unitconvert

begin=datetime.now()

si2 = Fragment(coords='Si2_opt.cjson')

obj = CP2K(frag=si2, functional='lda',basis='DZVP-ALL-PADE',
mixing_method='pulay_mixing',ngrids=4,
precision_all='1.0E-8',
 )

opt = Opt(theory=obj, algorithm='lbfgs',maxcycle=200,
trust_radius='energy')
          
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 = -7.232457015
testutils.validate(ecalc, eref)

