Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dedr-charged
Browse files Browse the repository at this point in the history
  • Loading branch information
thfroitzheim committed Nov 27, 2024
2 parents 8f2eb5d + 2a3d675 commit 337d830
Show file tree
Hide file tree
Showing 33 changed files with 729 additions and 144 deletions.
68 changes: 47 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ on: [push, pull_request]
env:
BUILD_DIR: _build
PIP_PACKAGES: >-
meson==0.55
meson
cmake
ninja
gcovr
numpy
pytest
MACOS_BASEKIT_URL: >-
https://registrationcenter-download.intel.com/akdlm/irc_nas/17969/m_BaseKit_p_2021.3.0.3043.dmg
MACOS_HPCKIT_URL: >-
https://registrationcenter-download.intel.com/akdlm/irc_nas/17890/m_HPCKit_p_2021.3.0.3226_offline.dmg
LINUX_INTEL_COMPONENTS: >-
intel-oneapi-compiler-fortran
intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic
intel-oneapi-mkl
intel-oneapi-mkl-devel
intel-oneapi-compiler-fortran-2021.2.0
intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic-2021.2.0
intel-oneapi-mkl-2021.2.0
intel-oneapi-mkl-devel-2021.2.0
jobs:
build:
Expand All @@ -29,14 +31,14 @@ jobs:
build: [meson, cmake]
build-type: [debug]
compiler: [gnu]
version: [10]
version: [12]

include:
- os: ubuntu-latest
build: meson
build-type: coverage
compiler: gnu
version: 10
version: 11

- os: windows-latest
build: meson
Expand All @@ -58,24 +60,33 @@ jobs:
FC: ${{ matrix.compiler == 'intel' && 'ifort' || 'gfortran' }}
CC: ${{ matrix.compiler == 'intel' && 'icc' || 'gcc' }}
GCC_V: ${{ matrix.version }}
PYTHON_V: 3.8
PYTHON_V: 3.9
OMP_NUM_THREADS: 1,2,1

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- uses: actions/setup-python@v1
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_V }}

- name: Install GCC (OSX)
- name: Link pre-installed GCC and FC (macOS)
if: ${{ contains(matrix.os, 'macos') && matrix.compiler == 'gnu' }}
run: |
brew install gcc@${{ env.GCC_V }}
ln -s /usr/local/bin/gfortran-${{ env.GCC_V }} /usr/local/bin/gfortran
ln -s /usr/local/bin/gcc-${{ env.GCC_V }} /usr/local/bin/gcc
ln -s /usr/local/bin/g++-${{ env.GCC_V }} /usr/local/bin/g++
brew install openblas
gfortran_path=$( which gfortran-${{ env.GCC_V }} )
gcc_path=$( which gcc-${{ env.GCC_V }} )
gplusplus_path=$( which g++-${{ env.GCC_V }} )
export FC=$gfortran_path
export CC=$gcc_path
export CXX=$gplusplus_path
ln -s $gfortran_path /usr/local/bin/gfortran
ln -s $gcc_path /usr/local/bin/gcc
ln -s $gplusplus_path /usr/local/bin/g++
echo "PKG_CONFIG_PATH=/usr/local/opt/openblas/lib/pkgconfig" >> $GITHUB_ENV
echo "LDFLAGS=-L/opt/homebrew/opt/openblas/lib" >> $GITHUB_ENV
echo "CPPFLAGS=-I/opt/homebrew/opt/openblas/include" >> $GITHUB_ENV
- name: Install GCC (Linux)
if: ${{ contains(matrix.os, 'ubuntu') && matrix.compiler == 'gnu' }}
Expand Down Expand Up @@ -116,7 +127,7 @@ jobs:
- name: Cache Intel install
if: ${{ matrix.compiler == 'intel' }}
id: cache-install
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: /opt/intel/oneapi
key: install-${{ matrix.compiler }}-${{ matrix.version }}-${{ matrix.os }}
Expand Down Expand Up @@ -176,7 +187,6 @@ jobs:
if: ${{ matrix.compiler == 'intel' }}
run: |
source /opt/intel/oneapi/setvars.sh
source /opt/intel/oneapi/compiler/2024.0/env/vars.sh
printenv >> $GITHUB_ENV
- name: Install build and test dependencies
Expand All @@ -187,6 +197,12 @@ jobs:
if: ${{ contains(matrix.os, 'windows') }}
run: pip3 install meson==0.55

