#! /bin/bash

# This script installs lammps automatically in a directory /share/apps/lammps_gnu_5May15.
# Execute as su

## requirement (mandatory):

## /share/apps/mpich2/3.1.4/gcc
## /share/apps/fftw-3.3.4/gnu/lib
## /share/apps/atlas-3-10-2/gnu/lib (Atlas libraries for lapack and blas, tuned version)

### default mpic++ is from 
## /usr/lib64/mpich/
# /usr/lib64/mpich/bin/mpic++ 
# /usr/lib64/mpich/lib 
# /usr/lib64/mpich/include
### ignore #####################

## python-devel.x86_64 is installed. Check this out by typing 'which python-config'. If it returns /usr/bin/python-config, then it is fine. Else yum install python-devel.x86_64.


####### begin installation ####################################################
cd /share/apps
mkdir mylammps_gnu_5May15
cd mylammps_gnu_5May15
mylammpsdir=$(echo $PWD)
echo mylammpsdir= $mylammpsdir
cp /share/apps/configrepo/mylammps_gnu_5May15.tar.gz .
#wget http://www2.fizik.usm.my/configrepo/howto/mylammps/mylammps_gnu_5May15.tar.gz
tar -xzvf mylammps_gnu_5May15.tar.gz
mv mylammps_gnu_5May15.tar.gz configrepo
mv mylammps/* .
rm -rf mylammps

# linalg #
cd $mylammpsdir/lib/linalg
rm -f *.a *.o
make -f Makefile.gfortran


# atc #
cd $mylammpsdir/lib
cd atc
rm -f *.a *.o
wget http://www2.fizik.usm.my/configrepo/howto/mylammps/gnu/Makefile.lammps.atc.atlas
rm -rf Makefile.lammps.installed
cp Makefile.lammps.atc.atlas Makefile.lammps.installed
make -f Makefile.mpic++

# cuda # Make only if CUDA is available on the machine 
# cd $mylammpsdir/lib
# cd cuda
# make 

# gpu ## Make only if CUDA is available on the machine 
#cd $mylammpsdir/lib
#cd gpu
#rm -f *.a *.o
#rm -f Makefile.lammps
#wget http://www2.fizik.usm.my/configrepo/howto/mylammps/lammps_tmpl_5March_12_gnu_sa/lib/gpu/Makefile.lammps .
#wget http://www2.fizik.usm.my/configrepo/howto/mylammps/lammps_tmpl_5March_12_gnu_sa/lib/gpu/Makefile.anicca .
#make -f Makefile.anicca

# meam #
cd $mylammpsdir/lib
cd meam
rm -f *.a *.o
make -f Makefile.gfortran

# poems #
cd $mylammpsdir/lib
cd poems
rm -f *.a *.o
make -f Makefile.g++


# reax #
cd $mylammpsdir/lib/reax
rm -f *.a *.o
make -f Makefile.gfortran

#cd $mylammpsdir/lib/voronoi
#ln -s voro++-0.4.6/src /share/apps/voro++-0.4.6/include
#ln -s voro++-0.4.6/src /share/apps/voro++-0.4.6/include

cd $mylammpsdir/lib/qmmm
rm -f *.a *.o
make -f Makefile.gfortran

cd $mylammpsdir/lib/colvars
rm -f *.a *.o
make -f Makefile.g++

cd $mylammpsdir/lib/awpmd
wget http://www2.fizik.usm.my/configrepo/howto/mylammps/gnu/Makefile.lammps.awpmd.atlas
rm -rf Makefile.lammps.installed
cp Makefile.lammps.awpmd.atlas Makefile.lammps.installed
make -f Makefile.mpicc

# Now exit /lib 

cd $mylammpsdir/src/MAKE
#wget http://www2.fizik.usm.my/configrepo/howto/mylammps/gnu/Makefile.gnu
wget http://www2.fizik.usm.my/configrepo/howto/mylammps/gnu/Makefile.gnu.mpich2
cd ../

make yes-all
make no-user-quip
make no-kim
make no-voronoi
make no-kokkos
make no-user-molfile
make no-user-cuda ## uncomment if got cuda installed
make no-gpu ## uncomment if got cuda installed
make no-user-intel
#make no-user-awpmd
#make no-user-colvars
#make no-user-qmmm

#make gnu
make gnu.mpich2
rm -rf lmp_gnu
ln -s lmp_gnu.mpich2 lmp_gnu

### creating link
cd /share/apps/local/bin
rm -rf lmp_gnu
ln -s $mylammpsdir/src/lmp_gnu .
