# Construct an MgO surface cluster from a CIF file

# Initialise ChemShell
from chemsh import *
from chemsh.io.tools import convert_atoms_to_frag
from sys import stdout

# NB this example requires ASE to be installed
from ase.io import read

# Read in CIF data and convert to a ChemShell Fragment
mgo = convert_atoms_to_frag(read('slab_mgo.cif'), connect_mode='ionic', twoDimensional=True)
mgo.addCharges({'O' :-2.0, 
                'Mg':2.0})
mgo.addShells('O', displace=0.0, charges={'O':-2.792547})

# Cut out cluster from periodic fragment
# Note distances are in bohr and python counts atoms from zero
cluster = mgo.construct_cluster(origin=40, radius_cluster=40.0,
                                adjust_charge='coordination_scaled',
                                radius_active=24.0, bq_margin=2.0,
                                bq_density=5, bq_layer=12.0)

# Save the resulting cluster in ChemShell punch format
cluster.save('mgo_shells_cluster_cif.pun', 'pun')