- name: Check gfortran version for meson build
if: ${{ matrix.build == 'meson' && matrix.compiler == 'gnu' }}
run: |
gfortran --version
which gfortran
- name: Configure build (meson)
if: ${{ matrix.build == 'meson' }}
run: >-
Expand All @@ -199,7 +215,9 @@ jobs:
${{ env.MESON_ARGS }}
env:
COVERAGE: ${{ matrix.build-type == 'coverage' }}
MESON_ARGS: ${{ matrix.compiler == 'intel' && '-Dfortran_link_args=-qopenmp' || '' }}
MESON_ARGS: >-
${{ matrix.compiler == 'intel' && '-Dfortran_link_args=-qopenmp' || '' }}
${{ contains(matrix.os, 'macos') && '-Dlapack=openblas' || '' }}
- name: Configure build (CMake)
if: ${{ matrix.build == 'cmake' }}
Expand All @@ -220,18 +238,26 @@ jobs:
meson test -C ${{ env.BUILD_DIR }} --print-errorlogs --no-rebuild
env:
OMP_NUM_THREADS: 1
MKL_NUM_THREADS: 1

- name: Run validation tests
if: ${{ matrix.build == 'meson' && ! contains(matrix.os, 'windows') }}
run: |
meson test -C ${{ env.BUILD_DIR }} --print-errorlogs --no-rebuild --suite multicharge --benchmark
env:
OMP_NUM_THREADS: 1
MKL_NUM_THREADS: 1

- name: Run unit tests
if: ${{ matrix.build == 'cmake' }}
run: |
ctest --output-on-failure --parallel 2
ctest --output-on-failure --parallel 2
working-directory: ${{ env.BUILD_DIR }}

- name: Create coverage report
if: ${{ matrix.build == 'meson' && matrix.build-type == 'coverage' }}
run:
ninja -C ${{ env.BUILD_DIR }} coverage
ninja -C ${{ env.BUILD_DIR }} coverage

- name: Install project
run: |
Expand All @@ -249,7 +275,7 @@ jobs:

