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="main" || 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 # since 2025 x86-32 support was dropped
30 KEYWORDS="~amd64 -arm ~arm64 ~riscv -x86 ~amd64-linux -x86-linux ~x64-macos"
33 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"
35 DESCRIPTION="The ultimate molecular dynamics simulation package"
36 HOMEPAGE="https://www.gromacs.org/"
38 # see COPYING for details
39 # https://repo.or.cz/w/gromacs.git/blob/HEAD:/COPYING
40 # base, vmd plugins, fftpack from numpy, blas/lapck from netlib, memtestG80 library, mpi_thread lib
41 LICENSE="LGPL-2.1 UoI-NCSA !mkl? ( !fftw? ( BSD ) !blas? ( BSD ) !lapack? ( BSD ) ) cuda? ( LGPL-3 ) threads? ( BSD )"
43 IUSE="blas clang clang-cuda cuda +custom-cflags +doc build-manual double-precision +fftw +gmxapi +gmxapi-legacy +hwloc lapack mkl mpi nnpot +offensive opencl openmp +python +single-precision test +threads +tng ${ACCE_IUSE}"
46 blas? ( virtual/blas )
47 cuda? ( >=dev-util/nvidia-cuda-toolkit-11:=[profiler] )
48 opencl? ( virtual/opencl )
51 llvm-core/clang-runtime[openmp]
53 fftw? ( sci-libs/fftw:3.0= )
54 hwloc? ( sys-apps/hwloc:= )
55 lapack? ( virtual/lapack )
57 mpi? ( virtual/mpi[cxx] )
58 nnpot? ( sci-libs/caffe2[cuda=,opencl=] )
60 >=dev-cpp/muParser-2.3:=
65 clang? ( >=llvm-core/clang-6:* )
67 $(python_gen_cond_dep '
68 dev-python/sphinx[${PYTHON_USEDEP}]
69 dev-python/sphinx-copybutton[${PYTHON_USEDEP}]
70 dev-python/sphinx-inline-tabs[${PYTHON_USEDEP}]
71 dev-python/sphinx-argparse[${PYTHON_USEDEP}]
72 dev-python/sphinxcontrib-autoprogram[${PYTHON_USEDEP}]
77 $(python_gen_cond_dep '
78 dev-python/sphinx[${PYTHON_USEDEP}]
79 dev-python/sphinx-copybutton[${PYTHON_USEDEP}]
80 dev-python/sphinx-inline-tabs[${PYTHON_USEDEP}]
81 dev-python/sphinx-argparse[${PYTHON_USEDEP}]
82 dev-python/sphinxcontrib-autoprogram[${PYTHON_USEDEP}]
86 dev-texlive/texlive-latex
87 dev-texlive/texlive-latexextra
93 || ( single-precision double-precision )
94 doc? ( !build-manual )
95 cuda? ( single-precision )
96 opencl? ( single-precision )
98 clang-cuda? ( clang cuda )
99 mkl? ( !blas !fftw !lapack )
100 ${PYTHON_REQUIRED_USE}"
102 DOCS=( AUTHORS README )
104 RESTRICT="!test? ( test )"
107 "${FILESDIR}/${PN}-gcc-15.patch"
108 "${FILESDIR}/${PN}-2025.0-beta-fix-man-build.patch"
111 if [[ ${PV} != *9999 ]]; then
112 S="${WORKDIR}/${PN}-${PV/_/-}"
116 [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
120 [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
121 python-single-r1_pkg_setup
125 if [[ ${PV} != *9999 ]]; then
130 EGIT_REPO_URI="https://gitlab.com/gromacs/gromacs-regressiontests.git" \
131 EGIT_BRANCH="${EGIT_BRANCH}" \
132 EGIT_CHECKOUT_DIR="${WORKDIR}/regressiontests"\
140 # -on apple: there is framework support
142 xdg_environment_reset #591952
144 # we can use clang as default
145 if use clang && ! tc-is-clang ; then
146 export CC=${CHOST}-clang
147 export CXX=${CHOST}-clang++
151 # clang-cuda need to filter mfpmath
152 if use clang-cuda ; then
159 use cuda && cuda_src_prepare
162 use single-precision && GMX_DIRS+=" float"
163 use double-precision && GMX_DIRS+=" double"
166 for x in ${GMX_DIRS}; do
167 mkdir -p "${WORKDIR}/${P}_${x}" || die
168 cp -al "${WORKDIR}/regressiontests"* "${WORKDIR}/${P}_${x}/tests" || die
172 DOC_CONTENTS="Gromacs can use sci-chemistry/vmd to read additional file formats"
173 if use build-manual; then
174 # try to create policy for imagemagik
175 mkdir -p "${HOME}"/.config/ImageMagick
176 cat >> "${HOME}"/.config/ImageMagick/policy.xml <<- EOF
177 <?xml version="1.0" encoding="UTF-8"?>
178 <!DOCTYPE policymap [
179 <!ELEMENT policymap (policy)+>
180 !ATTLIST policymap xmlns CDATA #FIXED ''>
181 <!ELEMENT policy EMPTY>
182 <!ATTLIST policy xmlns CDATA #FIXED '' domain NMTOKEN #REQUIRED
183 name NMTOKEN #IMPLIED pattern CDATA #IMPLIED rights NMTOKEN #IMPLIED
184 stealth NMTOKEN #IMPLIED value CDATA #IMPLIED>
187 <policy domain="coder" rights="read | write" pattern="PS" />
188 <policy domain="coder" rights="read | write" pattern="PS2" />
189 <policy domain="coder" rights="read | write" pattern="PS3" />
190 <policy domain="coder" rights="read | write" pattern="EPS" />
191 <policy domain="coder" rights="read | write" pattern="PDF" />
192 <policy domain="coder" rights="read | write" pattern="XPS" />
199 local mycmakeargs_pre=( ) extra fft_opts=( )
207 if use custom-cflags; then
208 #go from slowest to fastest acceleration
210 if (use amd64 || use x86); then
211 use cpu_flags_x86_sse2 && acce="SSE2"
212 use cpu_flags_x86_sse4_1 && acce="SSE4.1"
213 use cpu_flags_x86_fma4 && acce="AVX_128_FMA"
214 use cpu_flags_x86_avx && acce="AVX_256"
215 use cpu_flags_x86_avx2 && acce="AVX2_256"
216 use cpu_flags_x86_avx512f && acce="AVX_512"
218 use cpu_flags_arm_neon && acce="ARM_NEON"
219 elif (use arm64); then
220 use cpu_flags_arm_neon && acce="ARM_NEON_ASIMD"
226 #to create man pages, build tree binaries are executed (bug #398437)
227 [[ ${CHOST} = *-darwin* ]] && \
228 extra+=" -DCMAKE_BUILD_WITH_INSTALL_RPATH=OFF"
231 fft_opts=( -DGMX_FFT_LIBRARY=fftw3 )
233 local bits=$(get_libdir)
234 fft_opts=( -DGMX_FFT_LIBRARY=mkl
235 -DMKL_INCLUDE_DIR="$(echo /opt/intel/*/mkl/include)"
236 -DMKL_LIBRARIES="$(echo /opt/intel/*/mkl/lib/*${bits/lib}/libmkl_rt.so)"
239 fft_opts=( -DGMX_FFT_LIBRARY=fftpack )
245 -DGMX_USE_LMFIT=EXTERNAL
246 -DGMX_USE_MUPARSER=EXTERNAL
247 -DGMX_EXTERNAL_BLAS=$(usex blas)
248 -DGMX_EXTERNAL_LAPACK=$(usex lapack)
249 -DGMX_OPENMP=$(usex openmp)
250 -DGMX_COOL_QUOTES=$(usex offensive)
251 -DGMX_USE_TNG=$(usex tng)
252 -DGMX_BUILD_MANUAL=$(usex build-manual)
254 -DGMX_HWLOC=$(usex hwloc)
255 -DGMX_DEFAULT_SUFFIX=off
256 -DGMX_BUILD_HELP=$(usex doc)
259 -DGMX_VMD_PLUGIN_PATH="${EPREFIX}/usr/$(get_libdir)/vmd/plugins/*/molfile/"
260 -DBUILD_TESTING=$(usex test)
261 -DGMX_BUILD_UNITTESTS=$(usex test)
262 -DPYTHON_EXECUTABLE="${EPREFIX}/usr/bin/${EPYTHON}"
266 for x in ${GMX_DIRS}; do
267 einfo "Configuring for ${x} precision"
269 #if we build single and double - double is suffixed
270 use double-precision && use single-precision && \
271 [[ ${x} = "double" ]] && suffix="_d"
273 [[ ${x} = "double" ]] && p="-DGMX_DOUBLE=ON" || p="-DGMX_DOUBLE=OFF"
274 local gpu=( "-DGMX_GPU=OFF" )
275 [[ ${x} = "float" ]] && use cuda && gpu=( "-DGMX_GPU=CUDA" )
276 [[ ${x} = "float" ]] && use clang-cuda && gpu=( "-DGMX_GPU=CUDA" "-DGMX_CLANG_CUDA=ON" )
277 use opencl && gpu=( "-DGMX_GPU=OPENCL" )
279 ${mycmakeargs_pre[@]} ${p}
280 -DGMX_MPI=$(usex mpi)
281 -DGMX_THREAD_MPI=$(usex threads)
282 -DGMXAPI=$(usex gmxapi)
283 -DGMX_INSTALL_LEGACY_API=$(usex gmxapi-legacy)
285 "$(use test && echo -DREGRESSIONTEST_PATH="${WORKDIR}/${P}_${x}/tests")"
286 -DGMX_BINARY_SUFFIX="${suffix}"
287 -DGMX_LIBS_SUFFIX="${suffix}"
288 -DGMX_PYTHON_PACKAGE=$(usex python)
290 BUILD_DIR="${WORKDIR}/${P}_${x}" cmake_src_configure
291 [[ ${CHOST} != *-darwin* ]] || \
292 sed -i '/SET(CMAKE_INSTALL_NAME_DIR/s/^/#/' "${WORKDIR}/${P}_${x}/gentoo_rules.cmake" || die
297 for x in ${GMX_DIRS}; do
298 einfo "Compiling for ${x} precision"
299 BUILD_DIR="${WORKDIR}/${P}_${x}"\
301 BUILD_DIR="${WORKDIR}/${P}_${x}"\
302 cmake_src_compile man
304 BUILD_DIR="${WORKDIR}/${P}_${x}"\
305 cmake_src_compile python_packaging/all
306 BUILD_DIR="${WORKDIR}/${P}" \
307 distutils-r1_src_compile
309 # not 100% necessary for rel ebuilds as available from website
310 if use build-manual; then
311 BUILD_DIR="${WORKDIR}/${P}_${x}"\
312 cmake_src_compile manual
318 for x in ${GMX_DIRS}; do
319 BUILD_DIR="${WORKDIR}/${P}_${x}"\
320 cmake_src_compile check
325 for x in ${GMX_DIRS}; do
326 BUILD_DIR="${WORKDIR}/${P}_${x}" \
329 BUILD_DIR="${WORKDIR}/${P}_${x}" \
330 cmake_src_install python_packaging/install
332 if use build-manual; then
333 newdoc "${WORKDIR}/${P}_${x}"/docs/manual/gromacs.pdf "${PN}-manual-${PV}.pdf"
337 if [[ ${PV} != *9999* ]]; then
338 newdoc "${DISTDIR}/manual-${PV/_/-}.pdf" "${PN}-manual-${PV}.pdf"
344 insinto /usr/include/tng
345 doins src/external/tng_io/include/tng/*h
347 # drop unneeded stuff
348 rm "${ED}"/usr/bin/GMXRC* || die
349 for x in "${ED}"/usr/bin/gmx-completion-*.bash ; do
350 local n=${x##*/gmx-completion-}
352 cat "${ED}"/usr/bin/gmx-completion.bash "$x" > "${T}/${n}" || die
353 newbashcomp "${T}"/"${n}" "${n}"
355 rm "${ED}"/usr/bin/gmx-completion*.bash || die
356 readme.gentoo_create_doc
361 einfo "Please read and cite gromacs related papers from list:"
362 einfo "https://www.gromacs.org/articles.html"
364 readme.gentoo_print_elog