Skip to content

Commit 967a5db

Browse files
committed
Add support for reading QCSchema JSON
- allow automatic detection of jsonfortran installations via CMake - subproject fallback support for meson
1 parent e401fa3 commit 967a5db

31 files changed

+1058
-7
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ jobs:
144144
if: ${{ matrix.build == 'fpm' }}
145145
uses: fortran-lang/setup-fpm@v3
146146
with:
147-
fpm-version: 'v0.2.0'
147+
fpm-version: 'v0.3.0'
148148

149149
- name: Prepare for cache restore
150150
if: ${{ matrix.compiler == 'intel' }}

CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ include(GNUInstallDirs)
2727
# General configuration information
2828
add_subdirectory("config")
2929

30+
# Dependencies
31+
if(NOT TARGET "jsonfortran::jsonfortran" AND WITH_JSON)
32+
find_package("jsonfortran" REQUIRED)
33+
endif()
34+
3035
# Collect source of the project
3136
set(srcs)
3237
add_subdirectory("src")
@@ -36,6 +41,18 @@ add_library(
3641
"${PROJECT_NAME}-lib"
3742
"${srcs}"
3843
)
44+
target_compile_definitions(
45+
"${PROJECT_NAME}-lib"
46+
PRIVATE
47+
"WITH_JSON=$<BOOL:${WITH_JSON}>"
48+
)
49+
if(WITH_JSON)
50+
target_link_libraries(
51+
"${PROJECT_NAME}-lib"
52+
PRIVATE
53+
"jsonfortran::jsonfortran"
54+
)
55+
endif()
3956
set_target_properties(
4057
"${PROJECT_NAME}-lib"
4158
PROPERTIES
@@ -48,6 +65,7 @@ set_target_properties(
4865
target_include_directories(
4966
"${PROJECT_NAME}-lib"
5067
PUBLIC
68+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
5169
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
5270
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
5371
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${module-dir}>

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
To build this project from the source code in this repository you need to have
1313
a Fortran compiler supporting Fortran 2008 and one of the supported build systems:
14-
- [meson](https://mesonbuild.com) version 0.53 or newer, with
14+
- [meson](https://mesonbuild.com) version 0.55 or newer, with
1515
a build-system backend, *i.e.* [ninja](https://ninja-build.org) version 1.7 or newer
1616
- [cmake](https://cmake.org) version 3.14 or newer, with
1717
a build-system backend, *i.e.* [ninja](https://ninja-build.org) version 1.10 or newer
18-
- [fpm](https://github.com/fortran-lang/fpm) version 0.2.0 or newer
18+
- [fpm](https://github.com/fortran-lang/fpm) version 0.3.0 or newer
1919

2020
Currently this project supports GCC, Intel and PGI/NVHPC compilers.
2121

config/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,22 @@
1515
option(BUILD_SHARED_LIBS "Whether the libraries built should be shared" FALSE)
1616

1717
option(WITH_OpenMP "Enable support for shared memory parallelisation with OpenMP" TRUE)
18+
option(WITH_JSON "Enable support for JSON parsing via json-fortran" FALSE)
1819

1920
set(
2021
module-dir
2122
"${PROJECT_NAME}/${CMAKE_Fortran_COMPILER_ID}-${CMAKE_Fortran_COMPILER_VERSION}"
2223
)
2324
set(module-dir "${module-dir}" PARENT_SCOPE)
2425

26+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
27+
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
28+
install(
29+
DIRECTORY
30+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/"
31+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
32+
)
33+
2534
# Set build type as CMake does not provide defaults
2635
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
2736
set(
@@ -53,6 +62,17 @@ install(
5362
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
5463
)
5564

65+
if(BUILD_SHARED_LIBS)
66+
set(PKG_CONFIG_REQUIRES "Requires.private")
67+
else()
68+
set(PKG_CONFIG_REQUIRES "Requires")
69+
endif()
70+
if(WITH_JSON)
71+
set(PKG_CONFIG_REQUIREMENTS "json-fortran")
72+
else()
73+
set(PKG_CONFIG_REQUIREMENTS)
74+
endif()
75+
5676
configure_file(
5777
"${CMAKE_CURRENT_SOURCE_DIR}/template.pc"
5878
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"

config/cmake/Findjsonfortran.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file is part of mctc-lib.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
if(NOT TARGET "jsonfortran::jsonfortran")
16+
# json-fortran tries to make it hard to get found
17+
string(TOLOWER "jsonfortran-${CMAKE_Fortran_COMPILER_ID}" jsonfortran)
18+
find_package("${jsonfortran}" CONFIG)
19+
add_library("jsonfortran::jsonfortran" IMPORTED INTERFACE)
20+
target_link_libraries(
21+
"jsonfortran::jsonfortran"
22+
INTERFACE
23+
"jsonfortran$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:-static>"
24+
)
25+
target_include_directories(
26+
"jsonfortran::jsonfortran"
27+
INTERFACE
28+
"${jsonfortran_INCLUDE_DIRS}"
29+
)
30+
endif()

config/meson.build

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,14 @@ if get_option('openmp')
4646
omp_dep = dependency('openmp')
4747
lib_deps += omp_dep
4848
endif
49+
50+
jsonfortran_dep = dependency(
51+
'json-fortran',
52+
required: get_option('json'),
53+
fallback: ['json-fortran-8.2.5','jsonfortran_dep'],
54+
default_options: [
55+
'default_library=static',
56+
],
57+
static: get_option('default_library') != 'dynamic',
58+
)
59+
lib_deps += jsonfortran_dep

config/template.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@PACKAGE_INIT@
22

33
set("@PROJECT_NAME@_WITH_OpenMP" @WITH_OpenMP@)
4+
set("@PROJECT_NAME@_WITH_JSON" @WITH_JSON@)
45

56
if(NOT TARGET "@PROJECT_NAME@::@PROJECT_NAME@")
67
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake")
@@ -10,4 +11,8 @@ if(NOT TARGET "@PROJECT_NAME@::@PROJECT_NAME@")
1011
if(NOT TARGET "OpenMP::OpenMP_Fortran" AND "@PROJECT_NAME@_WITH_OpenMP")
1112
find_dependency("OpenMP")
1213
endif()
14+
15+
if(NOT TARGET "jsonfortran::jsonfortran" AND "@PROJECT_NAME@_WITH_JSON")
16+
find_dependency("jsonfortran")
17+
endif()
1318
endif()

config/template.pc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
44

55
Name: @PROJECT_NAME@
66
Description: @PROJECT_DESCRIPTION@
7+
@PKG_CONFIG_REQUIRES@: @PKG_CONFIG_REQUIREMENTS@
78
Version: @PROJECT_VERSION@
89
Libs: -L${libdir} -l@PROJECT_NAME@
910
Cflags: -I${includedir} -I${includedir}/@module-dir@

doc/format-qcschema.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: QCSchema JSON
3+
---
4+
5+
## Specification
6+
7+
@Note [Reference](https://molssi-qc-schema.readthedocs.io)
8+
9+
JSON files are identified by the extension ``json`` and parsed following the ``qcschema_molecule`` or ``qcschema_input`` format.
10+
The ``molecule`` entry from a ``qcschema_input`` will be extracted, but there is no guarantee that the input information will be used by the program.
11+
12+
13+
## Example
14+
15+
Caffeine molecule in ``qcschema_molecule`` format.
16+
17+
18+
```json
19+
{
20+
"schema_version": 2,
21+
"schema_name": "qcschema_molecule",
22+
"provenance": {
23+
"creator": "mctc-lib",
24+
"version": "0.2.3",
25+
"routine": "mctc_io_write_qcschema::write_qcschema"
26+
},
27+
"symbols": [
28+
"C", "N", "C", "N", "C", "C", "C", "O", "N", "C", "O", "N",
29+
"C", "C", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H"
30+
],
31+
"geometry": [
32+
2.0280536328008760E+00, 9.2407587256767454E-02,-1.4305223630546618E-01,
33+
4.7502035191684326E+00, 2.3810543955731494E-02,-1.4324120887654343E-01,
34+
6.3343605825088858E+00, 2.0709504064354083E+00,-1.4229634602115726E-01,
35+
8.7286430580574415E+00, 1.3800666865770403E+00,-1.4267429116331171E-01,
36+
8.6532430021976250E+00,-1.1931728137816557E+00,-1.4229634602115726E-01,
37+
6.2385514889727283E+00,-2.0836115686975827E+00,-1.4210737345008001E-01,
38+
5.6327054260991156E+00,-4.6995588701197342E+00,-1.3946175745499875E-01,
39+
3.4493163398727531E+00,-5.4809604515240968E+00,-1.4324120887654343E-01,
40+
7.7750874644017181E+00,-6.2442206661050452E+00,-1.3114696432760045E-01,
41+
1.0302217657417570E+01,-5.3974345751079591E+00,-1.3681614145991747E-01,
42+
1.2074024483837716E+01,-6.9158291837135346E+00,-1.3662716888884024E-01,
43+
1.0700382864677302E+01,-2.7907469296685923E+00,-1.4154045573684831E-01,
44+
1.3246032369658721E+01,-1.7697281281382971E+00,-1.4210737345008001E-01,
45+
7.4088586216540389E+00,-8.9590006222005893E+00,-1.1640710378357619E-01,
46+
1.3870586717068980E+00, 2.0558326007492296E+00,-1.4172942830792554E-01,
47+
1.3462405963542154E+00,-8.6360464982295970E-01, 1.5560001502499454E+00,
48+
1.3462405963542154E+00,-8.6133697897003281E-01,-1.8434274308584184E+00,
49+
5.6559490523416152E+00, 4.0016831651315083E+00,-1.4135148316577109E-01,
50+
1.4674287061860456E+01,-3.2622334945062916E+00,-1.4343018144762065E-01,
51+
1.3508893216027154E+01,-6.0811373372653921E-01, 1.5490081651200875E+00,
52+
1.3507759380600691E+01,-6.0622400801576681E-01,-1.8320890765937843E+00,
53+
5.4140641613627567E+00,-9.4924701903516215E+00,-1.1017100893802745E-01,
54+
8.3191394965330758E+00,-9.7494728870166600E+00, 1.5654487788038070E+00,
55+
8.3151710725404531E+00,-9.7685591166954602E+00,-1.7910820286700244E+00
56+
],
57+
"molecular_charge": 0,
58+
"connectivity": [
59+
[ 0, 1, 1],
60+
[ 1, 2, 4],
61+
[ 2, 3, 4],
62+
[ 3, 4, 4],
63+
[ 1, 5, 1],
64+
[ 4, 5, 4],
65+
[ 5, 6, 1],
66+
[ 6, 7, 2],
67+
[ 6, 8, 1],
68+
[ 8, 9, 1],
69+
[ 9,10, 2],
70+
[ 4,11, 1],
71+
[ 9,11, 1],
72+
[11,12, 1],
73+
[ 8,13, 1],
74+
[ 0,14, 1],
75+
[ 0,15, 1],
76+
[ 0,16, 1],
77+
[ 2,17, 1],
78+
[12,18, 1],
79+
[12,19, 1],
80+
[12,20, 1],
81+
[13,21, 1],
82+
[13,22, 1],
83+
[13,23, 1]
84+
]
85+
}
86+
```
87+
88+
89+
## Missing features
90+
91+
The schema is not verified on completeness and not all data is stored in the final structure type.
92+
93+
@Note Feel free to contribute support for missing features
94+
or bring missing features to our attention by opening an issue.

doc/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ This library supports reading and writing of the following formats:
1111
- [a subset of PDB format](./format-pdb.html)
1212
- [DFTB+ general format](./format-gen.html)
1313
- [Gaussian external format](./format-ein.html)
14+
- [QCSchema JSON format](./format-qcschema.html)

0 commit comments

Comments
 (0)