1 # Copyright 1999-2024 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 CMAKE_MAKEFILE_GENERATOR="ninja"
8 PYTHON_COMPAT=( python3_{10..12} )
11 DISTUTILS_USE_PEP517=no
12 DISTUTILS_SINGLE_IMPL=1
14 inherit bash-completion-r1 cmake cuda distutils-r1 flag-o-matic readme.gentoo-r1 toolchain-funcs xdg-utils
16 if [[ ${PV} = *9999* ]]; then
18 https://gitlab.com/gromacs/gromacs.git
19 https://github.com/gromacs/gromacs.git
21 [[ ${PV} = 9999 ]] && EGIT_BRANCH="master" || EGIT_BRANCH="release-${PV:0:4}"
25 https://ftp.gromacs.org/gromacs/${PN}-${PV/_/-}.tar.gz
26 doc? ( https://ftp.gromacs.org/manual/manual-${PV/_/-}.pdf )
27 test? ( https://ftp.gromacs.org/regressiontests/regressiontests-${PV/_/-}.tar.gz )"
28 # since 2022 arm support was dropped (but not arm64)
29 KEYWORDS="amd64 -arm arm64 ~x86 ~amd64-linux ~x86-linux ~x64-macos"
32 ACCE_IUSE="cpu_flags_x86_sse2 cpu_flags_x86_sse4_1 cpu_flags_x86_fma4 cpu_flags_x86_avx cpu_flags_x86_avx2 cpu_flags_x86_avx512f cpu_flags_arm_neon"
34 DESCRIPTION="The ultimate molecular dynamics simulation package"
35 HOMEPAGE="https://www.gromacs.org/"
37 # see COPYING for details
38 # https://repo.or.cz/w/gromacs.git/blob/HEAD:/COPYING
39 # base, vmd plugins, fftpack from numpy, blas/lapck from netlib, memtestG80 library, mpi_thread lib
40 LICENSE="LGPL-2.1 UoI-NCSA !mkl? ( !fftw? ( BSD ) !blas? ( BSD ) !lapack? ( BSD ) ) cuda? ( LGPL-3 ) threads? ( BSD )"
42 IUSE="blas clang clang-cuda cuda +custom-cflags +doc build-manual double-precision +fftw +gmxapi +gmxapi-legacy +hwloc lapack mkl mpi +offensive opencl openmp +python +single-precision test +threads +tng ${ACCE_IUSE}"
45 blas? ( virtual/blas )
46 cuda? ( >=dev-util/nvidia-cuda-toolkit-11:=[profiler] )
47 opencl? ( virtual/opencl )
50 llvm-core/clang-runtime[openmp]
52 fftw? ( sci-libs/fftw:3.0= )
53 hwloc? ( sys-apps/hwloc:= )
54 lapack? ( virtual/lapack )
56 mpi? ( virtual/mpi[cxx] )
58 >=dev-cpp/muParser-2.3:=
63 clang? ( >=llvm-core/clang-6:* )
66 $(python_gen_cond_dep '
67 dev-python/sphinx[${PYTHON_USEDEP}]
68 dev-python/sphinx-copybutton[${PYTHON_USEDEP}]
69 dev-python/sphinx-inline-tabs[${PYTHON_USEDEP}]
70 dev-python/sphinx-argparse[${PYTHON_USEDEP}]
71 dev-python/sphinxcontrib-autoprogram[${PYTHON_USEDEP}]
75 dev-texlive/texlive-latex
76 dev-texlive/texlive-latexextra
82 || ( single-precision double-precision )
83 doc? ( !build-manual )
84 cuda? ( single-precision )
85 opencl? ( single-precision )
87 clang-cuda? ( clang cuda )
88 mkl? ( !blas !fftw !lapack )
89 ${PYTHON_REQUIRED_USE}"
91 DOCS=( AUTHORS README )
93 RESTRICT="!test? ( test )"
95 if [[ ${PV} != *9999 ]]; then
96 S="${WORKDIR}/${PN}-${PV/_/-}"
100 [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
104 [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
105 python-single-r1_pkg_setup
109 if [[ ${PV} != *9999 ]]; then
114 EGIT_REPO_URI="https://gitlab.com/gromacs/gromacs-regressiontests.git" \
115 EGIT_BRANCH="${EGIT_BRANCH}" \
116 EGIT_CHECKOUT_DIR="${WORKDIR}/regressiontests"\
124 # -on apple: there is framework support
126 xdg_environment_reset #591952
128 # we can use clang as default
129 if use clang && ! tc-is-clang ; then
130 export CC=${CHOST}-clang
131 export CXX=${CHOST}-clang++
135 # clang-cuda need to filter mfpmath
136 if use clang-cuda ; then
143 use cuda && cuda_src_prepare
146 use single-precision && GMX_DIRS+=" float"
147 use double-precision && GMX_DIRS+=" double"
150 for x in ${GMX_DIRS}; do
151 mkdir -p "${WORKDIR}/${P}_${x}" || die
152 cp -al "${WORKDIR}/regressiontests"* "${WORKDIR}/${P}_${x}/tests" || die
156 DOC_CONTENTS="Gromacs can use sci-chemistry/vmd to read additional file formats"
157 if use build-manual; then
158 # try to create policy for imagemagik
159 mkdir -p "${HOME}"/.config/ImageMagick
160 cat >> "${HOME}"/.config/ImageMagick/policy.xml <<- EOF
161 <?xml version="1.0" encoding="UTF-8"?>
162 <!DOCTYPE policymap [
163 <!ELEMENT policymap (policy)+>
164 !ATTLIST policymap xmlns CDATA #FIXED ''>
165 <!ELEMENT policy EMPTY>
166 <!ATTLIST policy xmlns CDATA #FIXED '' domain NMTOKEN #REQUIRED
167 name NMTOKEN #IMPLIED pattern CDATA #IMPLIED rights NMTOKEN #IMPLIED
168 stealth NMTOKEN #IMPLIED value CDATA #IMPLIED>
171 <policy domain="coder" rights="read | write" pattern="PS" />
172 <policy domain="coder" rights="read | write" pattern="PS2" />
173 <policy domain="coder" rights="read | write" pattern="PS3" />
174 <policy domain="coder" rights="read | write" pattern="EPS" />
175 <policy domain="coder" rights="read | write" pattern="PDF" />
176 <policy domain="coder" rights="read | write" pattern="XPS" />
183 local mycmakeargs_pre=( ) extra fft_opts=( )
186 if use custom-cflags; then
187 #go from slowest to fastest acceleration
189 if (use amd64 || use x86); then
190 use cpu_flags_x86_sse2 && acce="SSE2"
191 use cpu_flags_x86_sse4_1 && acce="SSE4.1"
192 use cpu_flags_x86_fma4 && acce="AVX_128_FMA"
193 use cpu_flags_x86_avx && acce="AVX_256"
194 use cpu_flags_x86_avx2 && acce="AVX2_256"
195 use cpu_flags_x86_avx512f && acce="AVX_512"
197 use cpu_flags_arm_neon && acce="ARM_NEON"
198 elif (use arm64); then
199 use cpu_flags_arm_neon && acce="ARM_NEON_ASIMD"
205 #to create man pages, build tree binaries are executed (bug #398437)
206 [[ ${CHOST} = *-darwin* ]] && \
207 extra+=" -DCMAKE_BUILD_WITH_INSTALL_RPATH=OFF"
210 fft_opts=( -DGMX_FFT_LIBRARY=fftw3 )
212 local bits=$(get_libdir)
213 fft_opts=( -DGMX_FFT_LIBRARY=mkl
214 -DMKL_INCLUDE_DIR="$(echo /opt/intel/*/mkl/include)"
215 -DMKL_LIBRARIES="$(echo /opt/intel/*/mkl/lib/*${bits/lib}/libmkl_rt.so)"
218 fft_opts=( -DGMX_FFT_LIBRARY=fftpack )
224 -DGMX_USE_LMFIT=EXTERNAL
225 -DGMX_USE_MUPARSER=EXTERNAL
226 -DGMX_EXTERNAL_BLAS=$(usex blas)
227 -DGMX_EXTERNAL_LAPACK=$(usex lapack)
228 -DGMX_OPENMP=$(usex openmp)
229 -DGMX_COOL_QUOTES=$(usex offensive)
230 -DGMX_USE_TNG=$(usex tng)
231 -DGMX_BUILD_MANUAL=$(usex build-manual)
232 -DGMX_HWLOC=$(usex hwloc)
233 -DGMX_DEFAULT_SUFFIX=off
235 -DGMX_VMD_PLUGIN_PATH="${EPREFIX}/usr/$(get_libdir)/vmd/plugins/*/molfile/"
236 -DBUILD_TESTING=$(usex test)
237 -DGMX_BUILD_UNITTESTS=$(usex test)
238 -DPYTHON_EXECUTABLE="${EPREFIX}/usr/bin/${EPYTHON}"
242 for x in ${GMX_DIRS}; do
243 einfo "Configuring for ${x} precision"
245 #if we build single and double - double is suffixed
246 use double-precision && use single-precision && \
247 [[ ${x} = "double" ]] && suffix="_d"
249 [[ ${x} = "double" ]] && p="-DGMX_DOUBLE=ON" || p="-DGMX_DOUBLE=OFF"
250 local gpu=( "-DGMX_GPU=OFF" )
251 [[ ${x} = "float" ]] && use cuda && gpu=( "-DGMX_GPU=CUDA" )
252 [[ ${x} = "float" ]] && use clang-cuda && gpu=( "-DGMX_GPU=CUDA" "-DGMX_CLANG_CUDA=ON" )
253 use opencl && gpu=( "-DGMX_GPU=OPENCL" )
255 ${mycmakeargs_pre[@]} ${p}
256 -DGMX_MPI=$(usex mpi)
257 -DGMX_THREAD_MPI=$(usex threads)
258 -DGMXAPI=$(usex gmxapi)
259 -DGMX_INSTALL_LEGACY_API=$(usex gmxapi-legacy)
261 "$(use test && echo -DREGRESSIONTEST_PATH="${WORKDIR}/${P}_${x}/tests")"
262 -DGMX_BINARY_SUFFIX="${suffix}"
263 -DGMX_LIBS_SUFFIX="${suffix}"
264 -DGMX_PYTHON_PACKAGE=$(usex python)
266 BUILD_DIR="${WORKDIR}/${P}_${x}" cmake_src_configure
267 [[ ${CHOST} != *-darwin* ]] || \
268 sed -i '/SET(CMAKE_INSTALL_NAME_DIR/s/^/#/' "${WORKDIR}/${P}_${x}/gentoo_rules.cmake" || die
273 for x in ${GMX_DIRS}; do
274 einfo "Compiling for ${x} precision"
275 BUILD_DIR="${WORKDIR}/${P}_${x}"\
278 BUILD_DIR="${WORKDIR}/${P}_${x}"\
279 cmake_src_compile python_packaging/all
280 BUILD_DIR="${WORKDIR}/${P}" \
281 distutils-r1_src_compile
283 # not 100% necessary for rel ebuilds as available from website
284 if use build-manual; then
285 BUILD_DIR="${WORKDIR}/${P}_${x}"\
286 cmake_src_compile manual
292 for x in ${GMX_DIRS}; do
293 BUILD_DIR="${WORKDIR}/${P}_${x}"\
294 cmake_src_compile check
299 for x in ${GMX_DIRS}; do
300 BUILD_DIR="${WORKDIR}/${P}_${x}" \
303 BUILD_DIR="${WORKDIR}/${P}_${x}" \
304 cmake_src_install python_packaging/install
306 if use build-manual; then
307 newdoc "${WORKDIR}/${P}_${x}"/docs/manual/gromacs.pdf "${PN}-manual-${PV}.pdf"
311 if [[ ${PV} != *9999* ]]; then
312 newdoc "${DISTDIR}/manual-${PV/_/-}.pdf" "${PN}-manual-${PV}.pdf"
318 insinto /usr/include/tng
319 doins src/external/tng_io/include/tng/*h
321 # drop unneeded stuff
322 rm "${ED}"/usr/bin/GMXRC* || die
323 for x in "${ED}"/usr/bin/gmx-completion-*.bash ; do
324 local n=${x##*/gmx-completion-}
326 cat "${ED}"/usr/bin/gmx-completion.bash "$x" > "${T}/${n}" || die
327 newbashcomp "${T}"/"${n}" "${n}"
329 rm "${ED}"/usr/bin/gmx-completion*.bash || die
330 readme.gentoo_create_doc
335 einfo "Please read and cite gromacs related papers from list:"
336 einfo "https://www.gromacs.org/articles.html"
338 readme.gentoo_print_elog