Skip to content

Commit facba90

Browse files
committed
deploy: c9d128f
0 parents  commit facba90

187 files changed

Lines changed: 32646 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.buildinfo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sphinx build info version 1
2+
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3+
config: 3a88eb33a9143260534ed02dfb7830fc
4+
tags: 645f666f9bcd5a90fca523b33c5a78b7

.nojekyll

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Yinzhanghao Zhou
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

_sources/api/data.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Data Structures (`dftio.data`)
2+
3+
The `dftio.data` module provides the fundamental data structures for storing and managing atomic information and computational results. These structures are designed to be flexible, efficient, and compatible with machine learning workflows.
4+
5+
## `AtomicData`
6+
7+
The `dftio.data.AtomicData` class is the primary container for data associated with a single atomic structure. It is a dictionary-like object that stores properties of the system, such as atomic numbers, positions, and cell parameters, as PyTorch tensors.
8+
9+
### Key Features
10+
11+
- **Tensor-Based:** All data is stored as `torch.Tensor` objects, enabling seamless integration with PyTorch and other machine learning libraries.
12+
- **Extensible:** You can add any custom data to an `AtomicData` object, allowing for flexible and detailed representations of your system.
13+
- **Property-Based Access:** Accessing a key on an `AtomicData` object (e.g., `data['positions']`) returns the corresponding tensor.
14+
15+
### Core Properties
16+
17+
The following are some of the standard keys defined in `dftio.data._keys`:
18+
19+
- `cell`: The lattice vectors of the simulation cell.
20+
- `positions`: The coordinates of each atom.
21+
- `atomic_numbers`: The atomic number of each atom.
22+
- `pbc` (Periodic Boundary Conditions): A boolean tensor indicating which directions are periodic.
23+
- `eigs`: The eigenvalues of the electronic structure.
24+
- `kpoints`: The coordinates of the k-points.
25+
26+
## `AtomicDataDict`
27+
28+
The `dftio.data.AtomicDataDict` class is a specialized dictionary designed to hold multiple `AtomicData` objects. It is the primary data structure returned by the parsers when processing multiple frames or structures.
29+
30+
### Key Features
31+
32+
- **Batching:** Provides methods for collating multiple `AtomicData` objects into a single batch for efficient processing.
33+
- **Transformation Support:** Can be used with the `dftio.data.transforms` module to apply transformations to all `AtomicData` objects in the dictionary.
34+
- **Serialization:** Can be saved to and loaded from disk, typically in `.dat` files (PyTorch's serialization format).
35+
36+
## Example Usage
37+
38+
```python
39+
import torch
40+
from dftio.data import AtomicData
41+
42+
# Create an AtomicData object for a simple system
43+
data = AtomicData(
44+
positions=torch.tensor([[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]]),
45+
atomic_numbers=torch.tensor([14, 14]), # Silicon
46+
cell=torch.eye(3) * 5.43,
47+
pbc=torch.tensor([True, True, True]),
48+
)
49+
50+
# Access properties
51+
print(data.positions)
52+
print(data.cell)
53+
```

_sources/api/index.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# API Reference
2+
3+
This section provides detailed, auto-generated documentation for the `dftio` Python API. Use this reference to understand the internal components, data structures, and parser implementations.
4+
5+
The API is organized into several key modules:
6+
7+
- **[I/O and Parsers (`dftio.io`)](./io.md):** The core parsing engine, including the abstract base parser and specific implementations for each supported DFT code.
8+
9+
- **[Data Structures (`dftio.data`)](./data.md):** The internal data containers used to store and manage atomic structures and calculation results.
10+
11+
For details on how to use these components, please refer to the pages linked above.

_sources/api/io.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# I/O and Parsers (`dftio.io`)
2+
3+
The `dftio.io` module is the core of the library's parsing capabilities. It contains the `ParserRegister` class, which manages the registration and selection of parsers for different DFT codes, as well as the implementations of the parsers themselves.
4+
5+
## `ParserRegister`
6+
7+
The `ParserRegister` class is a singleton that holds a registry of all available parsers. When you run `dftio parse` from the command line, this class is responsible for selecting the appropriate parser based on the `--mode` argument.
8+
9+
### Key Methods
10+
11+
- **`register(name, parser_cls)`:** Adds a new parser to the registry.
12+
- **`get_parser(name)`:** Retrieves a parser class from the registry by name.
13+
14+
## Available Parsers
15+
16+
`dftio` supports the following DFT codes. Each parser is implemented in its own submodule within `dftio.io`.
17+
18+
- **ABACUS (`abacus`):** Parses output from the ABACUS DFT code. See `dftio.io.abacus.abacus_parser`.
19+
- **Gaussian (`gaussian`):** Parses output from the Gaussian quantum chemistry software. See `dftio.io.gaussian.gaussian_parser`.
20+
- **PYATB (`pyatb`):** Parses output from the PYATB library. See `dftio.io.pyatb.pyatb_parser`.
21+
- **RESCU (`rescu`):** Parses output from the RESCU DFT code. See `dftio.io.rescu.rescu_parser`.
22+
- **SIESTA (`siesta`):** Parses output from the SIESTA DFT code. See `dftio.io.siesta.siesta_parser`.
23+
- **VASP (`vasp`):** Parses output from the Vienna Ab initio Simulation Package (VASP). See `dftio.io.vasp.vasp_parser`.
24+
25+
Below is a more detailed breakdown of each parser's functionality.
26+
27+
### ABACUS Parser
28+
29+
The ABACUS parser (`dftio.io.abacus.AbacusParser`) is designed to handle the output files generated by the ABACUS software.
30+
31+
**Key Responsibilities:**
32+
33+
- Parses atomic structures (`STRU` files).
34+
- Extracts Hamiltonian and overlap matrices from sparse matrix files (`data-HR-sparse_SPIN0.csr`, `data-SR-sparse_SPIN0.csr`).
35+
- Reads band structure data from `BANDS_1.dat`.
36+
- Extracts other information from the main log file (`running_scf.log`).
37+
38+
### Gaussian Parser
39+
40+
The Gaussian parser (`dftio.io.gaussian.GaussianParser`) processes `.log` files from Gaussian calculations.
41+
42+
**Key Responsibilities:**
43+
44+
- Extracts atomic structures and coordinates.
45+
- Parses basis set information.
46+
- Reads molecular orbital energies (eigenvalues).
47+
48+
### VASP Parser
49+
50+
The VASP parser (`dftio.io.vasp.VaspParser`) is responsible for parsing the various output files from VASP.
51+
52+
**Key Responsibilities:**
53+
54+
- Reads atomic positions from `POSCAR` or `CONTCAR`.
55+
- Parses eigenvalues from `EIGENVAL`.
56+
- Extracts k-points and weights from `KPOINTS`.
57+
- Gathers additional information from `OUTCAR`, such as lattice parameters and forces.

_sources/contributing.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Contributing to dftio
2+
3+
Thank you for your interest in contributing to dftio! We welcome contributions of all kinds, from bug fixes to new features.
4+
5+
## Development Setup
6+
7+
1. **Clone the repository:**
8+
```bash
9+
git clone https://github.com/deepmodeling/dftio.git
10+
cd dftio
11+
```
12+
13+
2. **Install dependencies:**
14+
This project uses `uv` for package management. To install all required dependencies, including those for development and testing, run:
15+
```bash
16+
uv sync --group dev
17+
```
18+
19+
3. **Run tests:**
20+
To make sure everything is set up correctly, run the test suite:
21+
```bash
22+
uv run pytest -m "not integration"
23+
```
24+
25+
## Code Style
26+
27+
- Follow PEP 8 guidelines for Python code.
28+
- Use clear and meaningful names for variables, functions, and classes.
29+
- Add docstrings to all public functions and classes, explaining their purpose, arguments, and return values.
30+
31+
## Testing
32+
33+
- All new features and bug fixes should be accompanied by tests.
34+
- Ensure that the full test suite passes before submitting a pull request.
35+
- Use `pytest` markers (e.g., `@pytest.mark.integration`) for tests that are slow or require external resources.
36+
37+
## Pull Request Process
38+
39+
1. Fork the repository on GitHub.
40+
2. Create a new feature branch from the `main` branch.
41+
3. Make your changes in the new branch.
42+
4. Add or update tests as needed.
43+
5. Run the tests to ensure everything passes.
44+
6. Submit a pull request to the `main` branch of the original repository.
45+
46+
## Implementing a New Parser
47+
48+
If you are adding support for a new DFT package, please see the [Developer Guide](developer-guide.md) for a general overview. When implementing the parser class, you will need to provide several key methods. Below are the details of what each method should return.
49+
50+
### `get_structure(idx)`
51+
52+
This method should return a dictionary containing the atomic structure for the `idx`-th calculation. The dictionary should have the following keys (defined in `dftio.data._keys`):
53+
54+
- `_keys.ATOMIC_NUMBERS_KEY`: Atomic numbers as a 1D tensor (`[natom]`).
55+
- `_keys.PBC_KEY`: Periodic boundary conditions as a boolean tensor (`[3]`).
56+
- `_keys.POSITIONS_KEY`: Atomic positions in Ångströms (`[nframe, natom, 3]`).
57+
- `_keys.CELL_KEY`: Lattice vectors in Ångströms (`[nframe, 3, 3]`).
58+
59+
### `get_eigenvalues(idx)`
60+
61+
This method should return a dictionary containing the eigenvalues and k-points:
62+
63+
- `_keys.KPOINT_KEY`: K-point coordinates (`[nk, 3]`).
64+
- `_keys.ENERGY_EIGENVALUE_KEY`: Eigenvalues (`[nframe, nk, nband]`).
65+
66+
### `get_basis(idx)`
67+
68+
This method should return a dictionary describing the basis set, for example: `{"Si": "2s2p1d"}`.
69+
70+
### `get_blocks(idx, ...)`
71+
72+
This method should parse the real-space Hamiltonian, overlap, and/or density matrices. It should return a tuple of three lists: `(hamiltonians, overlaps, density_matrices)`. Each list should contain one dictionary per frame, where each dictionary's keys are strings like `"i_j_Rx_Ry_Rz"` (representing the matrix element between orbital `i` and orbital `j` in a neighboring cell at `(Rx, Ry, Rz)`) and the values are the corresponding matrix blocks as NumPy arrays.

_sources/developer-guide.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Developer Guide
2+
3+
This guide is for developers who want to contribute to `dftio` by adding support for a new Density Functional Theory (DFT) software package.
4+
5+
## Project Structure
6+
7+
The core logic of `dftio` is organized into several key modules:
8+
9+
- **`dftio.data`**: Contains the fundamental data structures, such as `AtomicData` and `AtomicDataDict`, which are used to store and manage atomic information in a standardized format compatible with machine learning workflows.
10+
11+
- **`dftio.datastruct`**: Defines data structures for physical quantities like Hamiltonian matrices, overlap matrices, and fields.
12+
13+
- **`dftio.io`**: This is the I/O module, containing the interfaces to all supported DFT packages. Each package has its own submodule (e.g., `dftio.io.abacus`).
14+
15+
## How to Add a New Parser
16+
17+
Adding support for a new DFT code involves creating a new parser class and registering it with `dftio`. Here is a step-by-step guide:
18+
19+
### 1. Create a New Parser Module
20+
21+
Create a new directory under `dftio/io/` for your DFT package. For example, if you are adding a parser for a package named "NEWCODE," you would create the directory `dftio/io/newcode/`.
22+
23+
Inside this directory, create a Python file for your parser, e.g., `dftio/io/newcode/newcode_parser.py`.
24+
25+
### 2. Implement the Parser Class
26+
27+
In your new parser file, you will need to create a parser class that inherits from a base class (if one is available) or implements the necessary parsing methods. The key methods your parser will need to provide are:
28+
29+
- **`get_structure(idx)`**: This method should read the atomic structure information (atomic numbers, positions, cell, etc.) for a given calculation index (`idx`). It should return a dictionary of this data.
30+
31+
- **`get_eigenvalue(idx)`**: This method should parse the eigenvalues and k-points from the DFT output files.
32+
33+
- **`get_basis(idx)`**: This method should return information about the basis set used in the calculation.
34+
35+
- **`get_blocks(idx, hamiltonian, overlap, density_matrix)`**: This method is responsible for parsing the Hamiltonian, overlap, and/or density matrices.
36+
37+
### 3. Register Your Parser
38+
39+
To make your new parser available through the CLI and the `ParserRegister`, you need to add it to the registry in `dftio/io/parse.py`. Import your new parser class and add it to the `ParserRegister`.
40+
41+
```python
42+
# In dftio/io/parse.py
43+
from dftio.io.newcode.newcode_parser import NewCodeParser
44+
45+
# ...
46+
47+
ParserRegister.register("newcode", NewCodeParser)
48+
```
49+
50+
### 4. Add a Test Case
51+
52+
To ensure your parser works correctly and to prevent future regressions, you should add a new test file in the `test/` directory. You will need to include example output files from your DFT code in the `test/data/` directory.
53+
54+
## Supported DFT Software
55+
56+
`dftio` currently has parsers for the following DFT packages:
57+
58+
- ABACUS
59+
- Gaussian
60+
- PYATB
61+
- RESCU
62+
- SIESTA
63+
- VASP

_sources/index.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Welcome to dftio
2+
3+
[![Documentation](https://img.shields.io/badge/docs-latest-brightgreen.svg)](https://deepmodeling.github.io/dftio/)
4+
[![Tests](https://github.com/deepmodeling/dftio/workflows/Tests/badge.svg)](https://github.com/deepmodeling/dftio/actions/workflows/test.yml)
5+
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](../LICENSE)
6+
[![Python](https://img.shields.io/badge/python-3.10-blue)](https://www.python.org/downloads/)
7+
8+
`dftio` is a Python library designed to assist the machine learning community by transcribing and manipulating output from Density Functional Theory (DFT) calculations into formats that are easy to read and use with machine learning models.
9+
10+
It leverages multiprocessing to parallelize data processing and provides a standardized dataset class for direct use.
11+
12+
**Key Features:**
13+
14+
- **Broad Compatibility:** Parses output from a wide range of DFT software, including ABACUS, VASP, SIESTA, Gaussian, and more.
15+
- **Efficient I/O:** Uses multiprocessing to accelerate parsing of large datasets.
16+
- **Standardized Data:** Converts varied DFT outputs into consistent data structures.
17+
- **Flexible Output:** Saves processed data in multiple formats like `.dat`, `ase`, or `lmdb`.
18+
- **Command-Line Interface:** Provides a powerful CLI for easy automation and scripting.
19+
20+
This documentation will guide you through installing `dftio`, using its features, and contributing to its development.

_sources/installation.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Installation
2+
3+
There are several ways to install `dftio`. The recommended method is to use the provided install script, which handles all dependencies automatically.
4+
5+
## Using the Install Script (Recommended)
6+
7+
The easiest way to install `dftio` is by running the `install.sh` script in the root of the repository.
8+
9+
```bash
10+
# For a standard CPU-only installation
11+
./install.sh
12+
13+
# If you have a CUDA-compatible GPU (e.g., CUDA 12.1)
14+
./install.sh cu121
15+
```
16+
17+
This script ensures that all dependencies, including specific versions of PyTorch and `torch-scatter`, are installed correctly.
18+
19+
## Manual Installation with UV
20+
21+
If you prefer to manage the installation yourself, you can use `uv`.
22+
23+
1. **Install uv:**
24+
If you don't have `uv`, install it via pip:
25+
```bash
26+
pip install uv
27+
```
28+
29+
2. **Sync Dependencies:**
30+
Use `uv sync` to install the required packages from `pyproject.toml`.
31+
32+
```bash
33+
# For a CPU-only installation
34+
uv sync --group dev
35+
36+
# For a GPU installation (e.g., CUDA 12.1), specify the PyTorch find-links URL
37+
uv sync --group dev --find-links https://data.pyg.org/whl/torch-2.5.0+cu121.html
38+
```
39+
Including the `--group dev` flag will also install the packages required for testing and building documentation.
40+
41+
## Using pip (from PyPI)
42+
43+
*Coming soon. Once `dftio` is published to the Python Package Index (PyPI), you will be able to install it directly with `pip`.*
44+
45+
```bash
46+
# This will be enabled in a future release
47+
# pip install dftio
48+
```

0 commit comments

Comments
 (0)