Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPCM-X #838

Merged
merged 14 commits into from
Aug 14, 2023
76 changes: 76 additions & 0 deletions .github/workflows/fortran-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,82 @@ jobs:
working-directory: ${{ env.BUILD_DIR }}
env:
OMP_NUM_THREADS: 2,1

xtb-lightweight-meson-build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
fc: [gfortran-11]
cc: [gcc-11]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.x

- name: Install meson
run: pip3 install meson==0.62.0 ninja cmake

- name: Configure build
run: >-
meson setup ${{ env.BUILD_DIR }}
--buildtype=debug
--warnlevel=0
${{ env.MESON_ARGS }}
env:
FC: ${{ matrix.fc }}
CC: ${{ matrix.cc }}
MESON_ARGS: ${{ '-Dlapack=netlib -Dtblite=disabled -Dcpcmx=disabled' }}

- name: Build project
run: meson compile -C ${{ env.BUILD_DIR }}

- name: Run unit tests
run: meson test -C ${{ env.BUILD_DIR }} --print-errorlogs --no-rebuild -t 120 --suite xtb
env:
OMP_NUM_THREADS: 2,1

xtb-lightweight-cmake-build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
fc: [gfortran-10]
cc: [gcc-10]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.x

- name: Install CMake
run: pip3 install ninja cmake==3.26.4

- name: Configure build
run: cmake -B ${{ env.BUILD_DIR }} -DWITH_CPCMX=false -DWITH_TBLITE=false -G Ninja
env:
FC: ${{ matrix.fc }}
CC: ${{ matrix.cc }}

- name: Build project
run: cmake --build ${{ env.BUILD_DIR }}

- name: Run unit tests
run: ctest --parallel --output-on-failure -R 'xtb/*'
working-directory: ${{ env.BUILD_DIR }}
env:
OMP_NUM_THREADS: 2,1

# Test native MinGW Windows build
mingw-meson-build:
Expand Down
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ if(NOT TARGET "tblite::tblite" AND WITH_TBLITE)
find_package("tblite" REQUIRED)
endif()

if(NOT TARGET "cpcmx::cpcmx" AND WITH_CPCMX)
find_package("cpcmx" REQUIRED)
endif()

