dev-python/agate: Bump to 1.13.0
[gentoo/gentoo.git] / sci-chemistry / gromacs / gromacs-2023.5.ebuild
blob83ceb0fceb6566a6003f663e215e09f570284c8e
1 # Copyright 1999-2024 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 EAPI=8
6 CMAKE_MAKEFILE_GENERATOR="ninja"
8 PYTHON_COMPAT=( python3_{10..12} )
10 DISTUTILS_OPTIONAL=1
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
17         EGIT_REPO_URI="
18                 https://gitlab.com/gromacs/gromacs.git
19                 https://github.com/gromacs/gromacs.git
20                 "
21         [[ ${PV} = 9999 ]] && EGIT_BRANCH="master" || EGIT_BRANCH="release-${PV:0:4}"
22         inherit git-r3
23 else
24         SRC_URI="
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 )"
41 SLOT="0/${PV}"
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}"
44 CDEPEND="
45         blas? ( virtual/blas )
46         cuda? ( >=dev-util/nvidia-cuda-toolkit-11:=[profiler] )
47         opencl? ( virtual/opencl )
48         openmp? (
49                 sys-devel/gcc[openmp]
50                 llvm-core/clang-runtime[openmp]
51         )
52         fftw? ( sci-libs/fftw:3.0= )
53         hwloc? ( sys-apps/hwloc:= )
54         lapack? ( virtual/lapack )
55         mkl? ( sci-libs/mkl )
56         mpi? ( virtual/mpi[cxx] )
57         sci-libs/lmfit:=
58         >=dev-cpp/muParser-2.3:=
59         ${PYTHON_DEPS}
60         "
61 BDEPEND="${CDEPEND}
62         virtual/pkgconfig
63         clang? ( >=llvm-core/clang-6:* )
64         build-manual? (
65                 app-text/doxygen
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}]
72                 ')
73                 media-gfx/mscgen
74                 media-gfx/graphviz
75                 dev-texlive/texlive-latex
76                 dev-texlive/texlive-latexextra
77                 media-gfx/imagemagick
78         )"
79 RDEPEND="${CDEPEND}"
81 REQUIRED_USE="
82         || ( single-precision double-precision )
83         doc? ( !build-manual )
84         cuda? ( single-precision )
85         opencl? ( single-precision )
86         cuda? ( !opencl )
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/_/-}"
99 pkg_pretend() {
100         [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
103 pkg_setup() {
104         [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
105         python-single-r1_pkg_setup
108 src_unpack() {
109         if [[ ${PV} != *9999 ]]; then
110                 default
111         else
112                 git-r3_src_unpack
113                 if use test; then
114                         EGIT_REPO_URI="https://gitlab.com/gromacs/gromacs-regressiontests.git" \
115                         EGIT_BRANCH="${EGIT_BRANCH}" \
116                         EGIT_CHECKOUT_DIR="${WORKDIR}/regressiontests"\
117                                 git-r3_src_unpack
118                 fi
119         fi
122 src_prepare() {
123         #notes/todos
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++
132         else
133                 tc-export CXX CC
134         fi
135         # clang-cuda need to filter mfpmath
136         if use clang-cuda ; then
137                 filter-mfpmath sse
138                 filter-mfpmath i386
139         fi
141         cmake_src_prepare
143         use cuda && cuda_src_prepare
145         GMX_DIRS=""
146         use single-precision && GMX_DIRS+=" float"
147         use double-precision && GMX_DIRS+=" double"
149         if use test; then
150                 for x in ${GMX_DIRS}; do
151                         mkdir -p "${WORKDIR}/${P}_${x}" || die
152                         cp -al "${WORKDIR}/regressiontests"* "${WORKDIR}/${P}_${x}/tests" || die
153                 done
154         fi
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>
169                 ]>
170                 <policymap>
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" />
177                 </policymap>
178                 EOF
179         fi
182 src_configure() {
183         local mycmakeargs_pre=( ) extra fft_opts=( )
184         local acce="AUTO"
186         if use custom-cflags; then
187                 #go from slowest to fastest acceleration
188                 acce="None"
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"
196                 elif (use arm); then
197                         use cpu_flags_arm_neon && acce="ARM_NEON"
198                 elif (use arm64); then
199                         use cpu_flags_arm_neon && acce="ARM_NEON_ASIMD"
200                 fi
201         else
202                 strip-flags
203         fi
205         #to create man pages, build tree binaries are executed (bug #398437)
206         [[ ${CHOST} = *-darwin* ]] && \
207                 extra+=" -DCMAKE_BUILD_WITH_INSTALL_RPATH=OFF"
209         if use fftw; then
210                 fft_opts=( -DGMX_FFT_LIBRARY=fftw3 )
211         elif use mkl; then
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)"
216                 )
217         else
218                 fft_opts=( -DGMX_FFT_LIBRARY=fftpack )
219         fi
221         mycmakeargs_pre+=(
222                 "${fft_opts[@]}"
223                 "${lmfit_opts[@]}"
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
234                 -DGMX_SIMD="$acce"
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}"
239                 ${extra}
240         )
242         for x in ${GMX_DIRS}; do
243                 einfo "Configuring for ${x} precision"
244                 local suffix=""
245                 #if we build single and double - double is suffixed
246                 use double-precision && use single-precision && \
247                         [[ ${x} = "double" ]] && suffix="_d"
248                 local p
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" )
254                 local mycmakeargs=(
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)
260                         "${gpu[@]}"
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)
265                 )
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
269         done
272 src_compile() {
273         for x in ${GMX_DIRS}; do
274                 einfo "Compiling for ${x} precision"
275                 BUILD_DIR="${WORKDIR}/${P}_${x}"\
276                         cmake_src_compile
277                 if use python; then
278                         BUILD_DIR="${WORKDIR}/${P}_${x}"\
279                                 cmake_src_compile       python_packaging/all
280                         BUILD_DIR="${WORKDIR}/${P}" \
281                                 distutils-r1_src_compile
282                 fi
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
287                 fi
288         done
291 src_test() {
292         for x in ${GMX_DIRS}; do
293                 BUILD_DIR="${WORKDIR}/${P}_${x}"\
294                         cmake_src_compile check
295         done
298 src_install() {
299         for x in ${GMX_DIRS}; do
300                 BUILD_DIR="${WORKDIR}/${P}_${x}" \
301                         cmake_src_install
302                 if use python; then
303                         BUILD_DIR="${WORKDIR}/${P}_${x}" \
304                                 cmake_src_install       python_packaging/install
305                 fi
306                 if use build-manual; then
307                         newdoc "${WORKDIR}/${P}_${x}"/docs/manual/gromacs.pdf "${PN}-manual-${PV}.pdf"
308                 fi
310                 if use doc; then
311                         if [[ ${PV} != *9999* ]]; then
312                                 newdoc "${DISTDIR}/manual-${PV/_/-}.pdf" "${PN}-manual-${PV}.pdf"
313                         fi
314                 fi
315         done
317         if use tng; then
318                 insinto /usr/include/tng
319                 doins src/external/tng_io/include/tng/*h
320         fi
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-}
325                 n="${n%.bash}"
326                 cat "${ED}"/usr/bin/gmx-completion.bash "$x" > "${T}/${n}" || die
327                 newbashcomp "${T}"/"${n}" "${n}"
328         done
329         rm "${ED}"/usr/bin/gmx-completion*.bash || die
330         readme.gentoo_create_doc
333 pkg_postinst() {
334         einfo
335         einfo  "Please read and cite gromacs related papers from list:"
336         einfo  "https://www.gromacs.org/articles.html"
337         einfo
338         readme.gentoo_print_elog