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 ~riscv -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 PATCHES=( "${FILESDIR}/${PN}-gcc-15.patch" )
97 if [[ ${PV} != *9999 ]]; then
98 S="${WORKDIR}/${PN}-${PV/_/-}"
102 [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
106 [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
107 python-single-r1_pkg_setup
111 if [[ ${PV} != *9999 ]]; then
116 EGIT_REPO_URI="https://gitlab.com/gromacs/gromacs-regressiontests.git" \
117 EGIT_BRANCH="${EGIT_BRANCH}" \
118 EGIT_CHECKOUT_DIR="${WORKDIR}/regressiontests"\
126 # -on apple: there is framework support
128 xdg_environment_reset #591952
130 # we can use clang as default
131 if use clang && ! tc-is-clang ; then
132 export CC=${CHOST}-clang
133 export CXX=${CHOST}-clang++
137 # clang-cuda need to filter mfpmath
138 if use clang-cuda ; then
145 use cuda && cuda_src_prepare
148 use single-precision && GMX_DIRS+=" float"
149 use double-precision && GMX_DIRS+=" double"
152 for x in ${GMX_DIRS}; do
153 mkdir -p "${WORKDIR}/${P}_${x}" || die
154 cp -al "${WORKDIR}/regressiontests"* "${WORKDIR}/${P}_${x}/tests" || die
158 DOC_CONTENTS="Gromacs can use sci-chemistry/vmd to read additional file formats"
159 if use build-manual; then
160 # try to create policy for imagemagik
161 mkdir -p "${HOME}"/.config/ImageMagick
162 cat >> "${HOME}"/.config/ImageMagick/policy.xml <<- EOF
163 <?xml version="1.0" encoding="UTF-8"?>
164 <!DOCTYPE policymap [
165 <!ELEMENT policymap (policy)+>
166 !ATTLIST policymap xmlns CDATA #FIXED ''>
167 <!ELEMENT policy EMPTY>
168 <!ATTLIST policy xmlns CDATA #FIXED '' domain NMTOKEN #REQUIRED
169 name NMTOKEN #IMPLIED pattern CDATA #IMPLIED rights NMTOKEN #IMPLIED
170 stealth NMTOKEN #IMPLIED value CDATA #IMPLIED>
173 <policy domain="coder" rights="read | write" pattern="PS" />
174 <policy domain="coder" rights="read | write" pattern="PS2" />
175 <policy domain="coder" rights="read | write" pattern="PS3" />
176 <policy domain="coder" rights="read | write" pattern="EPS" />
177 <policy domain="coder" rights="read | write" pattern="PDF" />
178 <policy domain="coder" rights="read | write" pattern="XPS" />
185 local mycmakeargs_pre=( ) extra fft_opts=( )
188 if use custom-cflags; then
189 #go from slowest to fastest acceleration
191 if (use amd64 || use x86); then
192 use cpu_flags_x86_sse2 && acce="SSE2"
193 use cpu_flags_x86_sse4_1 && acce="SSE4.1"
194 use cpu_flags_x86_fma4 && acce="AVX_128_FMA"
195 use cpu_flags_x86_avx && acce="AVX_256"
196 use cpu_flags_x86_avx2 && acce="AVX2_256"
197 use cpu_flags_x86_avx512f && acce="AVX_512"
199 use cpu_flags_arm_neon && acce="ARM_NEON"
200 elif (use arm64); then
201 use cpu_flags_arm_neon && acce="ARM_NEON_ASIMD"
207 #to create man pages, build tree binaries are executed (bug #398437)
208 [[ ${CHOST} = *-darwin* ]] && \
209 extra+=" -DCMAKE_BUILD_WITH_INSTALL_RPATH=OFF"
212 fft_opts=( -DGMX_FFT_LIBRARY=fftw3 )
214 local bits=$(get_libdir)
215 fft_opts=( -DGMX_FFT_LIBRARY=mkl
216 -DMKL_INCLUDE_DIR="$(echo /opt/intel/*/mkl/include)"
217 -DMKL_LIBRARIES="$(echo /opt/intel/*/mkl/lib/*${bits/lib}/libmkl_rt.so)"
220 fft_opts=( -DGMX_FFT_LIBRARY=fftpack )
226 -DGMX_USE_LMFIT=EXTERNAL
227 -DGMX_USE_MUPARSER=EXTERNAL
228 -DGMX_EXTERNAL_BLAS=$(usex blas)
229 -DGMX_EXTERNAL_LAPACK=$(usex lapack)
230 -DGMX_OPENMP=$(usex openmp)
231 -DGMX_COOL_QUOTES=$(usex offensive)
232 -DGMX_USE_TNG=$(usex tng)
233 -DGMX_BUILD_MANUAL=$(usex build-manual)
234 -DGMX_HWLOC=$(usex hwloc)
235 -DGMX_DEFAULT_SUFFIX=off
237 -DGMX_VMD_PLUGIN_PATH="${EPREFIX}/usr/$(get_libdir)/vmd/plugins/*/molfile/"
238 -DBUILD_TESTING=$(usex test)
239 -DGMX_BUILD_UNITTESTS=$(usex test)
240 -DPYTHON_EXECUTABLE="${EPREFIX}/usr/bin/${EPYTHON}"
244 for x in ${GMX_DIRS}; do
245 einfo "Configuring for ${x} precision"
247 #if we build single and double - double is suffixed
248 use double-precision && use single-precision && \
249 [[ ${x} = "double" ]] && suffix="_d"
251 [[ ${x} = "double" ]] && p="-DGMX_DOUBLE=ON" || p="-DGMX_DOUBLE=OFF"
252 local gpu=( "-DGMX_GPU=OFF" )
253 [[ ${x} = "float" ]] && use cuda && gpu=( "-DGMX_GPU=CUDA" )
254 [[ ${x} = "float" ]] && use clang-cuda && gpu=( "-DGMX_GPU=CUDA" "-DGMX_CLANG_CUDA=ON" )
255 use opencl && gpu=( "-DGMX_GPU=OPENCL" )
257 ${mycmakeargs_pre[@]} ${p}
258 -DGMX_MPI=$(usex mpi)
259 -DGMX_THREAD_MPI=$(usex threads)
260 -DGMXAPI=$(usex gmxapi)
261 -DGMX_INSTALL_LEGACY_API=$(usex gmxapi-legacy)
263 "$(use test && echo -DREGRESSIONTEST_PATH="${WORKDIR}/${P}_${x}/tests")"
264 -DGMX_BINARY_SUFFIX="${suffix}"
265 -DGMX_LIBS_SUFFIX="${suffix}"
266 -DGMX_PYTHON_PACKAGE=$(usex python)
268 BUILD_DIR="${WORKDIR}/${P}_${x}" cmake_src_configure
269 [[ ${CHOST} != *-darwin* ]] || \
270 sed -i '/SET(CMAKE_INSTALL_NAME_DIR/s/^/#/' "${WORKDIR}/${P}_${x}/gentoo_rules.cmake" || die
275 for x in ${GMX_DIRS}; do
276 einfo "Compiling for ${x} precision"
277 BUILD_DIR="${WORKDIR}/${P}_${x}"\
280 BUILD_DIR="${WORKDIR}/${P}_${x}"\
281 cmake_src_compile python_packaging/all
282 BUILD_DIR="${WORKDIR}/${P}" \
283 distutils-r1_src_compile
285 # not 100% necessary for rel ebuilds as available from website
286 if use build-manual; then
287 BUILD_DIR="${WORKDIR}/${P}_${x}"\
288 cmake_src_compile manual
294 for x in ${GMX_DIRS}; do
295 BUILD_DIR="${WORKDIR}/${P}_${x}"\
296 cmake_src_compile check
301 for x in ${GMX_DIRS}; do
302 BUILD_DIR="${WORKDIR}/${P}_${x}" \
305 BUILD_DIR="${WORKDIR}/${P}_${x}" \
306 cmake_src_install python_packaging/install
308 if use build-manual; then
309 newdoc "${WORKDIR}/${P}_${x}"/docs/manual/gromacs.pdf "${PN}-manual-${PV}.pdf"
313 if [[ ${PV} != *9999* ]]; then
314 newdoc "${DISTDIR}/manual-${PV/_/-}.pdf" "${PN}-manual-${PV}.pdf"
320 insinto /usr/include/tng
321 doins src/external/tng_io/include/tng/*h
323 # drop unneeded stuff
324 rm "${ED}"/usr/bin/GMXRC* || die
325 for x in "${ED}"/usr/bin/gmx-completion-*.bash ; do
326 local n=${x##*/gmx-completion-}
328 cat "${ED}"/usr/bin/gmx-completion.bash "$x" > "${T}/${n}" || die
329 newbashcomp "${T}"/"${n}" "${n}"
331 rm "${ED}"/usr/bin/gmx-completion*.bash || die
332 readme.gentoo_create_doc
337 einfo "Please read and cite gromacs related papers from list:"
338 einfo "https://www.gromacs.org/articles.html"
340 readme.gentoo_print_elog