from numpy        import array
from chemsh       import *
from chemsh.utils import testutils

# Load in a single QM water molecule and a single MM water molecule
h2o = Fragment(coords='h2o_bq.pun')

# Set up QM calc
qm = GAMESS_UK(frag=h2o, method='hf', basis='sto3g', scftype='rhf', direct=False)

# In Tcl-ChemShell, tolerance is 1e-12
qfit = ChargeFitting(theory=qm, method='esp', npoints=20, type='shell', vdw_scale=1.5, nlayers=1, tolerance=1e-12)

# Run the charge fitting
qfit.run()

# Reference values from Tcl-ChemShell
# TD 10/04/2024 The tol has to be low as the Tcl-ChemShell interface to GAMESS-UK
# loses precision on reading in electrostatic potentials (not enough decimals
# written to the output file and not given in atomic units)
#reference = array([-0.62909, 0.31514, 0.31396])
#testutils.validate(h2o.charges, reference, tol=5e-4)

# Reference values from Py-ChemShell
reference = array([-0.6291735605072998, 0.31517846273762534, 0.3139950977696744])
testutils.validate(h2o.charges, reference, tol=1e-6)
