# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           python 1.0
PortGroup           github 1.0
PortGroup           boost 1.0

github.setup        schrodinger pymol-open-source 3.1.0 v
github.tarball_from archive
name                pymol
revision            1
conflicts           pymol-devel

categories          science chemistry
universal_variant   no
license             PSF
maintainers         {gmail.com:howarth.at.macports @jwhowarth} openmaintainer

description         Molecular graphics system
long_description    PyMOL is a molecular graphics system with an embedded Python interpreter \
                    designed for real-time visualization and rapid generation of high-quality \
                    molecular graphics images and animations.

homepage            https://www.pymol.org/

checksums           rmd160  0333aef1a1874cb7f8600923293a319c4090f4ce \
                    sha256  54306d65060bd58ed8b3dab1a8af521aeb4fd417871f15f463ff05ccb4e121fe \
                    size    29550866

subport pymol-devel {
    github.setup    schrodinger pymol-open-source 58484245b638b8a8f85966ec
    github.tarball_from archive
    version         20251010-[string range ${github.version} 0 7]
    conflicts       pymol
    revision        0
    maintainers     {reneeotten @reneeotten} openmaintainer
    checksums       rmd160  10b3a486fe1e1e6f1987f77d08eaa05d42c435a6 \
                    sha256  e40fa9b4b570ef7009c416e213f682f7bdd87733de6ba19ac9171d4b7e6eb877 \
                    size    29594476
}

variant python310 conflicts python311 python312 python313 python314 description {Use Python 3.10} {}
variant python311 conflicts python310 python312 python313 python314 description {Use Python 3.11} {}
variant python312 conflicts python310 python311 python313 python314 description {Use Python 3.12} {}
variant python313 conflicts python310 python311 python312 python314 description {Use Python 3.13} {}
variant python314 conflicts python310 python311 python312 python313 description {Use Python 3.14} {}

if {![variant_isset python310] && ![variant_isset python311]&& ![variant_isset python312] && ![variant_isset python314]} {
    default_variants +python313
}

foreach pv {314 313 312 311 310} {
    if {[variant_isset python${pv}]} {
        python.default_version ${pv}
        break
    }
}

python.link_binaries no
python.pep517   no

boost.depends_type build

compiler.cxx_standard 2017

variant vtkm description {Use VTK-m for isosurface generation} {
    if {${subport} eq "pymol-devel"} {
        depends_lib-append  port:vtk-m
        build.args-append   --use-vtkm 2.3
    } else {
        depends_lib-append  port:vtk-m-17
        build.args-append   --use-vtkm 1.7
    }
}

variant openmp description {Enable OpenMP support} {
    build.args-append   --use-openmp yes

    compiler.openmp_version 4.0
    patchfiles-append   patch-openmp.diff
}

depends_build-append \
                    port:py${python.version}-setuptools \
                    path:bin/cmake:cmake


depends_lib-append  port:freetype \
                    port:glew \
                    port:glm \
                    port:libpng \
                    port:libGLU \
                    port:libxml2 \
                    port:msgpack-cpp \
                    port:mmtf-cpp \
                    port:netcdf \
                    port:py${python.version}-numpy

depends_run-append  port:py${python.version}-pyqt5

patchfiles          pymol_shell.diff \
                    setup.py.diff \
                    patch-boost-include.diff \
                    apbs_gui_qt6.diff \
                    patch-numpy-pyproject.toml.diff

if {${subport} eq "pymol-devel"} {
    patchfiles-replace  setup.py.diff patch-devel-setup.py.diff
    patchfiles-delete   apbs_gui_qt6.diff \
                        patch-numpy-pyproject.toml.diff
}

post-patch {
    reinplace  "s|@PREFIX@|${prefix}|g" ${worksrcpath}/setup.py
    reinplace  "s|@@BOOST_INC_DIR@@|[boost::include_dir]|g" ${worksrcpath}/setup.py
    reinplace  "s|@@PYTHON_PKGDIR@@|${python.pkgd}|g" ${worksrcpath}/setup/pymol_macports
    reinplace  "s|@@PYTHON_BINARY@@|${python.bin}|g" ${worksrcpath}/setup/pymol_macports
    reinplace  "s|cxx + ' ' + cxxflags|'${configure.cxx} ' + cxxflags|g" ${worksrcpath}/monkeypatch_distutils.py
}

post-destroot {
     file copy ${worksrcpath}/setup/pymol_macports ${destroot}${prefix}/bin/pymol
     file attributes ${destroot}${prefix}/bin/pymol -permissions a+x
}
