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

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

ref = Fragment(coords='mgo.cjson', connect_mode='ionic')
ref.save('mgo_save.pun', 'pun')
saved = Fragment(coords='mgo_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 connectivity
testutils.validate(saved.conn, ref.conn)

