Skip to content

Commit

Permalink
science/psi4: New port: Open-source suite of ab initio quantum chemis…
Browse files Browse the repository at this point in the history
…try programs
  • Loading branch information
yurivict committed Nov 26, 2022
1 parent aa9c528 commit c492d0d
Show file tree
Hide file tree
Showing 9 changed files with 6,091 additions and 0 deletions.
1 change: 1 addition & 0 deletions science/Makefile
Expand Up @@ -265,6 +265,7 @@
SUBDIR += plumed
SUBDIR += pnetcdf
SUBDIR += precice
SUBDIR += psi4
SUBDIR += pulseview
SUBDIR += py-DendroPy
SUBDIR += py-GPy
Expand Down
74 changes: 74 additions & 0 deletions science/psi4/Makefile
@@ -0,0 +1,74 @@
PORTNAME= psi4
DISTVERSION= 1.6.1.20221122
CATEGORIES= science # quantum-chemistry
EXTRACT_ONLY= ${DISTNAME}${EXTRACT_SUFX}

MAINTAINER= yuri@FreeBSD.org
COMMENT= Open-source suite of ab initio quantum chemistry programs
WWW= https://psicode.org/

LICENSE= LGPL3
LICENSE_FILE= ${WRKSRC}/COPYING

PY_DEPENDS= ${PYTHON_PKGNAMEPREFIX}gau2grid>0:math/py-gau2grid@${PY_FLAVOR} \
${PYTHON_PKGNAMEPREFIX}qcelemental>0:science/py-qcelemental@${PY_FLAVOR} \
${PYTHON_PKGNAMEPREFIX}qcengine>0:science/py-qcengine@${PY_FLAVOR}
BUILD_DEPENDS= boost-libs>0:devel/boost-libs \
${LOCALBASE}/include/pybind11/pybind11.h:devel/pybind11 \
${PY_DEPENDS} \
libint2-psi4>0:science/libint2-psi4 # has to be this library
LIB_DEPENDS= libgg.so:math/gau2grid \
libxc.so:science/libxc
RUN_DEPENDS= ${PY_DEPENDS} \
libint2-psi4>0:science/libint2-psi4

USES= blaslapack:openblas cmake compiler:c++17-lang eigen:3 fortran localbase:ldflags python:3.8+

USE_GITHUB= yes
GH_TAGNAME= 0889d6d34

CMAKE_ARGS= -DLibxc_DIR=${LOCALBASE} \
-DFREEBSD_PYTHON_VER=${PYTHON_VER} \
-DPython_EXECUTABLE=${PYTHON_CMD}
CONFIGURE_ENV= FREEBSD_PYTHON_VER=${PYTHON_VER}

LDFLAGS+= -lexecinfo # for backtrace_symbols

TEST_ENV= ${MAKE_ENV} \
PYTHONPATH=${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}:${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}/psi4/tests \
PSIDATADIR=${STAGEDIR}${DATADIR}

post-patch:
# correct the default data dir
@${REINPLACE_CMD} \
-E 's|os.path.sep.join\(\[os.path.abspath\(os.path.dirname\(__file__\)\), "share", "psi4"\]\)|"${DATADIR}"|' \
${WRKSRC}/psi4/run_psi4.py
@${REINPLACE_CMD} \
-E 's|from pathlib import Path|&; os.environ["PSIDATADIR"] = "${DATADIR}"|' \
${WRKSRC}/psi4/run_psi4.py

do-install: # project fails to install itself into a stage directory due to a convoluted cmake code structure (DESTDIR isn't handled correctly)
# main
cd ${BUILD_WRKSRC}/stage && ${COPYTREE_SHARE} . ${STAGEDIR}${PREFIX}
${FIND} ${STAGEDIR}${PREFIX} -name "*.pyc" -delete
# samples
cd ${WRKSRC} && ${COPYTREE_SHARE} samples ${STAGEDIR}${DATADIR}
${FIND} ${STAGEDIR}${PREFIX} -name "example_psi4rc_file" -delete
# delete empty directories
${FIND} ${STAGEDIR} -type d -empty -delete
# set executable flag
${CHMOD} +x ${STAGEDIR}${PREFIX}/bin/psi4
# move python module to a proper place
${MKDIR} ${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}
${MV} ${STAGEDIR}${PREFIX}/lib/psi4 ${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}
${RLN} ${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}/psi4 ${STAGEDIR}${PREFIX}/lib/psi4 # for the path-calculating logic in psi4/__init__.py
# correct version number
@${REINPLACE_CMD} -i '' -e "s|__version__ = 'undefined'|__version__ = '${DISTVERSION}'|" \
${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}/psi4/metadata.py
@${REINPLACE_CMD} -i '' -e "s|__version_long = 'undefined+11'|__version_long = '${DISTVERSION}'|" \
${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}/psi4/metadata.py

do-test: # based on https://psicode.org/psi4manual/master/build_planning.html#faq-minutetests - most tests fail due to path mismatches
@cd ${WRKSRC}/tests/isapt2 && ${SETENV} ${TEST_ENV} pytest

