#! /bin/bash

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

## requirement (mandatory):

## /share/apps/openmpi-1.8.5/intel/bin
## /share/apps/intel/Compiler/11.0/081/lib/intel64
## /share/apps/intel/impi/4.1.0.024/
## /share/apps/intel/Compiler/11.1/072/mkl/include/fftw
## /share/apps/intel/Compiler/11.1/072/mkl/lib/em64t/libfftw2xc_intel.a
## must use gcc-4.9.0, located at /share/apps/gcc-4.9.0

## 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 or apt-get python-dev


####### begin installation ####################################################
cd /share/apps
mkdir mylammps_intel_5May15
cd mylammps_intel_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

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

# linalg #
cd $mylammpsdir/lib/linalg
rm -f *.a *.o
make -f Makefile.gfortran ## use /share/apps/openmpi-1.8.5/intel/bin/mpif90 in place of gfotran

# atc #
cd $mylammpsdir/lib
cd atc
rm -f *.a *.o
wget http://www2.fizik.usm.my/configrepo/howto/mylammps/intel/Makefile.lammps.atc.mkl
rm -rf Makefile.lammps.installed
cp Makefile.lammps.atc.mkl Makefile.lammps.installed
make -f Makefile.mpic++ ## CC=use /share/apps/openmpi-1.8.5/intel/bin/mpic++

cuda # if cuda is to be compiled, gcc.4.9.0 must be used or else it wont work.
cd $mylammpsdir/lib
cd cuda
make 

# gpu ## if cuda is to be compiled, gcc.4.9.0 must be used or else it wont work.
cd $mylammpsdir/lib
cd gpu
rm -f *.a *.o
rm -f Makefile.lammps
make -f Makefile.linux # CUDR_CPP = /share/apps/openmpi-1.8.5/intel/bin/mpic++ -DMPI_GERYON -DUCL_NO_EXIT -DMPICH_IGNORE_CXX_SEEK. gcc=4.9.0

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

# poems #
cd $mylammpsdir/lib
cd poems
rm -f *.a *.o
make -f Makefile.g++  ##use CC = /share/apps/openmpi-1.8.5/intel/bin/mpicxx

# reax #
cd $mylammpsdir/lib/reax
rm -f *.a *.o
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
rm -f *.a *.o
make -f Makefile.gfortran ##/use mpicxx=share/apps/openmpi-1.8.5/intel/bin/mpicxx

cd $mylammpsdir/lib/colvars
rm -f *.a *.o
make -f Makefile.g++  #use mpicxx=/share/apps/openmpi-1.8.5/intel/bin/mpicxx

cd $mylammpsdir/lib/awpmd
wget http://www2.fizik.usm.my/configrepo/howto/mylammps/intel/Makefile.lammps.awpmd.mkl
rm -rf Makefile.lammps.installed
cp Makefile.lammps.awpmd.mkl Makefile.lammps.installed
make -f Makefile.mpicc #CC=/share/apps/openmpi-1.8.5/intel/bin/mpicxx

# Now exit /lib 

cd $mylammpsdir/src
make clean-all
make yes-all
make no-user-quip
make no-kim
make no-voronoi
make no-user-colvars
make no-user-qmmm
make no-h5md
make no-smd
make no-colvars

#make no-kokkos
#make no-user-molfile
#make no-user-awpmd
#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 intel.openmpi

rm -rf lmp_intel
ln -s lmp_intel.openmpi lmp_intel

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