#
# 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 = MNDO(method="am1")
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

# Test result from Tcl-ChemShell
eref = -0.084715196531

testutils.validate(ecalc, eref, tol=1.0e-7)
