# CASTEP DFT single point energy

import chemsh
from chemsh       import *
from chemsh.utils import testutils
from datetime import datetime
begin=datetime.now()

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

# default functional is 'lda'
castep_obj = CASTEP(frag=water,
cut_off_energy='150 eV',
functional='lda')

sp = SP(theory=castep_obj, gradients=True)

sp.run(dryrun=False)

ecalc = sp.result.energy[0]
gradients = sp.result.gradients

print(f"Final energy is {ecalc}")

print(f"Gradients: \n{gradients}\n")
end=datetime.now()
print(f'Total elapsed time={(end-begin)}')

# Test result
eref = -15.189309715
testutils.validate(ecalc, eref)
