#!/bin/csh -f
echo " "
echo "  MTK++ MCPB example "
echo " "

# Clean up
#rm -rf 1HZY_ZN.README
#rm -rf *.bcl
#rm -rf createLibraries.sh createRespAdditions.sh getCharges.sh
#rm -rf *.pdb
#rm -rf *.log

#cp data/*.pdb .
#cp data/*.bcl .
#cp data/*.log .
#cp data/*.fchk .

echo "Generating scripts "
sh genMetalFF.sh -n 1HZY_ZN

#cp data/1AMP.pdb .
#cp data/1HZY_ZN_fixed.pdb .
#cp data/1HZY_ZN_sidechain.bcl .
#cp data/1HZY_ZN_addStdMol.bcl .
#cp data/1HZY_ZN_large.bcl .
#cp data/1HZY_ZN_large_mk.log .

#cp data/1HZY_ZN_sidechain_fc_md.log .
#cp data/1HZY_ZN_sidechain_opt_md.fchk .
#cp data/1HZY_ZN_sidechain_opt_md.log .

echo "Adding Hydrogens to pdb file "
$AMBERHOME/bin/MCPB -i 1HZY_ZN_addHs.bcl \
                    -l 1HZY_ZN_addHs.bcl.log || goto error

echo "Creating Model 1"
$AMBERHOME/bin/MCPB -i 1HZY_ZN_sidechain.bcl \
                    -l 1HZY_ZN_sidechain.bcl.log || goto error

echo "Adding standard molecule to library "
$AMBERHOME/bin/MCPB -i 1HZY_ZN_addStdMol.bcl \
                    -l 1HZY_ZN_addStdMol.bcl.log || goto error

echo "Creating Model 2 "
$AMBERHOME/bin/MCPB -i 1HZY_ZN_large.bcl \
                    -l 1HZY_ZN_large.bcl.log || goto error

echo "Creating RESP files 0 "
$AMBERHOME/bin/MCPB -i 1HZY_ZN_large_mk0.bcl \
                    -l 1HZY_ZN_large_mk0.bcl.log || goto error
mv 1HZY_ZN_large_respAdds 1HZY_ZN_large_respAdds0 || goto error

echo "Creating RESP files 1 "
$AMBERHOME/bin/MCPB -i 1HZY_ZN_large_mk1.bcl \
                    -l 1HZY_ZN_large_mk1.bcl.log || goto error
mv 1HZY_ZN_large_respAdds 1HZY_ZN_large_respAdds1 || goto error

echo "Creating RESP files 2 "
$AMBERHOME/bin/MCPB -i 1HZY_ZN_large_mk2.bcl \
                    -l 1HZY_ZN_large_mk2.bcl.log || goto error
mv 1HZY_ZN_large_respAdds 1HZY_ZN_large_respAdds2 || goto error

echo "Creating RESP files 3 "
$AMBERHOME/bin/MCPB -i 1HZY_ZN_large_mk3.bcl \
                    -l 1HZY_ZN_large_mk3.bcl.log || goto error
mv 1HZY_ZN_large_respAdds 1HZY_ZN_large_respAdds3 || goto error

echo "Determining charges "
sh ./getCharges.sh 0 || goto error
sh ./getCharges.sh 1 || goto error
sh ./getCharges.sh 2 || goto error
sh ./getCharges.sh 3 || goto error

echo "Creating library files "
$AMBERHOME/bin/MCPB -i 1HZY_ZN_large_chg0.bcl \
                    -l 1HZY_ZN_large_chg0.bcl.log || goto error

$AMBERHOME/bin/MCPB -i 1HZY_ZN_large_chg1.bcl \
                    -l 1HZY_ZN_large_chg1.bcl.log || goto error

$AMBERHOME/bin/MCPB -i 1HZY_ZN_large_chg2.bcl \
                    -l 1HZY_ZN_large_chg2.bcl.log || goto error

$AMBERHOME/bin/MCPB -i 1HZY_ZN_large_chg3.bcl \
                    -l 1HZY_ZN_large_chg3.bcl.log || goto error

#echo "Determining Seminario force constants "
#$AMBERHOME/bin/MCPB -i 1HZY_ZN_sidechain_fc_sem.bcl \
#                    -l 1HZY_ZN_sidechain_fc_sem.bcl.log || goto error

#echo "Determining Traditional force constants "
#$AMBERHOME/bin/MCPB -i 1HZY_ZN_sidechain_fc_md.bcl \
 #                   -l 1HZY_ZN_sidechain_fc_md.bcl.log || goto error

#echo "Exporting Seminario library to AMBER format "
#$AMBERHOME/bin/MCPB -i 1HZY_ZN_toAmberFormats_sem.bcl \
 #                   -l 1HZY_ZN_toAmberFormats_sem.bcl.log || goto error

#echo "Generating toAmberScripts"
#sh ./createToAmber.sh 

#echo "Exporting Traditional library 0 to AMBER format "
#$AMBERHOME/bin/MCPB -i 1HZY_ZN_toAmberFormats_md0.bcl \
#                    -l 1HZY_ZN_toAmberFormats_md0.bcl.log || goto error
#echo "Exporting Traditional library 1 to AMBER format "
#$AMBERHOME/bin/MCPB -i 1HZY_ZN_toAmberFormats_md1.bcl \
#                    -l 1HZY_ZN_toAmberFormats_md1.bcl.log || goto error
#echo "Exporting Traditional library 2 to AMBER format "
#$AMBERHOME/bin/MCPB -i 1HZY_ZN_toAmberFormats_md2.bcl \
#                    -l 1HZY_ZN_toAmberFormats_md2.bcl.log || goto error
#echo "Exporting Traditional library 3 to AMBER format "
#$AMBERHOME/bin/MCPB -i 1HZY_ZN_toAmberFormats_md3.bcl \
#                    -l 1HZY_ZN_toAmberFormats_md3.bcl.log || goto error

#echo "Reading protonated file and updating residue names "
#$AMBERHOME/bin/MCPB -i 1HZY_ZN_resNames.bcl \
 #                   -l 1HZY_ZN_resNames.bcl.log || goto error

echo No errors detected
exit(0)

error:
echo Problem: check log files and try again
exit(1)
