slackbuilds_ponce/academic/lammps/lammps.SlackBuild
Giancarlo Dessi 469fecd964
academic/lammps: Added (molecular simulator).
Signed-off-by: Andrew Clemons <andrew.clemons@gmail.com>

Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
2023-09-03 09:37:13 +07:00

358 lines
14 KiB
Bash

#!/bin/bash
# Slackware build script for lammps
# Copyright 2023 Giancarlo Dessi, Cagliari, IT
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cd $(dirname $0) ; CWD=$(pwd)
PRGNAM=lammps
VERSION=${VERSION:-2023.08.02}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}
SRCNAM=lammps-stable
SRCVERSION=${SRCVERSION:-2Aug2023}
if [ -z "$ARCH" ]; then
case "$( uname -m )" in
i?86) ARCH=i586 ;;
arm*) ARCH=arm ;;
*) ARCH=$( uname -m ) ;;
esac
fi
if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
exit 0
fi
# First detect if openmpi or mpich are installed, so we can build LAMMPS with the
# parallel computing and enable some packages
MP=""
mpi=""
if pkg-config --exists ompi; then
MP="openmpi";
mpi="-DBUILD_OMP=yes "
fi
if pkg-config --exists mpich; then
MP="mpich";
mpi="-DBUILD_MPI=yes "
fi
# These internal packages are enabled by default.
# If you do not require some of them you have to edit the conditions in this block
# otherwise pass the respective environment variables set to "no" to the script
# for each package not desired
# (for example: AMOEBA=no ASPHERE=no ./lammps.SlackBuild)
amoeba="" [ "${AMOEBA:-yes}" = "yes" ] && amoeba="-DPKG_AMOEBA=yes "
asphere="" ; [ "${ASPHERE:-yes}" = "yes" ] && asphere="-DPKG_ASPHERE=yes "
atc="" ; [ "${ATC:-yes}" = "yes" ] && atc="-DPKG_ATC=yes "
awpmd="" ; [ "${AWPMD:-yes}" = "yes" ] && awpmd="-DPKG_AWPMD=yes "
bocs="" ; [ "${BOCS:-yes}" = "yes" ] && bocs="-DPKG_BOCS=yes "
body="" ; [ "${BODY:-yes}" = "yes" ] && body="-DPKG_BODY=yes "
bpm="" ; [ "${BPM:-yes}" = "yes" ] && bpm="-DPKG_BPM=yes "
brownian="" ; [ "${BROWNIAN:-yes}" = "yes" ] && brownian="-DPKG_BROWNIAN=yes "
cgdna="" ; [ "${CGDNA:-yes}" = "yes" ] && cgdna="-DPKG_CG-DNA=yes "
cgspica="" ; [ "${CGSPICA:-yes}" = "yes" ] && cgspica="-DPKG_CG-SPICA=yes "
class2="" ; [ "${CLASS2:-yes}" = "yes" ] && class2="-DPKG_CLASS2=yes "
colloid="" ; [ "${COLLOID:-yes}" = "yes" ] && colloid="-DPKG_COLLOID=yes "
colvars="" ; [ "${COLVARS:-yes}" = "yes" ] && colvars="-DPKG_COLVARS=yes "
compress="" ; [ "${COMPRESS:-yes}" = "yes" ] && compress="-DPKG_COMPRESS=yes "
coreshell="" ; [ "${CORESHELL:-yes}" = "yes" ] && coreshell="-DPKG_CORESHELL=yes "
dielectric="" ; [ "${DIELECTRIC:-yes}" = "yes" ] && dielectric="-DPKG_DIELECTRIC=yes "
diffraction="" ; [ "${DIFFRACTION:-yes}" = "yes" ] && diffraction="-DPKG_DIFFRACTION=yes "
dipole="" ; [ "${DIPOLE:-yes}" = "yes" ] && dipole="-DPKG_DIPOLE=yes "
dpdbasic="" ; [ "${DPDBASIC:-yes}" = "yes" ] && dpdbasic="-DPKG_DPD-BASIC=yes "
dpdmeso="" ; [ "${DPDMESO:-yes}" = "yes" ] && dpdmeso="-DPKG_DPD-MESO=yes "
dpdreact="" ; [ "${DPDREACT:-yes}" = "yes" ] && dpdreact="-DPKG_DPD-REACT=yes "
dpdsmooth="" ; [ "${DPDSMOOTH:-yes}" = "yes" ] && dpdsmooth="-DPKG_DPD-SMOOTH=yes "
drude="" ; [ "${DRUDE:-yes}" = "yes" ] && drude="-DPKG_DRUDE=yes "
eff="" ; [ "${EFF:-yes}" = "yes" ] && eff="-DPKG_EFF=yes "
electrode="" ; [ "${ELECTRODE:-yes}" = "yes" ] && electrode="-DPKG_ELECTRODE=yes "
extracompute="" ; [ "${EXTRACOMPUTE:-yes}" = "yes" ] && extracompute="-DPKG_EXTRA-COMPUTE=yes "
extradump="" ; [ "${EXTRADUMP:-yes}" = "yes" ] && extradump="-DPKG_EXTRA-DUMP=yes "
extrafix="" ; [ "${EXTRAFIX:-yes}" = "yes" ] && extrafix="-DPKG_EXTRA-FIX=yes "
extramolecule="" ; [ "${EXTRAMOLECULE:-yes}" = "yes" ] && extramolecule="-DPKG_EXTRA-MOLECULE=yes "
extrapair="" ; [ "${EXTRAPAIR:-yes}" = "yes" ] && extrapair="-DPKG_EXTRA-PAIR=yes "
fep="" ; [ "${FEP:-yes}" = "yes" ] && fep="-DPKG_FEP=yes "
granular="" ; [ "${GRANULAR:-yes}" = "yes" ] && granular="-DPKG_GRANULAR=yes "
intel="" ; [ "${INTEL:-yes}" = "yes" ] && intel="-DPKG_INTEL=yes "
interlayer="" ; [ "${INTERLAYER:-yes}" = "yes" ] && interlayer="-DPKG_INTERLAYER=yes "
kspace="" ; [ "${KSPACE:-yes}" = "yes" ] && kspace="-DPKG_KSPACE=yes "
lepton="" ; [ "${LEPTON:-yes}" = "yes" ] && lepton="-DPKG_LEPTON=yes "
machdyn="" ; [ "${MACHDYN:-yes}" = "yes" ] && machdyn="-DPKG_MACHDYN=yes "
manifold="" ; [ "${MANIFOLD:-yes}" = "yes" ] && manifold="-DPKG_MANIFOLD=yes "
manybody="" ; [ "${MANYBODY:-yes}" = "yes" ] && manybody="-DPKG_MANYBODY=yes "
mc="" ; [ "${MC:-yes}" = "yes" ] && mc="-DPKG_MC=yes "
mdi="" ; [ "${MDI:-yes}" = "yes" ] && mdi="-DPKG_MDI=yes -DDOWNLOAD_MDI=yes "
meam="" ; [ "${MEAM:-yes}" = "yes" ] && meam="-DPKG_MEAM=yes "
mesont="" ; [ "${MESONT:-yes}" = "yes" ] && mesont="-DPKG_MESONT=yes "
mgpt="" ; [ "${MGPT:-yes}" = "yes" ] && mgpt="-DPKG_MGPT=yes "
misc="" ; [ "${MISC:-yes}" = "yes" ] && misc="-DPKG_MISC=yes "
mlhdnnp="" ; [ "${MLHDNNP:-yes}" = "yes" ] && mlhdnnp="-DPKG_ML-HDNNP=yes "
mliap="" ; [ "${MLIAP:-yes}" = "yes" ] && mliap="-DPKG_ML-IAP=yes -DMLIAP_ENABLE_PYTHON=autodetected "
mlpace="" ; [ "${MLPACE:-yes}" = "yes" ] && mlpace="-DPKG_ML-PACE=yes "
mlpod="" ; [ "${MLPOD:-yes}" = "yes" ] && mlpod="-DPKG_ML-POD=yes "
mlrann="" ; [ "${MLRANN:-yes}" = "yes" ] && mlrann="-DPKG_ML-RANN=yes "
mlsnap="" ; [ "${MLSNAP:-yes}" = "yes" ] && mlsnap="-DPKG_ML-SNAP=yes "
mofff="" ; [ "${MOFFF:-yes}" = "yes" ] && mofff="-DPKG_MOFFF=yes "
molecule="" ; [ "${MOLECULE:-yes}" = "yes" ] && molecule="-DPKG_MOLECULE=yes "
opt="" ; [ "${OPT:-yes}" = "yes" ] && opt="-DPKG_OPT=yes "
orient="" ; [ "${ORIENT:-yes}" = "yes" ] && orient="-DPKG_ORIENT=yes "
peri="" ; [ "${PERI:-yes}" = "yes" ] && peri="-DPKG_PERI=yes "
phonon="" ; [ "${PHONON:-yes}" = "yes" ] && phonon="-DPKG_PHONON=yes "
plugin="" ; [ "${PLUGIN:-yes}" = "yes" ] && plugin="-DPKG_PLUGIN=yes "
poems="" ; [ "${POEMS:-yes}" = "yes" ] && poems="-DPKG_POEMS=yes "
ptm="" ; [ "${PTM:-yes}" = "yes" ] && ptm="-DPKG_PTM=yes "
qeq="" ; [ "${QEQ:-yes}" = "yes" ] && qeq="-DPKG_QEQ=yes "
qtb="" ; [ "${QTB:-yes}" = "yes" ] && qtb="-DPKG_QTB=yes "
reaction="" ; [ "${REACTION:-yes}" = "yes" ] && reaction="-DPKG_REACTION=yes "
reaxff="" ; [ "${REAXFF:-yes}" = "yes" ] && reaxff="-DPKG_REAXFF=yes "
replica="" ; [ "${REPLICA:-yes}" = "yes" ] && replica="-DPKG_REPLICA=yes "
rigid="" ; [ "${RIGID:-yes}" = "yes" ] && rigid="-DPKG_RIGID=yes "
shock="" ; [ "${SHOCK:-yes}" = "yes" ] && shock="-DPKG_SHOCK=yes "
smtbq="" ; [ "${SMTBQ:-yes}" = "yes" ] && smtbq="-DPKG_SMTBQ=yes "
sph="" ; [ "${SPH:-yes}" = "yes" ] && sph="-DPKG_SPH=yes "
spin="" ; [ "${SPIN:-yes}" = "yes" ] && spin="-DPKG_SPIN=yes "
srd="" ; [ "${SRD:-yes}" = "yes" ] && srd="-DPKG_SRD=yes "
tally="" ; [ "${TALLY:-yes}" = "yes" ] && tally="-DPKG_TALLY=yes "
uef="" ; [ "${UEF:-yes}" = "yes" ] && uef="-DPKG_UEF=yes "
yaff="" ; [ "${YAFF:-yes}" = "yes" ] && yaff="-DPKG_YAFF=yes "
# If OpenBLAS is installed ELECTRODE will be enabled using the system LAPACK
# otherwise a bundled linear algebra is used. To force the use of internal
# linear algebra edit the CMake flag setting "-DUSE_INTERNAL_LINALG=yes "
if [ "$electrode" = "-DPKG_ELECTRODE=yes " ]; then
if pkg-config --exists openblas; then
electrode=$electrode"-DUSE_INTERNAL_LINALG=no "
fi
fi
if [ "${PYTHON:-yes}" = "yes" ]; then
python="-DPKG_PYTHON=yes "
else
python=""
mliap=""
fi
# The GPU package requires some basic settings that may be customized through environment
# variables. For advanced options requiring specific hardware configurations (GPU) see the
# documentation in lammps.org
# This package causes many issues depending on the hardware/software configuration (build
# failure or segmentation fault) that require additional settings to be solved, so it is
# disabled by default.
if [ "${GPU:-no}" = "yes" ]; then
# by default the GPU package is enabled using bundled OpenCL ICD loader library/headers
# but users may prefer the local opencl installed in the system
opencl_loader="yes" ; [ "${STATIC_OCL:-no}" = "no" ] && opencl_loader="no"
gpu="-DPKG_GPU=yes -DGPU_API=opencl -DUSE_STATIC_OPENCL_LOADER=${opencl_loader} "
else
opencl_loader=""
gpu=""
fi
# Following conditions enable by default all packages that require dependencies if these
# are installed in the system
latboltz=""
openmp=""
scafacos=""
if [ "$MP" = "openmpi" ]; then
latboltz="" ; [ "${LATBOLTZ:-yes}" = "yes" ] && latboltz="-DPKG_LATBOLTZ=yes "
openmp="" ; [ "${OPENMP:-yes}" = "yes" ] && openmp="-DPKG_OPENMP=yes "
scafacos="" ; [ "${SCAFACOS:-yes}" = "yes" ] && scafacos="-DPKG_SCAFACOS=yes "
fi
if [ "$MP" = "mpich" ]; then
latboltz="" ; [ "${LATBOLTZ:-yes}" = "yes" ] && latboltz="-DPKG_LATBOLTZ=yes "
scafacos="" ; [ "${SCAFACOS:-yes}" = "yes" ] && scafacos="-DPKG_SCAFACOS=yes "
fi
if pkg-config --exists plumed; then
plumed="" ; [ "${PLUMED:-yes}" = "yes" ] && plumed="-DPKG_PLUMED=yes -DDOWNLOAD_PLUMED=no "
else
plumed=""
fi
netcdf=""
if pkg-config --exists netcdf; then
netcdf="" ; [ "${NETCDF:-yes}" = "yes" ] && netcdf="-DPKG_NETCDF=yes "
fi
voronoi=""
if [ -f /usr/bin/voro++ ]; then
voronoi="" ; [ "${VORONOI:-yes}" = "yes" ] && voronoi="-DPKG_VORONOI=yes "
fi
h5md=""
if [ -f /usr/bin/h5cc ]; then
h5md="" ; [ "${H5MD:-yes}" = "yes" ] && h5md="-DPKG_H5MD=yes "
fi
# This shouldn't need in 32-bit architectures, however it significantly extends the build times
# and absorbs many resources. Openmpi is strictly required.
kokkos=""
if [ "$ARCH" = "x86_64" ]; then
if [ "${KOKKOS:-yes}" = "yes" ] ; then
kokkos="-DPKG_KOKKOS=yes -DKokkos_ARCH_NATIVE=yes -DKokkos_ENABLE_OPENMP=yes "
fi
if [ "$MP" != "openmpi" ]; then
kokkos=""
fi
fi
# All required cmake flags related to packages are included in a single global variable
packages=$amoeba$asphere$atc$awpmd$bocs$body$bpm$brownian$cgdna$cgspica$class2$colloid\
$colvars$compress$coreshell$dielectric$diffraction$dipole$dpdbasic$dpdmeso$dpdreact\
$dpdsmooth$drude$eff$electrode$extracompute$extradump$extrafix$extramolecule$extrapair\
$fep$gpu$granular$h5md$intel$interlayer$kokkos$kspace$latboltz$lepton$machdyn$manifold\
$manybody$mc$mdi$meam$mesont$mgpt$misc$mlhdnnp$mliap$mlpace$mlpod$mlrann$mlsnap$mofff\
$molecule$netcdf$openmp$opt$orient$peri$phonon$plugin$plumed$poems$ptm$qeq$qtb$reaction\
$reaxff$replica$rigid$scafacos$shock$smtbq$sph$spin$srd$tally$uef$voronoi$yaff
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}
if [ "$ARCH" = "i586" ]; then
SLKCFLAGS="-O2 -march=i586 -mtune=i686"
LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
SLKCFLAGS="-O2 -march=i686 -mtune=i686"
LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
SLKCFLAGS="-O2 -fPIC"
LIBDIRSUFFIX="64"
else
SLKCFLAGS="-O2"
LIBDIRSUFFIX=""
fi
set -e
rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf ${SRCNAM}_${SRCVERSION}
tar xvf $CWD/${SRCNAM}_${SRCVERSION}.tar.gz
cd ${SRCNAM}_${SRCVERSION}
echo -e "\nFLAGS FOR PACKAGES ENABLED:\n "$packages"\n"
echo -e "FLAGS FOR PYTHON:\n "$python
echo -e "\nFLAGS FOR MPI:\n "$mpi
if [ "$mesont" != "" ]; then
cp -a $CWD/C_10_10.mesocnt ./potentials
if [ "$molecule" = "" ]; then
echo -e "\n\033[33mYou have enabled the package MESONT. Since this package requires also "
echo -e "the package MOLECULE, the build of MOLECULE will be automatically enabled\033[0m\n"
packages=$packages" -DPKG_MOLECULE=yes "
fi
fi
if [ "$MP" = "" ]; then
echo -e "\n\033[33m******************** WARNING ********************\n"
echo " no API supporting MPI (mpich or openmpi) are "
echo " installed on your system. This does not affect "
echo " the build and installation of LAMMPS, but some "
echo " packages cannot be enabled and other may work "
echo " not optimally. "
echo -e "\n*************************************************\n\033[0m"
fi
# Prepare directories to move the extrafiles needed to build some packages
mkdir -p cmake/build
if [ "$opencl_loader" = "yes" ]; then
mkdir -p cmake/build/_deps
cp -a $CWD/opencl-loader-2022.01.04.tar.gz cmake/build/_deps
fi
if [ "$mdi" != "" ]; then
mkdir -p cmake/build/mdi_build_ext/src/
cp -a $CWD/MDI_Library-1.4.16.tar.gz cmake/build/mdi_build_ext/src/v1.4.16.tar.gz
fi
if [ "$mlhdnnp" != "" ]; then
mkdir -p cmake/build/n2p2_build-prefix/src/
cp -a $CWD/n2p2-2.2.0.tar.gz cmake/build/n2p2_build-prefix/src/v2.2.0.tar.gz
fi
if [ "$mlpace" != "" ]; then
cp -a $CWD/lammps-user-pace-v.2023.01.3.fix.tar.gz cmake/build/libpace.tar.gz
fi
if [ "$scafacos" != "" ]; then
mkdir -p cmake/build/scafacos_build-prefix/src
cp -a $CWD/scafacos-1.0.1.tar.gz cmake/build/scafacos_build-prefix/src
fi
chown -R root:root .
find -L . \
\( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
-o -perm 511 \) -exec chmod 755 {} \; -o \
\( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
-o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
# The Source has not a CMakeLists.txt file in the root directory we
# need to change in the cmake directory
cd cmake
cd build
cmake \
-DCMAKE_C_FLAGS:STRING="$SLKCFLAGS" \
-DCMAKE_CXX_FLAGS:STRING="$SLKCFLAGS" \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=Release \
$mpi \
$python \
$packages \
..
make
make install DESTDIR=$PKG
cd ..
rm -f $PKG/{,usr/}lib${LIBDIRSUFFIX}/*.la
find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \
| cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
#Since the build installs man in /usr/share we move the directory in /usr
mv -v $PKG/usr/share/man $PKG/usr
find $PKG/usr/man -type f -exec gzip -9 {} \;
for i in $( find $PKG/usr/man -type l ) ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done
#Since the build installs etc as subfolder of /usr (?), we move it in the root directory
mv -v $PKG/usr/etc $PKG
cd $TMP/${SRCNAM}_${SRCVERSION}
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a LICENSE README $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE