#! /bin/bash

# Run this script to install a lammps-icms in /home/common/nfs
# A folder lamps-icms will be created in /home/common/nfs
# Choose either scp from www2 (not current version) or git (current/latest version) or wget. By default, wget is used.
# Make sure you have git installed, or yum install git.x86_64 as root, if you wish to download with git clone (instead of scp)

cd /home/common/nfs
#scp -r tlyoon@www2.fizik.usm.my:/home/tlyoon/repo/lammps-icms .
#git clone http://git.icms.temple.edu/lammps-icms.git lammps-icms  #git clone takes a bit longer time to complete.
wget http://www2.fizik.usm.my/configrepo/howto/lammps-icms/lammps-icms.tar
tar -xvf lammps-icms.tar
#################################################################

cd lammps-icms

cd lib
cd atc
wget http://www2.fizik.usm.my/configrepo/howto/lammps-icms/Makefile.g++.lammps.atc.rocks53
mv Makefile.g++ Makefile.g++.bk
cp Makefile.g++.lammps.atc.rocks53 Makefile.g++
make -f Makefile.g++

cd ..
cd linalg
wget http://www2.fizik.usm.my/configrepo/howto/lammps-icms/Makefile.gfortran.linalg.rocks53
mv Makefile.gfortran Makefile.gfortran.bk
cp Makefile.gfortran.linalg.rocks53 Makefile.gfortran
make -f Makefile.gfortran

cd ..
cd meam  
make -f Makefile.gfortran


cd ..
cd reax  
wget http://www2.fizik.usm.my/configrepo/howto/lammps-icms/Makefile.gfortran.reax.rocks53
mv Makefile.gfortran Makefile.gfortran.bk
cp Makefile.gfortran.reax.rocks53 Makefile.gfortran
make -f Makefile.gfortran

cd ..
cd poems
make -f Makefile.g++

cd ..
cd ..

cd src
make yes-all 
make no-gpu

cd MAKE
wget http://www2.fizik.usm.my/configrepo/howto/lammps-icms/Makefile.g++.MAKE.CENTOS6
cp Makefile.g++ Makefile.g++.bk
cp Makefile.g++.MAKE.CENTOS6 Makefile.g++
cd ..
make g++


### This writes an alias lg++ in common's .bashrc
echo 'alias lg++="/home/common/nfs/lammps-icms/src/lmp_g++"' >> ~/.bashrc

. ~/.bashrc

### To test whether the lammps-icms just installed indeed was successful, issue the command to test run colloid found in 
/home/common/nfs/lammps-icms/examples. You can also test run other examples by properly changing the name of the input file in.*


### To run the test 'colloid':
mpiexec -f ~/hosts -np 4 lg++ < /home/common/nfs/lammps-icms/examples/colloid/in.colloid 
### The integer -np 4 refers to the number of processors, NP = 1, 2, 3, 4. ...
