#! /bin/bash

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

## requirements (mandatory):
### icc
## /share/apps/fftw3
## /share/apps/intel/Compiler/11.1/072/mkl
### /share/apps/estools/mpich2/3.1.4/intel/bin/mpic++
### /share/apps/mpich2/bin/mpic++ 
### default gcc as in rocsk 6.1.1


####### begin installation ####################################################
cd /share/apps/configrepo
mkdir mylammps_intel_5May15
cd mylammps_intel_5May15
mylammpsdir=$(echo $PWD)
echo mylammpsdir= $mylammpsdir

wget http://www2.fizik.usm.my/configrepo/howto/mylammps/mylammps_gnu_5May15.tar.gz
tar -xzvf mylammps_gnu_5May15.tar.gz
mv mylammps/* .
rm -rf mylammps

# linalg #
cd $mylammpsdir/lib/linalg
make -f rm -f *.a *.o
make -f Makefile.gfortran
#wget http://www2.fizik.usm.my/configrepo/howto/mylammps/lammps_tmpl_5March_12_gnu_sa/lib/linalg/Makefile.anicca .
#make -f Makefile.anicca


# atc #
cd $mylammpsdir/lib
cd atc
rm -f *.a *.o
## --with-lapack=-llapack -lcblas -latlas --with-blas=-lcblas -lf77blas -latlas
wget http://www2.fizik.usm.my/configrepo/howto/mylammps/intel/Makefile.lammps.atc
cp Makefile.lammps.atc Makefile.lammps.installed
wget http://www2.fizik.usm.my/configrepo/howto/mylammps/intel/Makefile.mpic++.atc
mv Makefile.mpic++.atc Makefile.mpic++
make -f Makefile.mpic++

# cuda #
cd $mylammpsdir/lib
cd cuda
make 

# gpu #
#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
mv Makefile.lammps.ifort Makefile.lammps.ifort.orig
wget http://www2.fizik.usm.my/configrepo/howto/mylammps/intel/Makefile.lammps.ifort
make -f Makefile.ifort

# poems #
cd $mylammpsdir/lib
cd poems
rm -f *.a *.o
#wget http://www2.fizik.usm.my/configrepo/howto/mylammps/lammps_tmpl_5March_12_gnu_sa/lib/poems/Makefile.anicca .
 make -f Makefile.icc


# reax #
cd $mylammpsdir/lib/reax
rm -f *.a *.o
#rm -f Makefile.lammps
#wget http://www2.fizik.usm.my/configrepo/howto/mylammps/lammps_tmpl_5March_12_gnu_sa/lib/reax/Makefile.lammps .
#wget http://www2.fizik.usm.my/configrepo/howto/mylammps/lammps_tmpl_5March_12_gnu_sa/lib/reax/Makefile.anicca .
make -f Makefile.ifort


#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
make -f Makefile.gfortran

cd $mylammpsdir/lib/colvars
make -f Makefile.g++

#cd $mylammpsdir/lib/awpmd
#make -f Makefile.mpicc


# Now exit /lib 

cd $mylammpsdir/src/MAKE
#wget http://www2.fizik.usm.my/configrepo/howto/mylammps/intel/Makefile.mpich_icc
wget http://www2.fizik.usm.my/configrepo/howto/mylammps/intel/Makefile.ytl
cd ../

rm -f *.a *.o
make yes-all
make no-user-quip
make no-user-cuda
make no-gpu
make no-user-awpmd
make no-kim
make no-voronoi
make no-user-colvars
#make no-user-qmmm
make no-kokkos
make no-user-intel
make no-user-molfile

make ytl

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