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='resp', 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.60878, 0.30470, 0.30408])
#testutils.validate(h2o.charges, reference, tol=5e-4)

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

