''' CASTEP Geometry Optimisation of butanol '''

# Note this is a long test so is not included in the standard validation test set.
# But is useful to check atom mapping in CASTEP inputs is working OK.

from chemsh       import *
from chemsh.utils import testutils

butanol = Fragment(coords='butanol.cjson')

castep_obj = CASTEP(frag=butanol, functional='pbe',
cut_off_energy='350 eV',maxiter=60,
mixing_scheme='pulay',rand_seed='123654')

opt = Opt(theory=castep_obj, algorithm='lbfgs',maxcycle=200,
trust_radius='energy')
          
opt.run()

ecalc = opt.result.energy[0]

print(f'Optimised Energy:{ecalc}')

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