- name: Upload package
if: ${{ matrix.build == 'meson' && matrix.build-type != 'coverage' }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: ${{ env.MCHRG_OUTPUT }}
path: ${{ env.MCHRG_OUTPUT }}
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ get_directory_property(is-subproject PARENT_DIRECTORY)
project(
"multicharge"
LANGUAGES "Fortran"
VERSION "0.2.0"
VERSION "0.3.0"
DESCRIPTION "Molecular structure store for testing"
)

Expand Down
81 changes: 69 additions & 12 deletions app/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ program main
& write_ascii_model, write_ascii_properties, write_ascii_results, &
& get_coordination_number, get_covalent_rad, get_lattice_points, &
& get_multicharge_version
use multicharge_output, only : json_results
implicit none
character(len=*), parameter :: prog_name = "multicharge"
character(len=*), parameter :: json_output = "multicharge.json"

character(len=:), allocatable :: input
character(len=:), allocatable :: input, chargeinput
integer, allocatable :: input_format
integer :: stat, unit
type(error_type), allocatable :: error
type(structure_type) :: mol
type(mchrg_model_type) :: model
logical :: grad
logical :: grad, json, exist
real(wp), parameter :: cn_max = 8.0_wp, cutoff = 25.0_wp
real(wp), allocatable :: cn(:), dcndr(:, :, :), dcndL(:, :, :), rcov(:), trans(:, :)
real(wp), allocatable :: energy(:), gradient(:, :), sigma(:, :)
real(wp), allocatable :: qvec(:), dqdr(:, :, :), dqdL(:, :, :)
real(wp), allocatable :: charge

call get_arguments(input, input_format, grad, error)
call get_arguments(input, input_format, grad, charge, json, error)
if (allocated(error)) then
write(error_unit, '(a)') error%message
error stop
Expand All @@ -52,6 +56,27 @@ program main
error stop
end if

if (allocated(charge)) then
mol%charge = charge
else
chargeinput = ".CHRG"
inquire(file=chargeinput, exist=exist)
if (exist) then
open(file=chargeinput, newunit=unit)
allocate(charge)
read(unit, *, iostat=stat) charge
if (stat == 0) then
mol%charge = charge
write(output_unit, '(a,/)') &
"[Info] Molecular charge read from '"//chargeinput//"'"
else
write(output_unit, '(a,/)') &
"[Warn] Could not read molecular charge read from '"//chargeinput//"'"
end if
close(unit)
end if
end if

call new_eeq2019_model(mol, model)
call get_lattice_points(mol%periodic, mol%lattice, cutoff, trans)

Expand Down Expand Up @@ -79,6 +104,14 @@ program main
call write_ascii_properties(output_unit, mol, model, cn, qvec)
call write_ascii_results(output_unit, mol, energy, gradient, sigma)

if (json) then
open(file=json_output, newunit=unit)
call json_results(unit, " ", energy=sum(energy), gradient=gradient, charges=qvec, cn=cn)
close(unit)
write(output_unit, '(a)') &
"[Info] JSON dump of results written to '"// json_output //"'"
end if

contains


Expand All @@ -95,10 +128,12 @@ subroutine help(unit)
""

write(unit, '(2x, a, t25, a)') &
"-i, --input <format>", "Hint for the format of the input file", &
"--grad", "Evaluate molecular gradient and virial", &
"--version", "Print program version and exit", &
"--help", "Show this help message"
"-i, -input, --input <format>", "Hint for the format of the input file", &
"-c, -charge, --charge <value>", "Set the molecular charge", &
"-g, -grad, --grad", "Evaluate molecular gradient and virial", &
"-j, -json, --json", "Provide output in JSON format to the file 'multicharge.json'", &
"-v, -version, --version", "Print program version and exit", &
"-h, -help, --help", "Show this help message"

write(unit, '(a)')

Expand All @@ -116,7 +151,7 @@ subroutine version(unit)
end subroutine version


subroutine get_arguments(input, input_format, grad, error)
subroutine get_arguments(input, input_format, grad, charge, json, error)

!> Input file name
character(len=:), allocatable :: input
Expand All @@ -127,23 +162,30 @@ subroutine get_arguments(input, input_format, grad, error)
!> Evaluate gradient
logical, intent(out) :: grad

!> Provide JSON output
logical, intent(out) :: json

!> Charge
real(wp), allocatable, intent(out) :: charge

!> Error handling
type(error_type), allocatable, intent(out) :: error

integer :: iarg, narg
integer :: iarg, narg, iostat
character(len=:), allocatable :: arg

grad = .false.
json = .false.
iarg = 0
narg = command_argument_count()
do while(iarg < narg)
iarg = iarg + 1
call get_argument(iarg, arg)
select case(arg)
case("-help", "--help")
case("-h", "-help", "--help")
call help(output_unit)
stop
case("-version", "--version")
case("-v", "-version", "--version")
call version(output_unit)
stop
case default
Expand All @@ -161,8 +203,23 @@ subroutine get_arguments(input, input_format, grad, error)
exit
end if
input_format = get_filetype("."//arg)
case("-grad", "--grad")
case("-c", "-charge", "--charge")
iarg = iarg + 1
call get_argument(iarg, arg)
if (.not.allocated(arg)) then
call fatal_error(error, "Missing argument for charge")
exit
end if
allocate(charge)
read(arg, *, iostat=iostat) charge
if (iostat /= 0) then
call fatal_error(error, "Invalid charge value")
exit
end if
case("-g", "-grad", "--grad")
grad = .true.
case("-j", "-json", "--json")
json = .true.
end select
end do

Expand Down
2 changes: 1 addition & 1 deletion config/cmake/Findcustom-blas.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if(WITH_ILP64)
endif()

if(NOT BLAS_FOUND)
find_package("BLAS")
find_package("BLAS" REQUIRED)
if(NOT TARGET "BLAS::BLAS")
add_library("BLAS::BLAS" INTERFACE IMPORTED)
target_link_libraries("BLAS::BLAS" INTERFACE "${BLAS_LIBRARIES}")
Expand Down
4 changes: 2 additions & 2 deletions config/cmake/Findcustom-lapack.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ if(WITH_ILP64)
endif()

if(NOT LAPACK_FOUND)
find_package("LAPACK")
find_package("LAPACK" REQUIRED)

if(NOT TARGET "BLAS::BLAS")
find_package("custom-blas")
find_package("custom-blas" REQUIRED)
endif()

if(NOT TARGET "LAPACK::LAPACK")
Expand Down
2 changes: 1 addition & 1 deletion config/cmake/Findmctc-lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
set(_lib "mctc-lib")
set(_pkg "MCTCLIB")
set(_url "https://github.com/grimme-lab/mctc-lib")
set(_rev "v0.3.0")
set(_rev "v0.3.2")

if(NOT DEFINED "${_pkg}_FIND_METHOD")
if(DEFINED "${PROJECT_NAME}-dependency-method")
Expand Down
3 changes: 2 additions & 1 deletion config/cmake/Findmstore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
set(_lib "mstore")
set(_pkg "MSTORE")
set(_url "https://github.com/grimme-lab/mstore")
set(_rev "v0.3.0")

if(NOT DEFINED "${_pkg}_FIND_METHOD")
if(DEFINED "${PROJECT_NAME}-dependency-method")
Expand All @@ -28,7 +29,7 @@ endif()

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

multicharge_find_package("${_lib}" "${${_pkg}_FIND_METHOD}" "${_url}" "HEAD")
multicharge_find_package("${_lib}" "${${_pkg}_FIND_METHOD}" "${_url}" "${_rev}")

if(DEFINED "_${_pkg}_FIND_METHOD")
unset("${_pkg}_FIND_METHOD")
Expand Down
4 changes: 4 additions & 0 deletions config/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ os = host_machine.system()
fc = meson.get_compiler('fortran')
fc_id = fc.get_id()

# Treat Intel LLVM compiler as standard Intel compiler for compatibility
if fc_id == 'intel-llvm'
fc_id = 'intel'
endif
if fc_id == 'gcc'
add_project_arguments(
'-ffree-line-length-none',
Expand Down
Loading

0 comments on commit 337d830

Please sign in to comment.