|
| 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. |
0 commit comments