# MgO shell model single point using the GULP library potential bush.lib

# The location of the GULP potential library should be specified
# in the GULP_LIB environment variable before running this test.

from chemsh       import *
from chemsh.utils import testutils
from os import environ

mgo = Fragment(coords="mgo.cjson", shellatoms=range(8))

mm = GULP(frag=mgo, ff="bush")

# Check that the environmental variable GULP_LIB has been set
# NB: Do not set it in this input file, as all MPI processes need to see it.
if "GULP_LIB" not in environ.keys():
    print(" >>> Unsupported test: GULP_LIB must be set first.", flush=True)
    testutils.setUnsupported()
    exit()

sp = SP(theory=mm, gradients=True)
sp.run()

ecalc = sp.result.energy

# Test result
# NB the explicit forcefield definition used in other MgO tests
# is taken from bush.lib, so the result should be identical
eref = -5.98354835
testutils.validate(ecalc, eref)