.include <bsd.port.mk>
3 changes: 3 additions & 0 deletions science/psi4/distinfo
@@ -0,0 +1,3 @@
TIMESTAMP = 1669450517
SHA256 (psi4-psi4-1.6.1.20221122-0889d6d34_GH0.tar.gz) = 2ae56a29a2e6a9677ae6bcf0f302a22086427effee072c8fa58d0f12ee55cdef
SIZE (psi4-psi4-1.6.1.20221122-0889d6d34_GH0.tar.gz) = 44809685
32 changes: 32 additions & 0 deletions science/psi4/files/patch-CMakeLists.txt
@@ -0,0 +1,32 @@
--- CMakeLists.txt.orig 2022-11-22 21:26:37 UTC
+++ CMakeLists.txt
@@ -187,10 +190,14 @@ message(STATUS "Psi4 install: ${CMAKE_INSTALL_PREFIX}"
# * library: not at all

set(Python_ADDITIONAL_VERSIONS 3.11 3.10 3.9 3.8) # adjust with CMake minimum FindPythonInterp
+
+
if(DEFINED ENV{LGTM_SRC})
- find_package(Python 3.8 EXACT COMPONENTS Interpreter Development REQUIRED)
+ #find_package(Python ${FREEBSD_PYTHON_VER} EXACT COMPONENTS Interpreter Development REQUIRED)
+ find_package(Python $ENV{FREEBSD_PYTHON_VER} EXACT COMPONENTS Interpreter Development REQUIRED)
else()
- find_package(Python 3.8 COMPONENTS Interpreter Development NumPy REQUIRED)
+ #find_package(Python ${FREEBSD_PYTHON_VER} EXACT COMPONENTS Interpreter Development NumPy REQUIRED)
+ find_package(Python $ENV{FREEBSD_PYTHON_VER} EXACT COMPONENTS Interpreter Development NumPy REQUIRED)
endif()
message(STATUS "${Cyan}Found Python ${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}${ColourReset}: ${Python_EXECUTABLE} (found version ${Python_VERSION})")

@@ -302,9 +309,10 @@ ExternalProject_Add(psi4-core
-DOpenMP_LIBRARY_DIRS=${OpenMP_LIBRARY_DIRS}
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-DENABLE_CYTHONIZE=${ENABLE_CYTHONIZE}
+ -DFREEBSD_PYTHON_VER=${FREEBSD_PYTHON_VER}
CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
- USES_TERMINAL_BUILD 1
- BUILD_ALWAYS 1)
+ #USES_TERMINAL_BUILD 1
+ BUILD_ALWAYS 0)

add_subdirectory(external/downstream)
add_subdirectory(doc)
@@ -0,0 +1,8 @@
--- external/upstream/libxc/CMakeLists.txt.orig 2022-11-24 03:25:13 UTC
+++ external/upstream/libxc/CMakeLists.txt
@@ -1,4 +1,4 @@
-find_package(Libxc 5.1.2 CONFIG QUIET COMPONENTS C)
+find_package(Libxc CONFIG REQUIRED COMPONENTS C)

if(${Libxc_FOUND})
get_property(_loc TARGET Libxc::xc PROPERTY LOCATION)
11 changes: 11 additions & 0 deletions science/psi4/files/patch-psi4_CMakeLists.txt
@@ -0,0 +1,11 @@
--- psi4/CMakeLists.txt.orig 2022-11-24 05:29:32 UTC
+++ psi4/CMakeLists.txt
@@ -207,7 +207,7 @@ else()
message(STATUS "Disabled BrianQC")
endif()

-find_package(Libxc 5.1.2 CONFIG REQUIRED COMPONENTS C)
+find_package(Libxc CONFIG REQUIRED COMPONENTS C)
get_property(_loc TARGET Libxc::xc PROPERTY LOCATION)
list(APPEND _addons ${_loc})
message(STATUS "${Cyan}Using Libxc${ColourReset}: ${_loc} (version ${Libxc_VERSION})")
14 changes: 14 additions & 0 deletions science/psi4/files/patch-psi4_src_psi4_libpsio_open.cc
@@ -0,0 +1,14 @@
--- psi4/src/psi4/libpsio/open.cc.orig 2022-11-22 21:26:37 UTC
+++ psi4/src/psi4/libpsio/open.cc
@@ -41,6 +41,11 @@
#include "psi4/libpsio/psio.h"
#include "psi4/libpsio/psio.hpp"
#include "psi4/psi4-dec.h"
+
+#if defined(__FreeBSD__)
+#include <sys/stat.h>
+#endif
+
namespace psi {

void PSIO::open(size_t unit, int status) {
8 changes: 8 additions & 0 deletions science/psi4/pkg-descr
@@ -0,0 +1,8 @@
Psi4 is an open-source suite of ab initio quantum chemistry programs designed
for efficient, high-accuracy simulations of a variety of molecular properties.
We can routinely perform computations with more than 2500 basis functions
running serially or on multi-core machines.

With computationally demanding portions written in C++, Pybind11 exports many
of the C++ classes into Python, and a flexible Python driver, Psi4 strives to
be friendly to both users and developers.

0 comments on commit c492d0d

Please sign in to comment.