Skip to content

Commit 8faa526

Browse files
committed
Improve documentation
1 parent aa89d4b commit 8faa526

21 files changed

Lines changed: 1213 additions & 339 deletions

README.md

Lines changed: 187 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,44 @@
66
[![docs](https://github.com/grimme-lab/mctc-lib/workflows/docs/badge.svg)](https://grimme-lab.github.io/mctc-lib)
77
[![codecov](https://codecov.io/gh/grimme-lab/mctc-lib/branch/main/graph/badge.svg)](https://codecov.io/gh/grimme-lab/mctc-lib)
88

9+
A Fortran library providing unified molecular structure data handling and geometry file format I/O for computational chemistry applications.
10+
The library supports reading and writing of molecular structures in more than twelve different geometry formats and provides element data and coordination number utilities.
11+
12+
13+
## Features
14+
15+
- **Unified structure representation**: A common [``structure_type``](https://grimme-lab.github.io/mctc-lib/type/structure_type.html) for handling molecular and periodic systems
16+
- **Multi-format I/O**: Read and write structures in 12+ geometry formats
17+
- **Element data**: Access to atomic/covalent/vdW radii and Pauling electronegativities
18+
- **Coordination numbers**: Multiple counting functions (exponential, error function, electronegativity-weighted)
19+
- **Helpful error messages**: Detailed error reporting with source location information
20+
- **Multiple build systems**: Support for meson, CMake, and fpm
21+
22+
23+
## Quick Start
24+
25+
```f90
26+
program example
27+
use mctc_io
28+
use mctc_env
29+
implicit none
30+
type(structure_type) :: mol
31+
type(error_type), allocatable :: error
32+
33+
! Read a structure (format auto-detected from extension)
34+
call read_structure(mol, "molecule.xyz", error)
35+
if (allocated(error)) stop error%message
36+
37+
! Access structure data
38+
print '(a,i0)', "Number of atoms: ", mol%nat
39+
print '(a,f12.6)', "Total charge: ", mol%charge
40+
41+
! Write to different format
42+
call write_structure(mol, "molecule.mol", error)
43+
if (allocated(error)) stop error%message
44+
end program
45+
```
46+
947

1048
## Supported formats
1149

@@ -175,10 +213,32 @@ mctc-lib.git = "https://github.com/grimme-lab/mctc-lib"
175213

176214
An example application is provided with the [``mctc-convert``](man/mctc-convert.1.adoc) program to convert between different supported input formats.
177215

216+
217+
### Using mctc-convert
218+
219+
After building, the ``mctc-convert`` tool can convert between any supported formats:
220+
221+
```bash
222+
# Convert xyz to Turbomole coord
223+
mctc-convert molecule.xyz molecule.coord
224+
225+
# Convert VASP POSCAR to xyz
226+
mctc-convert POSCAR structure.xyz
227+
228+
# Pipe from stdin to stdout
229+
cat input.xyz | mctc-convert -i xyz -o mol - -
230+
231+
# Preserve bond information from SDF when converting
232+
mctc-convert optimized.xyz final.sdf --template original.sdf
233+
```
234+
235+
236+
### Library Usage
237+
178238
To read an input file using the IO library use the ``read_structure`` routine.
179239
The final geometry data is stored in a ``structure_type``:
180240

181-
```fortran
241+
```f90
182242
use mctc_io
183243
use mctc_env
184244
type(structure_type) :: mol
@@ -197,7 +257,7 @@ Alternatively, the ``filetype`` enumerator provides the identifiers of all suppo
197257

198258
In a similar way the ``write_structure`` routine allows to write a ``structure_type`` to a file or unit:
199259

200-
``` fortran
260+
```f90
201261
use mctc_io
202262
use mctc_env
203263
type(structure_type) :: mol
@@ -214,6 +274,120 @@ The [``mctc-convert``](man/mctc-convert.1.adoc) program provides a chained reade
214274
Checkout the implementation in [``app/main.f90``](app/main.f90).
215275

216276

277+
## Working with the Structure Type
278+
279+
The [``structure_type``](https://grimme-lab.github.io/mctc-lib/type/structure_type.html) is the central data structure for representing molecular systems:
280+
281+
```f90
282+
type(structure_type) :: mol
283+
284+
! Basic properties
285+
mol%nat ! Number of atoms
286+
mol%nid ! Number of unique species
287+
mol%charge ! Total molecular charge
288+
mol%uhf ! Number of unpaired electrons
289+
290+
! Atomic data (arrays)
291+
mol%xyz(:, :) ! Cartesian coordinates (3, nat) in Bohr
292+
mol%id(:) ! Species index for each atom (nat)
293+
mol%num(:) ! Atomic numbers for each species (nid)
294+
mol%sym(:) ! Element symbols for each species (nid)
295+
296+
! Periodic systems
297+
mol%lattice(:, :) ! Lattice vectors (3, 3) in Bohr
298+
mol%periodic(:) ! Periodic directions (3)
299+
300+
! Optional data
301+
mol%bond(:, :) ! Bond connectivity
302+
mol%comment ! Structure title/comment
303+
```
304+
305+
### Creating Structures Programmatically
306+
307+
All inputs use atomic units. Coordinates must be provided in Bohr (1 Bohr ≈ 0.529 Å).
308+
309+
```f90
310+
use mctc_io
311+
use mctc_env, only : wp
312+
implicit none
313+
type(structure_type) :: mol
314+
integer :: num(3)
315+
real(wp) :: xyz(3, 3)
316+
317+
! Water molecule (coordinates in Bohr)
318+
num = [8, 1, 1] ! O, H, H
319+
xyz = reshape([ &
320+
& 0.0_wp, 0.0_wp, 0.2372_wp, &
321+
& 0.0_wp, 1.4939_wp, -0.9487_wp, &
322+
& 0.0_wp, -1.4939_wp, -0.9487_wp], [3, 3])
323+
324+
call new(mol, num, xyz, charge=0.0_wp, uhf=0)
325+
```
326+
327+
328+
## Using Element Data
329+
330+
Access element-specific properties from the [``mctc_data``](https://grimme-lab.github.io/mctc-lib/module/mctc_data.html) module:
331+
332+
```f90
333+
use mctc_data
334+
use mctc_env, only : wp
335+
implicit none
336+
real(wp) :: radius
337+
338+
! Get covalent radius for carbon (atomic number 6)
339+
radius = get_covalent_rad(6)
340+
341+
! Available functions:
342+
! get_covalent_rad(num) - Covalent radii in Bohr
343+
! get_vdw_rad(num) - van der Waals radii in Bohr
344+
! get_atomic_rad(num) - Atomic radii in Bohr
345+
! get_pauling_en(num) - Pauling electronegativities
346+
```
347+
348+
349+
## Element Symbol Conversion
350+
351+
Convert between element symbols and atomic numbers:
352+
353+
```f90
354+
use mctc_io, only : to_number, to_symbol
355+
356+
integer :: num
357+
character(len=2) :: sym
358+
359+
num = to_number("C") ! Returns 6
360+
sym = to_symbol(6) ! Returns "C"
361+
```
362+
363+
364+
## Specifying File Formats
365+
366+
When the file extension is non-standard, use the ``filetype`` enumerator:
367+
368+
```f90
369+
use mctc_io
370+
371+
call read_structure(mol, "geometry.in", error, filetype%aims)
372+
call write_structure(mol, "output.dat", error, filetype%xyz)
373+
```
374+
375+
Available format identifiers:
376+
- ``filetype%xyz`` - xyz format
377+
- ``filetype%tmol`` - Turbomole coord
378+
- ``filetype%molfile`` - mol file
379+
- ``filetype%sdf`` - SDF format
380+
- ``filetype%vasp`` - VASP POSCAR
381+
- ``filetype%pdb`` - PDB format
382+
- ``filetype%gen`` - DFTB+ genFormat
383+
- ``filetype%gaussian`` - Gaussian external
384+
- ``filetype%qcschema`` - QCSchema JSON
385+
- ``filetype%cjson`` - Chemical JSON
386+
- ``filetype%pymatgen`` - Pymatgen JSON
387+
- ``filetype%aims`` - FHI-aims
388+
- ``filetype%qchem`` - Q-Chem
389+
390+
217391
## Error reporting
218392

219393
The geometry input readers try to be provide helpful error messages, no user should be left alone with an error message like *invalid input*.
@@ -272,6 +446,17 @@ Error: Conflicting lattice and cell groups
272446
We try to retain as much information as possible when displaying the error message to make it easy to fix the offending part in the input.
273447

274448

449+
## API Documentation
450+
451+
Full API documentation is available at [grimme-lab.github.io/mctc-lib](https://grimme-lab.github.io/mctc-lib).
452+
453+
Key modules:
454+
- [``mctc_io``](https://grimme-lab.github.io/mctc-lib/module/mctc_io.html) - Structure I/O (``read_structure``, ``write_structure``, ``structure_type``)
455+
- [``mctc_env``](https://grimme-lab.github.io/mctc-lib/module/mctc_env.html) - Environment utilities (``error_type``, ``wp`` working precision)
456+
- [``mctc_data``](https://grimme-lab.github.io/mctc-lib/module/mctc_data.html) - Element data (radii, electronegativities)
457+
- [``mctc_ncoord``](https://grimme-lab.github.io/mctc-lib/module/mctc_ncoord.html) - Coordination number evaluation
458+
459+
275460
## License
276461

277462
Licensed under the Apache License, Version 2.0 (the “License”);

doc/format-aims.md

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,48 @@
11
---
2-
title: FHI-aims geometry.in format
2+
title: FHI-aims Geometry Format
33
---
44

5+
## Overview
6+
7+
| Property | Value |
8+
|----------|-------|
9+
| File extension | (none, typically `geometry.in`) |
10+
| Coordinate units | Ångström |
11+
| Supports periodicity | Yes (via `lattice_vector`) |
12+
| Format hint | `aims` |
13+
514
## Specification
615

7-
Format used by FHI-aims program.
8-
Atoms are specified by ``atom`` or ``atom_frac`` keyword followed by three real numbers and an character identifier.
9-
Lattice parameters are given with the ``lattice_vector`` keyword followed by three real numbers.
16+
The FHI-aims geometry format is the native input format for the FHI-aims all-electron DFT code.
17+
18+
### Format Detection
1019

20+
The format is identified by:
21+
- Basename: `geometry.in` (case-insensitive)
22+
- Format specifier: `aims`
1123

12-
## Example
24+
### Keywords
1325

14-
Caffeine molecule in xyz format
26+
| Keyword | Description |
27+
|---------|-------------|
28+
| `atom` | Cartesian coordinates in Ångström |
29+
| `atom_frac` | Fractional coordinates (periodic systems) |
30+
| `lattice_vector` | Lattice vector (3 reals, one per line) |
1531

32+
### Atom Specification
33+
34+
```text
35+
atom x y z element
36+
atom_frac a b c element
1637
```
38+
39+
## Examples
40+
41+
### Molecular System
42+
43+
Caffeine molecule:
44+
45+
```text
1746
atom 1.07320000000000 0.04890000000000 -0.07570000000000 C
1847
atom 2.51370000000000 0.01260000000000 -0.07580000000000 N
1948
atom 3.35200000000000 1.09590000000000 -0.07530000000000 C
@@ -40,9 +69,11 @@ atom 4.40230000000000 -5.15920000000000 0.82840000000000 H
4069
atom 4.40020000000000 -5.16930000000000 -0.94780000000000 H
4170
```
4271

72+
### 3D Periodic System
73+
4374
Carbondioxide in FHI-aims format:
4475

45-
```
76+
```text
4677
atom 6.62447969041000 6.62412068645100 6.63464984519600 C
4778
atom 9.39832080661700 6.63600723231600 9.41199064870100 C
4879
atom 9.39627410479100 9.39525191972100 6.64954571641900 C
@@ -60,10 +91,9 @@ lattice_vector 0.00000000000000 5.68032472285798 0.0000000
6091
lattice_vector 0.00000000000000 0.00000000000000 5.68032472285798
6192
```
6293

63-
64-
## Missing Features
94+
## Limitations
6595

6696
The implementation of this format is (to our knowledge) feature-complete.
6797

68-
@Note Feel free to contribute support for missing features
69-
or bring missing features to our attention by opening an issue.
98+
@Note Feel free to bring missing features to our attention by opening an issue.
99+

doc/format-cjson.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,42 @@
11
---
2-
title: Chemical JSON
2+
title: Chemical JSON (cjson)
33
---
44

5+
## Overview
6+
7+
| Property | Value |
8+
|----------|-------|
9+
| File extensions | `.cjson`, `.json` |
10+
| Coordinate units | Ångström |
11+
| Supports periodicity | Yes (via `unit cell`) |
12+
| Supports bonds | Yes |
13+
| Format hint | `cjson` |
14+
15+
@Note Requires JSON support (jonquil dependency)
16+
517
## Specification
618

719
@Note [Reference](https://github.com/OpenChemistry/avogadrolibs/blob/master/avogadro/io/cjsonformat.cpp)
820

9-
Chemical JSON files are identified by the extension ``cjson`` or ``json`` 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.
21+
Chemical JSON is a JSON-based format developed for Avogadro 2.
22+
It provides a structured way to represent molecular data including geometry, bonds, and properties.
1123

24+
### Supported Fields
1225

13-
## Example
26+
| Field | Description |
27+
|-------|-------------|
28+
| `name` | Molecule name |
29+
| `atoms.elements.number` | Atomic numbers array |
30+
| `atoms.coords.3d` | Cartesian coordinates (Ångström) |
31+
| `atoms.coords.3dFractional` | Fractional coordinates |
32+
| `atoms.formalCharges` | Formal charges per atom |
33+
| `unitCell` | Unit cell parameters |
34+
| `bonds.connections.index` | Bond connectivity (pairs of atom indices) |
35+
| `bonds.order` | Bond orders |
1436

15-
Caffeine molecule in ``qcschema_molecule`` format.
37+
## Example
1638

39+
Caffeine molecule:
1740

1841
```json
1942
{
@@ -90,10 +113,11 @@ Caffeine molecule in ``qcschema_molecule`` format.
90113
}
91114
```
92115

116+
## Limitations
93117

94-
## Missing features
95-
96-
The schema is not verified on completeness and not all data is stored in the final structure type.
118+
- Schema completeness is not verified during reading
119+
- Not all Chemical JSON fields are preserved in the structure type
97120

98121
@Note Feel free to contribute support for missing features
99122
or bring missing features to our attention by opening an issue.
123+

0 commit comments

Comments
 (0)