#
# Water dimer with negatively charged MM water
# (Testing that MM charge does not affect number of electrons in QM calc)
#

from chemsh       import *
from chemsh.utils import testutils

water = Fragment(coords='../h2o_dimer_mmchg.cjson')

ff = '''#
# molmec removes Coulomb terms between bonded atoms
# and between atoms bonded to a common third atom
keyword molmec
# Flexible TIP3P model
# last number in LJ term is a cutoff
lennard 12 6 kcal x13
O O 582000.0 595.0 99.9
# intramolecular force-field parameters for MM
# from QM calculation on water monomer
# Note GULP k is twice that of ChemShell format
harmonic bond kcal
H O 1059.162 0.96
# Note GULP k is twice that of ChemShell format
# note different ordering of atoms
three bond kcal
O H H  68.087  104.5
'''


qm = PySCF(method="hf", basis="3-21g")
mm = GULP(ff=ff, molecule=True)

qmmm = QMMM(frag=water, qm_region=range(3), qm=qm, mm=mm, embedding='electrostatic', coupling='covalent')

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

sp.run()

ecalc = sp.result.energy

# Tcl-ChemShell 3.7.1/ORCA 4.2.1 reference result
# convergence='tightscf'
#eref = -75.57351823
# convergence='normalscf'
#eref = -75.57351822
# ORCA 5.0.3
#eref = -75.57351823

# pyscf reference
eref = -75.573518234

testutils.validate(ecalc, eref)
