#! /bin/bash

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

## requirement (mandatory):

## /share/apps/openmpi-1.8.5/gcc_4.9.0
## /share/apps/gcc-4.9.0
## /share/apps/fftw-3.3.4/gnu/lib
## /share/apps/atlas-3-10-2/gnu/lib (Atlas libraries for lapack and blas, tuned version)


## 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 install python-dev.


####### 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++ ## use /share/apps/openmpi-1.8.5/gcc_4.9.0/bin/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
make -f Makefile.linux #/share/apps/openmpi-1.8.5/gcc_4.9.0/bin/mpic++

# 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 #cxx=/share/apps/openmpi-1.8.5/gcc_4.9.0/bin/mpic++

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.openmpi
cd ../

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

#make gnu
make gnu.openmpi
rm -rf lmp_gnu
ln -s lmp_gnu.openmpi lmp_cuda

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