# Partition ionic MgO surface cluster using the explicit interface
# For testing purposes, do not remove any shells in region 2

from chemsh import *
from chemsh.utils import testutils

# Cluster with QM atoms labelled
mgo = Fragment(coords='mgo2d_cluster_qm.pun', connect_mode='ionic')

# Origin from original cluster cutting process
# Using coordinate array for testing purposes
origin = [ 0.00000000000000, 3.97947900462654, -3.93802223588453 ] 

cluster = mgo.partition(origin=origin, cutoff_boundary=6.0, radius_active=10.0,
                        qmmm_interface='explicit')

cluster.save('mgo2d_cluster_explicit.pun', 'pun')

# Tcl-ChemShell reference
ref = Fragment(coords='tcl-chemshell/ref/ref_surface_partition_explicit.pun', connect_mode='ionic')

# Test atoms
testutils.validate(cluster.natoms , ref.natoms)
# TODO test region labels
# testutils.validate(cluster.names  , ref.names)
testutils.validate(cluster.znums  , ref.znums)
testutils.validate(cluster.coords , ref.coords , tol=1.0e-10)
testutils.validate(cluster.charges, ref.charges, tol=1.0e-10)
testutils.validate(cluster.shellatoms, ref.shellatoms)

# Test shells
testutils.validate(cluster.shells.coreatoms, ref.shells.coreatoms)
testutils.validate(cluster.shells.coords   , ref.shells.coords , tol=1.0e-10)
testutils.validate(cluster.shells.charges  , ref.shells.charges, tol=1.0e-10)

# Test QM charge of neutral cluster
testutils.validate(cluster.totalcharge, ref.totalcharge, tol=1.0e-10)
