Skip to content

Commit 317869d

Browse files
committed
Merge branch 'main' into etot_add
2 parents 36e3765 + dd56aa1 commit 317869d

46 files changed

Lines changed: 5880 additions & 151 deletions

Some content is hidden

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

.github/workflows/docs.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Documentation
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
build-and-deploy:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.11'
24+
25+
- name: Install UV
26+
run: pip install uv
27+
28+
- name: Install dependencies
29+
run: |
30+
uv sync --group dev
31+
32+
- name: Build documentation
33+
run: |
34+
cd docs
35+
uv run jupyter book build .
36+
37+
- name: Deploy to GitHub Pages
38+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
39+
uses: peaceiris/actions-gh-pages@v4
40+
with:
41+
github_token: ${{ secrets.GITHUB_TOKEN }}
42+
publish_dir: ./docs/_build/html
43+
force_orphan: true

.github/workflows/test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0 # For setuptools-scm versioning
17+
18+
- name: Set up Python 3.10
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.10"
22+
23+
- name: Install UV
24+
run: pip install uv
25+
26+
- name: Install dependencies
27+
run: |
28+
uv sync --group dev
29+
30+
- name: Run tests
31+
run: |
32+
uv run pytest -v -m "not integration" --cov=dftio --cov-report=xml --cov-report=term
33+
34+
- name: Upload coverage to Codecov
35+
uses: codecov/codecov-action@v5
36+
with:
37+
file: ./coverage.xml
38+
flags: unittests
39+
name: codecov-umbrella
40+
fail_ci_if_error: false

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ instance/
6969

7070
# Sphinx documentation
7171
docs/_build/
72+
_build/
7273

7374
# PyBuilder
7475
.pybuilder/
@@ -100,6 +101,12 @@ ipython_config.py
100101
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
101102
#poetry.lock
102103

104+
# uv
105+
.python-version
106+
107+
# Version file auto-generated by setuptools-scm
108+
dftio/_version.py
109+
103110
# pdm
104111
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
105112
#pdm.lock

GEMINI.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# GEMINI.md: AI-Assisted Development Guide for `dftio`
2+
3+
This document provides context and instructions for an AI assistant to effectively contribute to the `dftio` project.
4+
5+
## Project Overview
6+
7+
`dftio` is a Python library designed to parse and process output files from various Density Functional Theory (DFT) software packages. Its primary goal is to convert complex DFT outputs into standardized, machine-learning-ready formats. The library supports packages such as ABACUS, VASP, SIESTA, Gaussian, RESCU, and PYATB.
8+
9+
The project provides a command-line interface (CLI) for parsing operations and for plotting derived data like electronic band structures.
10+
11+
**Key Technologies:**
12+
- **Language:** Python 3.9+
13+
- **Core Libraries:** NumPy, SciPy, PyTorch, ASE (Atomic Simulation Environment), sisl
14+
- **Package Management:** `uv`
15+
- **Testing:** `pytest`
16+
17+
## Building and Running
18+
19+
### Installation
20+
21+
The project uses `uv` for dependency management. To set up a development environment, including testing dependencies, run:
22+
23+
```bash
24+
# Install all dependencies, including development tools
25+
uv sync --group dev
26+
```
27+
This command installs packages defined in `pyproject.toml`.
28+
29+
### Running the CLI
30+
31+
The main entry point is the `dftio` command. It has several subcommands, with `parse` being the most central one.
32+
33+
**Example for parsing ABACUS output:**
34+
```bash
35+
dftio parse --mode abacus --root /path/to/abacus/output --hamiltonian --overlap -o /path/to/save
36+
```
37+
38+
For a full list of commands and options, use the help flag:
39+
```bash
40+
dftio --help
41+
dftio parse --help
42+
```
43+
44+
### Running Tests
45+
46+
The project uses `pytest` for testing. The standard test suite can be run with the following command, which excludes slower "integration" tests:
47+
48+
```bash
49+
uv run pytest -v -m "not integration"
50+
```
51+
52+
To run the full suite including code coverage analysis (as done in CI):
53+
```bash
54+
uv run pytest -v -m "not integration" --cov=dftio
55+
```
56+
57+
## Development Conventions
58+
59+
### Project Structure
60+
61+
- **`dftio/`**: Main source code for the library.
62+
- **`io/`**: Contains the parsing logic for different DFT packages. Each package (e.g., `abacus`, `siesta`) has its own submodule.
63+
- **`data/`**: Data structures for handling atomic configurations and computational results.
64+
- **`__main__.py`**: Defines the CLI entry point and its arguments.
65+
- **`test/`**: Contains all `pytest` tests. The structure mirrors the main `dftio/` directory.
66+
- **`docs/`**: Project documentation, built with Jupyter Book.
67+
- **`pyproject.toml`**: Defines project metadata, dependencies, and tool configurations (including `pytest`).
68+
69+
### Coding Style
70+
71+
Follow the existing coding style in the file you are editing. While no specific linter is enforced in the project configuration, adhere to standard PEP 8 conventions.
72+
73+
### Adding a New Parser
74+
75+
To add support for a new DFT package, you would typically:
76+
1. Create a new module under `dftio/io/`, e.g., `dftio/io/new_package/`.
77+
2. Implement a parser class within that module.
78+
3. Register the new parser in `dftio/io/parse.py`'s `ParserRegister` to make it available via the CLI.
79+
4. Add corresponding tests in the `test/` directory to validate the parser's correctness.

README.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,51 @@
11
# 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+
29
dftio is to assist machine learning communities in transcribing and manipulating DFT output into a format that is easy to read or used by machine learning models.
310

411
dftio uses multiprocessing to paralleling the processing, and provide a standard dataset class that reads the processed dataset directly.
512

613
## Installation
7-
The user can install dftio once located in the root directory, and run:
14+
15+
### Using the install script (Recommended)
16+
17+
The easiest way to install dftio is using the provided installation script:
18+
819
```bash
9-
pip install .
20+
# CPU version (default)
21+
./install.sh
22+
23+
# Or for GPU with CUDA 12.1
24+
./install.sh cu121
1025
```
11-
The dependent packages will be installed accordingly.
12-
However, the user can always manage the dependency themselves, here are the packages that dftio requires:
26+
27+
### Manual installation with UV
28+
29+
If you prefer manual installation:
30+
31+
```bash
32+
# Install UV if you haven't already
33+
pip install uv
34+
35+
# Install dftio (CPU version)
36+
uv sync
37+
38+
# Or for GPU version
39+
uv sync --find-links https://data.pyg.org/whl/torch-2.5.0+cu121.html
40+
```
41+
42+
### Using pip (from PyPI - coming soon)
43+
44+
```bash
45+
pip install dftio
46+
```
47+
48+
**Note**: dftio depends on `torch-scatter` which requires special handling. The install script automatically manages this for you.
1349

1450
## Supports
1551

dftio/op/grid_int.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def __init__(self, atomic_numbers, pbc, cell, coordinates, grids, atomic_basis,
3434
def integrate(self, weights=None):
3535

3636
ngrid = len(self.grids)
37-
results = torch.zeros(ngrid, dtype=weights.dtype)
37+
dtype = weights.dtype if weights is not None else self.dtype
38+
results = torch.zeros(ngrid, dtype=dtype)
3839
norbs = [self.atomic_basis[atomic_numbers_r[int(i)]].irreps.dim for i in self.atomic_numbers]
3940
cnorbs = torch.cumsum(torch.tensor([0]+norbs), dim=0)[:-1]
4041
for element in self.atomic_basis:

docs/_config.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Jupyter Book Configuration
2+
# Learn more at https://jupyterbook.org/customize/config.html
3+
4+
title: dftio Documentation
5+
author: dftio Team
6+
copyright: "2025"
7+
logo: ""
8+
9+
# Force re-execution of notebooks on each build
10+
execute:
11+
execute_notebooks: auto
12+
timeout: 600
13+
14+
# Define the name of the latex output file for PDF builds
15+
latex:
16+
latex_documents:
17+
targetname: dftio.tex
18+
19+
# Add a bibtex file so that we can create citations
20+
bibtex_bibfiles:
21+
- references.bib
22+
23+
# Information about where the book exists on the web
24+
repository:
25+
url: https://github.com/deepmodeling/dftio
26+
path_to_book: docs
27+
branch: main
28+
29+
# Add GitHub buttons to your book
30+
html:
31+
use_issues_button: true
32+
use_repository_button: true
33+
use_edit_page_button: true
34+
35+
# Sphinx configuration
36+
sphinx:
37+
extra_extensions:
38+
- sphinx.ext.autodoc
39+
- sphinx.ext.napoleon
40+
- sphinx.ext.viewcode
41+
- sphinx_autodoc_typehints
42+
config:
43+
html_theme: sphinx_book_theme
44+
autodoc_typehints: description

docs/_toc.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Table of Contents for dftio Documentation
2+
3+
format: jb-book
4+
root: index
5+
chapters:
6+
- file: installation
7+
- file: user-guide/index
8+
sections:
9+
- file: user-guide/quickstart
10+
- file: user-guide/parsing
11+
- file: user-guide/data-formats
12+
- file: user-guide/cli-reference
13+
- file: user-guide/supported_packages
14+
- file: tutorials/index
15+
sections:
16+
- file: tutorials/plot_bands
17+
- file: api/index
18+
sections:
19+
- file: api/io
20+
- file: api/data
21+
- file: developer-guide
22+
- file: contributing

docs/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+
```

docs/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.

0 commit comments

Comments
 (0)