#  Test consistency of chemical JSON I/O for a periodic ionic system with shells

from numpy        import array
from chemsh       import *
from chemsh.utils import testutils

ref = Fragment(coords='mgo_shells.cjson', connect_mode='ionic')
ref.save('mgo_shells_save.pun', 'pun')
saved = Fragment(coords='mgo_shells_save.pun', connect_mode='ionic')

# Test cell
testutils.validate(saved.cell.vectors, ref.cell.vectors, tol=1.0e-10)

# Test atoms
testutils.validate(saved.natoms, ref.natoms)
testutils.validate(saved.znums, ref.znums)
testutils.validate(saved.coords, ref.coords, tol=1.0e-10)
testutils.validate(saved.charges, ref.charges, tol=1.0e-10)

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

# Test connectivity
testutils.validate(saved.conn, ref.conn)

