# Initial setup of the P450cam system
#
# Created by YL Jul 2021
# Revised by YL, KS, TWK Oct-Dec 2021

# Initialise ChemShell
from chemsh import *

# Import a command from the NumPy library for later use
from numpy import unique 

# Read in the P450cam X-ray structure from disk
p450_original = Fragment(coords='1dz8.pdb')

# Create a new Fragment containig only chain A, which includes bound O2
indices_chainA = p450_original.select(chainIDs='A')
p450 = p450_original.getSelected(indices_chainA)

# Delete Tris buffer
p450.delete(residues=['TRS'])

# Delete (potassium) ions which are artefacts of crystalisation
p450.deleteIons()

# Check the segments of the new fragment
print("\n *** p450 segments =\n", unique(p450.segments))

# Give the new system a title
p450.title = 'p450'

# Save the resulting PDB
p450.save('p450_a.pdb')