if(NOT TARGET "test-drive::test-drive")
find_package("test-drive" REQUIRED)
endif()
Expand Down Expand Up @@ -75,6 +79,7 @@ target_link_libraries(
"${PROJECT_NAME}-object"
PUBLIC
"mctc-lib::mctc-lib"
"$<$<BOOL:${WITH_CPCMX}>:cpcmx::cpcmx>"
"$<$<BOOL:${WITH_TBLITE}>:tblite::tblite>"
"$<$<BOOL:${WITH_OpenMP}>:OpenMP::OpenMP_Fortran>"
)
Expand Down Expand Up @@ -105,7 +110,8 @@ target_link_libraries(
${LAPACK_LIBRARIES}
"$<$<BOOL:${WITH_OpenMP}>:OpenMP::OpenMP_Fortran>"
"mctc-lib::mctc-lib"
"tblite::tblite"
"$<$<BOOL:${WITH_CPCMX}>:cpcmx::cpcmx>"
"$<$<BOOL:${WITH_TBLITE}>:tblite::tblite>"
)
set_target_properties(
"lib-${PROJECT_NAME}-static"
Expand Down Expand Up @@ -136,7 +142,8 @@ target_link_libraries(
${LAPACK_LIBRARIES}
"$<$<BOOL:${WITH_OpenMP}>:OpenMP::OpenMP_Fortran>"
"mctc-lib::mctc-lib"
"tblite::tblite"
"$<$<BOOL:${WITH_CPCMX}>:cpcmx::cpcmx>"
"$<$<BOOL:${WITH_TBLITE}>:tblite::tblite>"
)
set_target_properties(
"lib-${PROJECT_NAME}-shared"
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ for GBSA and ALPB implicit solvation:
*J. Chem. Theory Comput.*, **2021**, 17, 4250-4261
DOI: [10.1021/acs.jctc.1c00471](https://doi.org/10.1021/acs.jctc.1c00471)

for ddCOSMO and CPCM-X implicit solvation:
- M.Stahn, S. Ehlert, S. Grimme,
*J. Phys. Chem. A*, **2023**, XX, XXX-XXX
DOI: [10.1021/acs.jpca.3c04382](https://doi.org/10.1021/acs.jpca.3c04382)

for DFT-D4:
- E. Caldeweyher, C. Bannwarth and S. Grimme, *J. Chem. Phys.*, **2017**, 147, 034112.
DOI: [10.1063/1.4993215](https://dx.doi.org/10.1063/1.4993215)
Expand Down
1 change: 1 addition & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

option(WITH_OpenMP "Enable support for shared memory parallelisation with OpenMP" TRUE)
option(WITH_TBLITE "Use tblite library as backend for xTB" TRUE)
option(WITH_CPCMX "Use CPCM-X solvation library for xTB" TRUE)
if(NOT DEFINED "${PROJECT_NAME}-dependeny-method")
set(
"${PROJECT_NAME}-dependency-method"
Expand Down
91 changes: 91 additions & 0 deletions cmake/modules/Findcpcmx.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# This file is part of xtb.
# SPDX-Identifier: LGPL-3.0-or-later
#
# xtb is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# xtb is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with xtb. If not, see <https://www.gnu.org/licenses/>.

#[[.rst:
Find test-cpcmx
---------------

Makes the cpcmx project available.

Imported Targets
^^^^^^^^^^^^^^^^

This module provides the following imported target, if found:

``cpcmx::cpcmx``
The cpcmx library


Result Variables
^^^^^^^^^^^^^^^^

This module will define the following variables:

``cpcmx_FOUND``
True if the test-drive library is available

``cpcmx_SOURCE_DIR``
Path to the source directory of the test-drive project,
only set if the project is included as source.

``cpcmx_BINARY_DIR``
Path to the binary directory of the test-drive project,
only set if the project is included as source.

Cache variables
^^^^^^^^^^^^^^^

The following cache variables may be set to influence the library detection:

``cpcmx_FIND_METHOD``
Methods to find or make the project available. Available methods are
- ``cmake``: Try to find via CMake config file
- ``pkgconf``: Try to find via pkg-config file
- ``subproject``: Use source in subprojects directory
- ``fetch``: Fetch the source from upstream

``cpcmx_DIR``
Used for searching the CMake config file

``cpcmx_SUBPROJECT``
Directory to find the test-drive subproject, relative to the project root

#]]

set(_lib "cpcmx")
set(_pkg "cpcmx")
set(_url "https://github.com/grimme-lab/CPCM-X")

if(NOT DEFINED "${_pkg}_FIND_METHOD")
if(DEFINED "${PROJECT_NAME}-dependency-method")
set("${_pkg}_FIND_METHOD" "${${PROJECT_NAME}-dependency-method}")
else()
set("${_pkg}_FIND_METHOD" "cmake" "pkgconf" "subproject" "fetch")
endif()
set("_${_pkg}_FIND_METHOD")
endif()

include("${CMAKE_CURRENT_LIST_DIR}/xtb-utils.cmake")

xtb_find_package("${_lib}" "${${_pkg}_FIND_METHOD}" "${_url}")

if(DEFINED "_${_pkg}_FIND_METHOD")
unset("${_pkg}_FIND_METHOD")
unset("_${_pkg}_FIND_METHOD")
endif()
unset(_lib)
unset(_pkg)
unset(_url)
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ xtb_lib = library(
install: install,
fortran_args: [
'-DWITH_TBLITE=@0@'.format(tblite_dep.found() ? 1 : 0),
'-DWITH_CPCMX=@0@'.format(cpx_dep.found() ? 1 : 0),
],
link_language: 'fortran',
)
Expand Down
9 changes: 9 additions & 0 deletions meson/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,12 @@ tblite_dep = dependency(
required: get_option('tblite')
)
lib_deps += tblite_dep

# Get CPCM-X
cpx_dep = dependency(
'cpx',
fallback: ['cpx', 'cpx_dep'],
default_options: ['default_library=static'],
required: get_option('cpcmx')
)
lib_deps += cpx_dep
8 changes: 8 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ option(
description: 'use tblite library as backend for xTB',
)

option(
'cpcmx',
type: 'feature',
value: 'auto',
yield: true,
description: 'include CPCM-X library for solvation evaluation',
)

option(
'openmp',
type: 'boolean',
Expand Down
7 changes: 7 additions & 0 deletions src/features.F90
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
#define WITH_TBLITE 0
#endif

#ifndef WITH_CPCMX
#define WITH_CPCMX 0
#endif

module xtb_features
implicit none
private

public :: get_xtb_feature

logical, parameter :: tblite_support = WITH_TBLITE /= 0
logical, parameter :: cpcmx_support = WITH_CPCMX /= 0


contains
Expand All @@ -37,6 +42,8 @@ function get_xtb_feature(feature) result(has_feature)
select case(feature)
case("tblite")
has_feature = tblite_support
case("cpcmx")
has_feature = cpcmx_support
case("color")
has_feature = color_support()
case default
Expand Down
Loading
Loading