# Source this file to initialize all of the crystallography software
# for bash, zsh

if [[ -d /usr/local/xtal/bin ]];then
    PATH=/usr/local/xtal/bin:$PATH
fi


if [[ -d  /usr/local/xtal/ccp4 ]];then
  if [[ -n $ZSH_NAME ]];then
    source /usr/local/xtal/ccp4/include/ccp4.setup-zsh
  else
    source /usr/local/xtal/ccp4/include/ccp4.setup-bash
  fi
fi

if [[ -n $( which ipmosflm | head -n 1 ) ]];then
    alias mosflm=$( which ipmosflm | head -n 1 )
fi

if [[ -d /usr/local/xtal/ccp4mg/  ]];then 
    function ccp4mg { /usr/local/xtal/ccp4mg/bin/ccp4mg "$@" ; }
fi

if [[ -d  /usr/local/xtal/cns_solve_1.1/ ]];then     
    source /usr/local/xtal/cns_solve_1.1/cns.sh
fi

if [[ -d  /usr/local/xtal/coot/ ]];then     
    source /usr/local/xtal/coot/setup/coot.sh
    export PYTHONPATH="$(which python)" 
fi

if [[ -d /usr/local/xtal/DTREK93/  ]];then 
    export DTREK_LOGIN_DIR=/usr/local/xtal/DTREK93/bin
    if [[ -f  $DTREK_LOGIN_DIR/DTREK_LOGIN.sh ]]; then
       source $DTREK_LOGIN_DIR/DTREK_LOGIN.sh    
    fi
fi

if [[ -d  /usr/local/xtal/eden/ ]];then     
    export EDENHOME=/usr/local/xtal/eden
    function eden { /usr/local/xtal/eden/source/eden "$@" ; }
fi

# Copies of these files reside in /usr/local/bin
# if [[ -d  /usr/local/xtal/HKL2000/ &&  -n $ZSH_NAME ]];then    
#    foreach hklprogpathname in /usr/local/xtal/HKL2000/*
#        if [[ -x $hklprogpathname  && ! -d $hklprogpathname ]];then
#            hklprogname=$(basename $hklprogpathname)
#            function $hklprogname { $hklprogpathname "$@" ; }
#        fi
#    end
#fi

if [[ -d /usr/local/xtal/ono/  ]];then     
    export ODAT=/usr/local/xtal/ono/data
    function ono { /usr/local/xtal/ono/bin/lin_ono "$@" ; }
fi

# New ccp4 has phaser in it
if [[ ! -d /usr/local/xtal/ccp4-6.0 &&  -d /usr/local/xtal/phaser-linux-1.3.1/  ]];then     
    function phaser { /usr/local/xtal/phaser-linux-1.3.1/phaser "$@" ; }
fi

if [[ -f  /usr/local/xtal/phenix-1.24.1b/phenix_env.sh  ]];then      
    source /usr/local/xtal/phenix-1.24.1b/phenix_env.sh 
fi

if [[ -d /usr/local/xtal/pymol  ]];then     
    function pymol { /usr/local/xtal/pymol/pymol "$@" ; }
fi

# This doesn't seem to work right:
#if [[ -d /usr/local/xtal/usf/ &&  -n $ZSH_NAME  ]];then   
# I've also created symbolic links for users of tcsh and bash  
# foreach progpathname in /usr/local/xtal/usf/*/lx_*
#        lx_progname=$(basename $progpathname)
#        progname=${lx_progname/lx_/}
#        function $progname { $progpathname "$@" ; }
#    end
#fi
#cd $OWD

#XUSERFILESEARCHPATH=/usr/local/xtal/DTREK93/bin_linux/X/%N:/usr/local/xtal/ccp4-6.0/lib/X11/app-defaults/%N:/etc/X11/app-defaults:$XUSERFILESEARCHPATH
XUSERFILESEARCHPATH=/usr/local/xtal/DTREK93/bin_linux/X/%N:/usr/local/xtal/ccp4-6.0/lib/X11/app-defaults/%N:/etc/X11/app-defaults

export XUSERFILESEARCHPATH

export XKEYSYMDB=/usr/share/X11/XKeysymDB
export LANG=C

if [[ -d /usr/local/xtal/shelx/bin ]];then
    PATH=/usr/local/xtal/shelx/bin:$PATH
    export PATH
fi

if [[ -d /usr/local/xtal/XtalView ]];then
    source /usr/local/xtal/XtalView/XtalView.env.sh 
fi
