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 )"
106 if [[ ${PV} != *9999 ]]; then
107 S="${WORKDIR}/${PN}-${PV/_/-}"
111 [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
115 [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
116 python-single-r1_pkg_setup
120 if [[ ${PV} != *9999 ]]; then
125 EGIT_REPO_URI="https://gitlab.com/gromacs/gromacs-regressiontests.git" \
126 EGIT_BRANCH="${EGIT_BRANCH}" \
127 EGIT_CHECKOUT_DIR="${WORKDIR}/regressiontests"\
135 # -on apple: there is framework support
137 xdg_environment_reset #591952
139 # we can use clang as default
140 if use clang && ! tc-is-clang ; then
141 export CC=${CHOST}-clang
142 export CXX=${CHOST}-clang++
146 # clang-cuda need to filter mfpmath
147 if use clang-cuda ; then
154 use cuda && cuda_src_prepare
157 use single-precision && GMX_DIRS+=" float"
158 use double-precision && GMX_DIRS+=" double"
161 for x in ${GMX_DIRS}; do
162 mkdir -p "${WORKDIR}/${P}_${x}" || die
163 cp -al "${WORKDIR}/regressiontests"* "${WORKDIR}/${P}_${x}/tests" || die
167 DOC_CONTENTS="Gromacs can use sci-chemistry/vmd to read additional file formats"
168 if use build-manual; then
169 # try to create policy for imagemagik
170 mkdir -p "${HOME}"/.config/ImageMagick
171 cat >> "${HOME}"/.config/ImageMagick/policy.xml <<- EOF
172 <?xml version="1.0" encoding="UTF-8"?>
173 <!DOCTYPE policymap [
174 <!ELEMENT policymap (policy)+>
175 !ATTLIST policymap xmlns CDATA #FIXED ''>
176 <!ELEMENT policy EMPTY>
177 <!ATTLIST policy xmlns CDATA #FIXED '' domain NMTOKEN #REQUIRED
178 name NMTOKEN #IMPLIED pattern CDATA #IMPLIED rights NMTOKEN #IMPLIED
179 stealth NMTOKEN #IMPLIED value CDATA #IMPLIED>
182 <policy domain="coder" rights="read | write" pattern="PS" />
183 <policy domain="coder" rights="read | write" pattern="PS2" />
184 <policy domain="coder" rights="read | write" pattern="PS3" />
185 <policy domain="coder" rights="read | write" pattern="EPS" />
186 <policy domain="coder" rights="read | write" pattern="PDF" />
187 <policy domain="coder" rights="read | write" pattern="XPS" />
194 local mycmakeargs_pre=( ) extra fft_opts=( )
202 if use custom-cflags; then
203 #go from slowest to fastest acceleration
205 if (use amd64 || use x86); then
206 use cpu_flags_x86_sse2 && acce="SSE2"
207 use cpu_flags_x86_sse4_1 && acce="SSE4.1"
208 use cpu_flags_x86_fma4 && acce="AVX_128_FMA"
209 use cpu_flags_x86_avx && acce="AVX_256"
210 use cpu_flags_x86_avx2 && acce="AVX2_256"
211 use cpu_flags_x86_avx512f && acce="AVX_512"
213 use cpu_flags_arm_neon && acce="ARM_NEON"
214 elif (use arm64); then
215 use cpu_flags_arm_neon && acce="ARM_NEON_ASIMD"
221 #to create man pages, build tree binaries are executed (bug #398437)
222 [[ ${CHOST} = *-darwin* ]] && \
223 extra+=" -DCMAKE_BUILD_WITH_INSTALL_RPATH=OFF"
226 fft_opts=( -DGMX_FFT_LIBRARY=fftw3 )
228 local bits=$(get_libdir)
229 fft_opts=( -DGMX_FFT_LIBRARY=mkl
230 -DMKL_INCLUDE_DIR="$(echo /opt/intel/*/mkl/include)"
231 -DMKL_LIBRARIES="$(echo /opt/intel/*/mkl/lib/*${bits/lib}/libmkl_rt.so)"
234 fft_opts=( -DGMX_FFT_LIBRARY=fftpack )
240 -DGMX_USE_LMFIT=EXTERNAL
241 -DGMX_USE_MUPARSER=EXTERNAL
242 -DGMX_EXTERNAL_BLAS=$(usex blas)
243 -DGMX_EXTERNAL_LAPACK=$(usex lapack)
244 -DGMX_OPENMP=$(usex openmp)
245 -DGMX_COOL_QUOTES=$(usex offensive)
246 -DGMX_USE_TNG=$(usex tng)
247 -DGMX_BUILD_MANUAL=$(usex build-manual)
249 -DGMX_HWLOC=$(usex hwloc)
250 -DGMX_DEFAULT_SUFFIX=off
251 -DGMX_BUILD_HELP=$(usex doc)
254 -DGMX_VMD_PLUGIN_PATH="${EPREFIX}/usr/$(get_libdir)/vmd/plugins/*/molfile/"
255 -DBUILD_TESTING=$(usex test)
256 -DGMX_BUILD_UNITTESTS=$(usex test)
257 -DPYTHON_EXECUTABLE="${EPREFIX}/usr/bin/${EPYTHON}"
261 for x in ${GMX_DIRS}; do
262 einfo "Configuring for ${x} precision"
264 #if we build single and double - double is suffixed
265 use double-precision && use single-precision && \
266 [[ ${x} = "double" ]] && suffix="_d"
268 [[ ${x} = "double" ]] && p="-DGMX_DOUBLE=ON" || p="-DGMX_DOUBLE=OFF"
269 local gpu=( "-DGMX_GPU=OFF" )
270 [[ ${x} = "float" ]] && use cuda && gpu=( "-DGMX_GPU=CUDA" )
271 [[ ${x} = "float" ]] && use clang-cuda && gpu=( "-DGMX_GPU=CUDA" "-DGMX_CLANG_CUDA=ON" )
272 use opencl && gpu=( "-DGMX_GPU=OPENCL" )
274 ${mycmakeargs_pre[@]} ${p}
275 -DGMX_MPI=$(usex mpi)
276 -DGMX_THREAD_MPI=$(usex threads)
277 -DGMXAPI=$(usex gmxapi)
278 -DGMX_INSTALL_LEGACY_API=$(usex gmxapi-legacy)
280 "$(use test && echo -DREGRESSIONTEST_PATH="${WORKDIR}/${P}_${x}/tests")"
281 -DGMX_BINARY_SUFFIX="${suffix}"
282 -DGMX_LIBS_SUFFIX="${suffix}"
283 -DGMX_PYTHON_PACKAGE=$(usex python)
285 BUILD_DIR="${WORKDIR}/${P}_${x}" cmake_src_configure
286 [[ ${CHOST} != *-darwin* ]] || \
287 sed -i '/SET(CMAKE_INSTALL_NAME_DIR/s/^/#/' "${WORKDIR}/${P}_${x}/gentoo_rules.cmake" || die
292 for x in ${GMX_DIRS}; do
293 einfo "Compiling for ${x} precision"
294 BUILD_DIR="${WORKDIR}/${P}_${x}"\
296 BUILD_DIR="${WORKDIR}/${P}_${x}"\
297 cmake_src_compile man
299 BUILD_DIR="${WORKDIR}/${P}_${x}"\
300 cmake_src_compile python_packaging/all
301 BUILD_DIR="${WORKDIR}/${P}" \
302 distutils-r1_src_compile
304 # not 100% necessary for rel ebuilds as available from website
305 if use build-manual; then
306 BUILD_DIR="${WORKDIR}/${P}_${x}"\
307 cmake_src_compile manual
313 for x in ${GMX_DIRS}; do
314 BUILD_DIR="${WORKDIR}/${P}_${x}"\
315 cmake_src_compile check
320 for x in ${GMX_DIRS}; do
321 BUILD_DIR="${WORKDIR}/${P}_${x}" \
324 BUILD_DIR="${WORKDIR}/${P}_${x}" \
325 cmake_src_install python_packaging/install
327 if use build-manual; then
328 newdoc "${WORKDIR}/${P}_${x}"/docs/manual/gromacs.pdf "${PN}-manual-${PV}.pdf"
332 if [[ ${PV} != *9999* ]]; then
333 newdoc "${DISTDIR}/manual-${PV/_/-}.pdf" "${PN}-manual-${PV}.pdf"
339 insinto /usr/include/tng
340 doins src/external/tng_io/include/tng/*h
342 # drop unneeded stuff
343 rm "${ED}"/usr/bin/GMXRC* || die
344 for x in "${ED}"/usr/bin/gmx-completion-*.bash ; do
345 local n=${x##*/gmx-completion-}
347 cat "${ED}"/usr/bin/gmx-completion.bash "$x" > "${T}/${n}" || die
348 newbashcomp "${T}"/"${n}" "${n}"
350 rm "${ED}"/usr/bin/gmx-completion*.bash || die
351 readme.gentoo_create_doc
356 einfo "Please read and cite gromacs related papers from list:"
357 einfo "https://www.gromacs.org/articles.html"
359 readme.gentoo_print_elog