This document provides guidance for AI agents and contributors working with the mctc-lib codebase.
mctc-lib (Modular Computation Tool Chain Library) is a Fortran library providing unified molecular structure data handling and geometry file format I/O for computational chemistry applications.
The library supports reading and writing 12+ geometry formats:
General ASCII formats:
- xyz - Xmol/xyz files (
.xyz,.log) - pdb - Protein Data Bank format (
.pdb) - mol/sdf - MDL connection table files (
.mol,.sdf)
JSON-based formats:
- QCSchema - MolSSI QCSchema JSON (
.qcjson,.json) - Chemical JSON - Avogadro Chemical JSON (
.cjson,.json) - Pymatgen JSON - Pymatgen Molecule/Structure (
.pmgjson,.json)
Program-specific formats:
- Turbomole coord - Turbomole/riper coordinates (
.tmol,.coord) - VASP POSCAR - VASP geometry files (
.vasp,.poscar,.contcar) - DFTB+ gen - DFTB+ genFormat (
.gen) - Gaussian external - Gaussian external program input (
.ein) - FHI-aims - FHI-aims geometry input (
geometry.in) - Q-Chem - Q-Chem molecule block (
.qchem)
mctc-lib/
├── src/mctc/ # Main library source code
│ ├── io/ # I/O module (readers/writers for all formats)
│ │ ├── read/ # Format-specific readers
│ │ └── write/ # Format-specific writers
│ ├── env/ # Environment module (error handling, testing)
│ ├── data/ # Element data (radii, electronegativities)
│ └── ncoord/ # Coordination number utilities
├── app/ # Application code (mctc-convert tool)
├── test/ # Unit test suite
├── doc/ # FORD documentation pages (format descriptions)
├── man/ # Manual pages (asciidoc format)
├── include/ # Public include files
├── config/ # Build configuration scripts
└── subprojects/ # Meson wrap dependencies (jonquil, toml-f, test-drive)
This project supports three build systems. Choose based on your workflow:
# Configure
meson setup _build
# Build
meson compile -C _build
# Test
meson test -C _build --print-errorlogs
# Install
meson install -C _buildNote: Meson version 1.8.0 has a known bug and is explicitly unsupported. Use any other version ≥ 0.55.
# Configure
cmake -B _build -G Ninja
# Build
cmake --build _build
# Test
cd _build && ctest && cd ..# Build
fpm build
# Test
fpm test
# Run application
fpm run -- --help- jonquil (v0.3.0 or later) - JSON parsing (optional, enables JSON format support)
- toml-f (v0.4.3 or later) - TOML parsing (dependency of jonquil)
- test-drive - Testing framework (test dependency only)
Dependencies are managed via Meson subprojects (wrap files), CMake find modules, or fpm.
Tests are organized by functionality in test/:
test_read_*.f90- Reader tests for each formattest_write_*.f90- Writer tests for each formattest_math.f90- Mathematical utility teststest_ncoord.f90- Coordination number teststest_symbols.f90- Element symbol conversion tests
# Run all tests with meson
meson test -C _build --print-errorlogs --suite mctc-lib
# Run specific test
meson test -C _build test_read_xyz --print-errorlogsTests use the mctc_env_testing module:
use mctc_env_testing, only : new_unittest, unittest_type, error_type, check
subroutine collect_my_tests(testsuite)
type(unittest_type), allocatable, intent(out) :: testsuite(:)
testsuite = [ &
& new_unittest("test-name", test_procedure), &
& new_unittest("expected-fail", test_fail, should_fail=.true.) &
]
end subroutine- Use Fortran 2008 standard features
- Free-form source format (
.f90,.F90for preprocessed) - Module names:
mctc_<subsystem>_<component>(e.g.,mctc_io_read) - Private by default, explicitly export public entities
- Use
implicit nonein all program units
All source files must include the Apache-2.0 license header:
! This file is part of mctc-lib.
!
! Licensed under the Apache License, Version 2.0 (the "License");
! ...Use the error_type for error propagation:
use mctc_env, only : error_type, fatal_error
subroutine my_routine(result, error)
type(error_type), allocatable, intent(out) :: error
if (some_error_condition) then
call fatal_error(error, "Descriptive error message")
return
end if
end subroutine- Use FORD-compatible docstrings (
!>for preceding,!<for trailing) - Document all public interfaces
- Run
ford docs.mdto generate documentation
The CI pipeline (.github/workflows/build.yml) runs on push and pull requests:
- Platforms: Ubuntu, macOS
- Compilers: GCC (10, 11, 12, 14), Intel oneAPI (2021)
- Build systems: Meson, CMake, fpm
- Coverage: Collected with GCC 11 and uploaded to Codecov
Contributions require sign-off. The DCO bot checks all commits. Sign your commits:
git commit -s -m "Your commit message"Documentation is built with FORD and deployed to GitHub Pages on:
- Pushes to
mainbranch - Tagged releases
- Create reader in
src/mctc/io/read/(e.g.,format.f90) - Create writer in
src/mctc/io/write/(e.g.,format.f90) - Add filetype enum in
src/mctc/io/filetype.f90 - Register in
src/mctc/io/read.f90andsrc/mctc/io/write.f90 - Update meson.build and CMakeLists.txt in relevant directories
- Add tests in
test/test_read_format.f90andtest/test_write_format.f90 - Document in
doc/format-<name>.md
structure_type(mctc_io_structure) - Main molecular structure containererror_type(mctc_env) - Error handling type
# Using the mctc-convert tool
meson compile -C _build
./_build/app/mctc-convert input.xyz output.moluse mctc_io
use mctc_env
type(structure_type) :: mol
type(error_type), allocatable :: error
call read_structure(mol, "input.xyz", error)
if (allocated(error)) then
print '(a)', error%message
error stop
end if| Option | Type | Default | Description |
|---|---|---|---|
openmp |
boolean | false | Enable OpenMP parallelization |
json |
feature | auto | Enable JSON format support |
meson setup _build -Djson=enabled -Dopenmp=true| Option | Description |
|---|---|
WITH_JSON |
Enable JSON support |
WITH_OpenMP |
Enable OpenMP |
-
Meson 1.8.0 error: Upgrade or downgrade meson (
pip install meson!=1.8.0) -
JSON tests fail: Ensure jonquil dependency is available or disable with
-Djson=disabled -
Missing Fortran compiler: Set
FCenvironment variable:FC=gfortran meson setup _build
- Fork the repository
- Create a feature branch
- Make changes following the code style guidelines
- Add tests for new functionality
- Ensure all tests pass
- Sign off commits (DCO requirement)
- Submit a pull request
Error messages in mctc-lib are designed to be helpful with source location information. If you encounter unclear error messages, please report them as bugs.