#!/bin/sh
#
##############################################################
#
# stc_batch_1 - version 1.0 Feb 27/2003
#
# the following script can be used to bypass the graphics
# mode of stc and run several pdb files for binding calculations.
#
# the script makes a number of assumptions in how you want to 
# make the calculations. It is your responsibility to verify 
# that this is what you want stc to do. I suggest you only
# run this script on one pdb first before doing several.
#
##############################################################

# Where can i find the stc programs
# if you type 'calc_asa' and get 'command not found'
# then you may want to set up your environment to include
# the path to these programs.

CALC_ASA="calc_asa pdbtodia addradii edpdb access"
THERMO="thermo"

# Where can I find your amino definitions file? The answer
# to this question may depend on where you installed stc.
# Or perhaps you are going to use your own definitions file.

AMINO_DEF="/software/local/lib/stc/amino.def"

# This is how i will find all the pdb files for processing
# the default is to look in the current directory for files with .pdb suffix

PDB_FILES=`ls -1 ./*.pdb`

# This is where i put the temporary output files after each run
# Note that i will be removing any previous files first.

TMP=./stc.tmp
\rm -rf $TMP
mkdir $TMP


# Make accessible surface area files for each pdb
# Note that I have assumed your ligand is entered first in the complex pdb

for i in $PDB_FILES; do 

	echo "Calculating ASA for $i"
	COMPLEX=$i.complex
	LIGAND=$i.ligand
	ENZYME=$i.enzyme

	# make sure stc is going to understand your pdb file
	fix_pdb 2 $i $COMPLEX $LIGAND $ENZYME > $i.fixpdb.log

	# calculate each part
	$CALC_ASA $COMPLEX $COMPLEX.acc $COMPLEX.dia $COMPLEX.radii $COMPLEX.edpdb > $COMPLEX.log
	$CALC_ASA $LIGAND $LIGAND.acc $LIGAND.dia $LIGAND.radii $LIGAND.edpdb > $LIGAND.log
	$CALC_ASA $ENZYME $ENZYME.acc $ENZYME.dia $ENZYME.radii $ENZYME.edpdb > $ENZYME.log


##############################################################

# Here we do thermodynamics calculations for each ASA file.
# Since the thermo program was designed to be interactive, we need to echo
# the correct answers to the program. The following is only one possible
# way that you can answer the questions. When you analyze your first run,
# you should type "thermo" and confirm that the answers presented here is
# how you want to make the calculations.

	echo "Thermodynamics calculations for $i"
	echo " 1
	$i.basic
	$i.detail
	$AMINO_DEF
	$LIGAND.acc
	$ENZYME.acc
	$COMPLEX.acc
	n
	n
	n
	3
	1
	5
	0 " | $THERMO > $i.thermo.log

	# clean up your files
	mv $LIGAND $ENZYME $COMPLEX $TMP
	mv *.acc *.dia *.radii *.edpdb $TMP
	mv *.log $TMP

	# do some intermediate stats
	grep DGbind $i.basic
	echo " "

done

#
# Now let's sort the basic output files according to delta G binding.
# Of course, you may want to do your own stats using your own scripts.
# Please feel free to tell me and i will advertise them on the stc
# website. cheers,
#
#
\rm -rf out.dgbind
grep DGbind *.basic | sort -k 3,3 > out.dgbind
