Skip to content

Commit abfbff1

Browse files
authored
Support chemical JSON (#50)
- implement basic reader for chemical JSON - implement writer for chemical JSON - test if chemical JSON produced by mctc-lib round-trips - document implemented format - implementation matches https://github.com/OpenChemistry/avogadrolibs/blob/c707a49/avogadro/io/cjsonformat.cpp
1 parent f02b590 commit abfbff1

19 files changed

+1463
-0
lines changed

doc/format-cjson.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
title: Chemical JSON
3+
---
4+
5+
## Specification
6+
7+
@Note [Reference](https://github.com/OpenChemistry/avogadrolibs/blob/master/avogadro/io/cjsonformat.cpp)
8+
9+
Chemical JSON files are identified by the extension ``cjson`` and parsed following the format implemented in Avogadro 2.
10+
The entries *name*, *atoms.elements.number*, *atoms.coords.3d*, *atoms.coords.3d fractional*, *unit cell*, *atoms.formalCharges*, *bonds.connections.index*, and *bonds.order* are recognized by the reader.
11+
12+
13+
## Example
14+
15+
Caffeine molecule in ``qcschema_molecule`` format.
16+
17+
18+
```json
19+
{
20+
"chemicalJson": 1,
21+
"atoms": {
22+
"elements": {
23+
"number": [
24+
6, 7, 6, 7, 6, 6, 6, 8, 7, 6, 8, 7, 6, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
25+
]
26+
},
27+
"coords": {
28+
"3d": [
29+
1.0731997649702911E+00, 4.8899989290949721E-02, -7.5699983421776973E-02,
30+
2.5136994495022558E+00, 1.2599997240612813E-02, -7.5799983399877077E-02,
31+
3.3519992659154081E+00, 1.0958997599990143E+00, -7.5299983509376570E-02,
32+
4.6189989884436962E+00, 7.3029984006504256E-01, -7.5499983465576764E-02,
33+
4.5790989971817559E+00, -6.3139986172404194E-01, -7.5299983509376570E-02,
34+
3.3012992770186567E+00, -1.1025997585317211E+00, -7.5199983531276451E-02,
35+
2.9806993472297307E+00, -2.4868994553714288E+00, -7.3799983837875047E-02,
36+
1.8252996002611557E+00, -2.9003993648153492E+00, -7.5799983399877077E-02,
37+
4.1143990989505834E+00, -3.3042992763616597E+00, -6.9399984801470568E-02,
38+
5.4516988060832432E+00, -2.8561993744951040E+00, -7.2399984144473614E-02,
39+
6.3892986007497967E+00, -3.6596991985294207E+00, -7.2299984166373524E-02,
40+
5.6623987599401575E+00, -1.4767996765823013E+00, -7.4899983596976152E-02,
41+
7.0094984649266268E+00, -9.3649979490745228E-01, -7.5199983531276451E-02,
42+
3.9205991413925863E+00, -4.7408989617477202E+00, -6.1599986509662634E-02,
43+
7.3399983925474632E-01, 1.0878997617510062E+00, -7.4999983575076257E-02,
44+
7.1239984398512435E-01, -4.5699989991746470E-01, 8.2339981967623732E-01,
45+
7.1239984398512435E-01, -4.5579990018026340E-01, -9.7549978636649193E-01,
46+
2.9929993445360430E+00, 2.1175995362477531E+00, -7.4799983618876062E-02,
47+
7.7652982994071955E+00, -1.7262996219420552E+00, -7.5899983377977168E-02,
48+
7.1485984344638682E+00, -3.2179992952612718E-01, 8.1969982048653345E-01,
49+
7.1479984345952676E+00, -3.2079992974512617E-01, -9.6949978768048573E-01,
50+
2.8649993725679135E+00, -5.0231988999243073E+00, -5.8299987232359275E-02,
51+
4.4022990359007768E+00, -5.1591988701404459E+00, 8.2839981858124223E-01,
52+
4.4001990363606742E+00, -5.1692988679285561E+00, -9.4779979243276369E-01
53+
]
54+
}
55+
},
56+
"bonds": {
57+
"connections": {
58+
"index": [
59+
0, 1,
60+
1, 2,
61+
2, 3,
62+
3, 4,
63+
1, 5,
64+
4, 5,
65+
5, 6,
66+
6, 7,
67+
6, 8,
68+
8, 9,
69+
9, 10,
70+
4, 11,
71+
9, 11,
72+
11, 12,
73+
8, 13,
74+
0, 14,
75+
0, 15,
76+
0, 16,
77+
2, 17,
78+
12, 18,
79+
12, 19,
80+
12, 20,
81+
13, 21,
82+
13, 22,
83+
13, 23
84+
]
85+
},
86+
"order": [
87+
1, 4, 4, 4, 1, 4, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
88+
]
89+
}
90+
}
91+
```
92+
93+
94+
## Missing features
95+
96+
The schema is not verified on completeness and not all data is stored in the final structure type.
97+
98+
@Note Feel free to contribute support for missing features
99+
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,6 +11,7 @@ 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+
- [Chemical JSON format](./format-cjson.html)
1415
- [QCSchema JSON format](./format-qcschema.html)
1516
- [FHI-aims geometry.in](./format-aims.html)
1617
- [Q-Chem molecule format](./format-qchem.html)

man/mctc-convert.1.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Supported formats:
2727
- Connection table files, molfile (mol) and structure data format (sdf)
2828
- Gaussian's external program input (ein)
2929
- JSON input with `qcschema_molecule` or `qcschema_input` structure (json)
30+
- Chemical JSON input (cjson)
3031
- FHI-AIMS' input files (geometry.in)
3132
- Q-Chem molecule block inputs (qchem)
3233

src/mctc/io/filetype.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ module mctc_io_filetype
5959
!> Q-Chem molecule format
6060
integer :: qchem = 11
6161

62+
!> Chemical JSON format (avogadro)
63+
integer :: cjson = 12
64+
6265
end type enum_filetype
6366

6467
!> File type enumerator
@@ -102,6 +105,8 @@ elemental function get_filetype(file) result(ftype)
102105
ftype = filetype%gaussian
103106
case('json')
104107
ftype = filetype%qcschema
108+
case('cjson')
109+
ftype = filetype%cjson
105110
case('qchem')
106111
ftype = filetype%qchem
107112
end select

src/mctc/io/read.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module mctc_io_read
1616
use mctc_env_error, only : error_type, fatal_error
1717
use mctc_io_filetype, only : filetype, get_filetype
1818
use mctc_io_read_aims, only : read_aims
19+
use mctc_io_read_cjson, only : read_cjson
1920
use mctc_io_read_ctfile, only : read_molfile, read_sdf
2021
use mctc_io_read_gaussian, only : read_gaussian_external
2122
use mctc_io_read_genformat, only : read_genformat
@@ -149,6 +150,9 @@ subroutine get_structure_reader(reader, ftype)
149150
case(filetype%qcschema)
150151
reader => read_qcschema
151152

153+
case(filetype%cjson)
154+
reader => read_cjson
155+
152156
case(filetype%pdb)
153157
reader => read_pdb
154158

src/mctc/io/read/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ set(dir "${CMAKE_CURRENT_SOURCE_DIR}")
1717
list(
1818
APPEND srcs
1919
"${dir}/aims.f90"
20+
"${dir}/cjson.F90"
2021
"${dir}/ctfile.f90"
2122
"${dir}/gaussian.f90"
2223
"${dir}/genformat.f90"

0 commit comments

Comments
 (0)