from chemsh       import *
from chemsh.utils import testutils

# read in the partitioned fragment from punch file
mgo_cluster = Fragment(coords='../../02b_partitioning_explicit/mgo_shells_qmmm_explicit.pun', connect_mode=None)

# use the total charge for QM
qm_charge = int(mgo_cluster.totalcharge)

# has to be "GAMESS_UK" for "GAMESS-UK" is illegal in Python!
qm_theory = GAMESS_UK(method='dft',
                      functional='blyp',
                      # use external basis set file from https://www.basissetexchange.org
                      basis='mgo_gamess-uk.bas',
                      # you'd better well name the filename
                      separate_ecps=True,
                      ecp='mgo_gamess-uk_explicit_separate.ecp',
                      charge=qm_charge,
                     )

mm_theory = GULP(ff='mgo_2body.ff',
                 # conjugate gradients
                 conjugate=True)

# in explicit mode the interface region should not be included in QM selection
qm_region = mgo_cluster.getRegion(1)
# alternative:
qm_region = mgo_cluster.getRegion("1")
print(" qm_region =", qm_region)

# fragment is assigned to QMMM instance
qmmm = QMMM(qm=qm_theory,
            mm=mm_theory,
            frag=mgo_cluster,
            qm_region=qm_region,
            # choose coupling='ionic' to switch off link atom and charge shift (those required by coupling='covalent')
            coupling='ionic',
            # normally shell relaxation converges robustly within 20 cycles
            shl_maxcycles=10,
            # default: 0.0001 although higher criterion can be reached
            shl_tolerance=0.001)

# create a single-point task instance and run
# alternative: sp = SP(theory=qmmm).run()
sp = SP(theory=qmmm)
sp.run()


