Skip to content

Commit 75e3b06

Browse files
update input and e3tb hands on doc (#240)
* update input and e3tb hands on doc * Update argcheck.py --------- Co-authored-by: QG-phy <guqq_phy@qq.com> Co-authored-by: Qiangqiang Gu <98570179+QG-phy@users.noreply.github.com>
1 parent 767d51f commit 75e3b06

File tree

6 files changed

+62
-47
lines changed

6 files changed

+62
-47
lines changed

docs/advanced/e3tb/advanced_input.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ In [7]: idp.get_irreps_ess()
8686
Out[7]: 7x0e+6x1o+6x2e+2x3o+1x4e
8787
```
8888

89+
Rules for the irreps setting:
90+
First, we should check the largest angular momentum defined in the DFT LCAO basis, and then double it as our highest order of irreps (since the addition rule of the angular momentum). For example, for `1s1p` basis, the irreps should contain features with angular momentum from 0 to 2, which is 2 times 1, the angular momentum of `p` orbital. If the basis contains `d` orbital, then the irreps should contain angular momentum up to 4. `f` and `g` or even higher orbitals are also supported.
91+
8992
`n_layers`: indicates the number of layers of the networks.
9093

9194
`env_embed_multiplicity`: decide the irreps number when initializing the edge and node features.

docs/quick_start/hands_on/e3tb_hands_on.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
DeePTB supports training an E3-equalvariant model to predict DFT Hamiltonian, density and overlap matrix under LCAO basis. Here, cubic-phase bulk silicon has been chosen as a quick start example.
44

5-
Silicon is a chemical element; it has the symbol Si and atomic number 14. It is a hard, brittle crystalline solid with a blue-grey metallic lustre, and is a tetravalent metalloid and semiconductor. The prepared files are located in:
5+
Silicon is a chemical element; it has the symbol Si and atomic number 14. It is a hard, brittle crystalline solid with a blue-grey metallic lustre, and is a tetravalent metalloid and semiconductor (Shut up). The prepared files are located in:
66

77
```
88
deeptb/examples/e3/
@@ -19,16 +19,13 @@ deeptb/examples/e3/
1919
| `-- info.json
2020
`-- input.json
2121
```
22-
We prepared one frame of silicon cubic bulk structure as an example. The data was computed using DFT software ABACUS, with an LCAO basis set containing 1 `s` and 1 `p` orbital. The cutoff radius for the orbital is 7au, which means the largest bond would be less than 14 au. Therefore, the r_max should be set as 7.4. So we have an info.json file like:
22+
We prepared one frame of silicon cubic bulk structure as an example. The data was computed using DFT software ABACUS, with an LCAO basis set containing 1 `s` and 1 `p` orbital. We now have an info.json file like:
2323

24-
```json
24+
```JSON
2525
{
2626
"nframes": 1,
2727
"pos_type": "cart",
28-
"AtomicData_options": {
29-
"r_max": 7.4,
30-
"pbc": true
31-
}
28+
"pbc": true, # same as [true, true, true]
3229
}
3330
```
3431

@@ -42,7 +39,7 @@ The `input_short.json` file contains the least number of parameters that are req
4239
"overlap": true
4340
}
4441
```
45-
In `common_options`, here are the essential parameters. The `basis` should align with the DFT calculation, so 1 `s` and 1 `p` orbital would result in a `1s1p` basis. The `device` can either be `cpu` or `cuda`, but we highly recommend using `cuda` if GPU is available. The `overlap` tag controls whether to fit the overlap matrix together. Benefitting from our parameterization, the fitting overlap only brings negelectable costs, but would boost the convenience when using the model.
42+
In `common_options`, here are the essential parameters. The `basis` should align with the DFT calculation, so 1 `s` and 1 `p` orbital would result in a `1s1p` basis. The cutoff radius for the orbital is 7au, which means the largest bond would be less than 14 au. Therefore, the `r_max`, which equals to the maximum bond length, should be set as 7.4. The `device` can either be `cpu` or `cuda`, but we highly recommend using `cuda` if GPU is available. The `overlap` tag controls whether to fit the overlap matrix together. Benefitting from our parameterization, the fitting overlap only brings negligible costs, but is very convenient when using the model.
4643

4744
Here comes the `model_options`:
4845
```json
@@ -67,16 +64,26 @@ The `model_options` contains `embedding` and `prediction` parts, denoting the co
6764

6865
In `embedding`, the `method` supports `slem` and `lem` for now, where `slem` has a strictly localized dependency, which has better transferability and data efficiency, while `lem` has an adjustable semi-local dependency, which has better representation capacity, but would require a little more data. `r_max` should align with the one defined in `info.json`.
6966

70-
For `irreps_hidden`, this parameter defines the size of the hidden equivariant irreducible representation, which is highly related to the power of the model. There are certain rules to define this param. First, we should check the largest angular momentum defined in the DFT LCAO basis, the irreps's highest angular momentum should always be double. For example, for `1s1p` basis, the irreps should contain features with angular momentum from 0 to 2, which is 2 times 1, the angular momentum of `p` orbital. If the basis contains `d` orbital, then the irreps should contain angular momentum up to 4. `f` and `g` or even higher orbitals are also supported.
67+
For `irreps_hidden`, this parameter defines the size of the hidden equivariant irreducible representation, which decides most of the power of the model. There are certain rules to define this param. But for quick usage, we provide a tool to do basis analysis to extract essential irreps.
68+
69+
```IPYTHON
70+
In [1]: from dptb.data import OrbitalMapper
71+
72+
In [2]: idp = OrbitalMapper(basis={"Si": "1s1p"})
73+
74+
In [3]: idp.get_irreps_ess()
75+
Out[3]: 2x0e+1x1o+1x2e
76+
```
7177

72-
In `prediction`, we should use the `e3tb` method to let the model know the output features are arranged in **DeePTB-E3** format. The neurons are defined for a simple MLP to predict the slater-koster-like parameters for predicting the overlap matrix, for which [64,64] is usually fine.
78+
This is the number of independent irreps contains in the basis. Irreps configured should be multiple times of this essential irreps. The number can varies with a pretty large freedom, but the all the types, for example ("0e", "1o", "2e") here, should be included for all. We usually take a descending order starts from "32", "64", or "128" for the first "0e" and decay by half for latter high order irreps. For general rules of the irreps, user can read the advance topics in the doc, but for now, you are safe to ignore!
7379

80+
In `prediction`, we should use the `e3tb` method to require the model output features using **DeePTB-E3** format. The neurons are defined for a simple MLP to predict the slater-koster-like parameters for predicting the overlap matrix, for which [64,64] is usually fine.
7481

7582
Now everything is prepared! We can using the following command and we can train the first model:
7683

7784
```bash
7885
cd deeptb/examples/e3
79-
dptb train ./input/input_short.json -o ./e3_silicon
86+
dptb train ./input_short.json -o ./e3_silicon
8087
```
8188

8289
Here ``-o`` indicate the output directory. During the fitting procedure, we can see the loss curve of hBN is decrease consistently. When finished, we get the fitting results in folders ```e3_silicon```.
@@ -87,9 +94,9 @@ python plot_band.py
8794
```
8895
or just using the command line
8996
```bash
90-
dptb run ./run/band.json -i ./e3_silicon/checkpoint/nnenv.best.pth -o ./band_plot
97+
dptb run ./band.json -i ./e3_silicon/checkpoint/nnenv.best.pth -o ./band_plot
9198
```
9299

93100
![band_e3_Si](https://raw.githubusercontent.com/deepmodeling/DeePTB/main/docs/img/silicon_e3_band.png)
94101

95-
Now you know how to train a **DeePTB-E3** model for Hamiltonian and overlap matrix. For better usage, we encourage the user to read the full input parameters for the **DeePTB-E3** model. Also, the **DeePTB** model supports several post-process tools, and the user can directly extract any predicted properties just using a few lines of code. Please see the basis_api for details.
102+
Now you know how to train a **DeePTB-E3** model for Hamiltonian and overlap matrix. For better usage, we encourage the user to read the full input parameters for the **DeePTB-E3** model. Also, the **DeePTB** model supports several post-process tools, and the user can directly extract any predicted properties just using a few lines of code. Please see the basis_api for details.

docs/quick_start/input.md

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,56 @@ The following files are the central input files for DeePTB. Before executing the
44

55
## Inputs
66
### Data
7-
The dataset files contrains both the **atomic structure** and the **training label** information.
7+
The dataset files contrains both the **atomic structure** and the **training label** information.
88

9-
The atomic structure should be prepared as a ASE trajectory binary file, where each structure is stored using an **Atom** class defined in ASE package. The provided trajectory file must have suffix `.traj` and the length of the trajectory is `nframes`. For labels, we currently support `eigenvalues`, `Hamiltonian`, `density matrix` and `overlap matrix`.
9+
The **atomic structure** contains the atoms' position, unit-cell vector and atomic number vector. They **must** be included in your datafile in all task.
10+
The **training labels** are prepared dependent on each task. If you are working on `DeePTB-SK` mode, the eigenvalues and kpoints are needed. If you are working with `DeePTB-E3` mode the Hamiltonian/Density Matrix under LCAO basis must be provided, while overlap matrix are optionally provided (But we suggest to do so for convenience).
1011

12+
The atomic structure should be prepared in either ASE trajectory binary file format, or the plain text format. We highly suggest to use the tool `dftio` to deal with the data preparation. It can transform the data from DFT output to the target format automatically. Herefore completion, we will introduce the format of each type.
1113

12-
For training a **DeePTB-SK** model, we need to prepare the `eigenvalues` label, which contrains the `eigenvalues.npy` and `kpoints.npy`. A typical dataset of **DeePTB-SK** task looks like:
14+
- For ASE trajectory binary file, each structure is stored using an **Atom** class defined in ASE package. The provided trajectory file must have suffix `.traj` and the length of the trajectory is `nframes`
1315

14-
```
15-
data/
16-
-- set.x
17-
-- -- eigenvalues.npy # numpy array of fixed shape [nframes, nkpoints, nbands]
18-
-- -- kpoints.npy # numpy array of fixed shape [nkpoints, 3]
19-
-- -- xdat.traj # ase trajectory file with nframes
20-
-- -- info.json # defining the parameters used in building AtomicData graph data
21-
```
16+
- For the plain text format, three seperate textfiles for **atomic structures** need to be provided: `atomic_numbers.dat`, `cell.dat` and `positions.dat`. The length unit used in `cell.dat` and `positions.dat` (if cartesian coordinates) is Angstrom.
2217

23-
> We also support another format to provide structure information, instead of loading structures from a single binary `.traj` file. In this way, three seperate textfiles for **atomic structures** need to be provided: `atomic_numbers.dat`, `pbc.dat`, `cell.dat` and `positions.dat`. The length unit used in `cell.dat` and `positions.dat` (if cartesian coordinates) is Angstrom.
2418

25-
The **band structures** data includes the kpoints list and eigenvalues in the binary format of `.npy`. The shape of kpoints data is fixed as **[nkpoints,3]** and eigenvalues is fixed as **[nframes,nkpoints,nbands]**. The `nframes` here must be the same as in **atomic structures** files.
19+
- For training a **DeePTB-SK** model, we need to prepare the `eigenvalues` label, which contrains the `eigenvalues.npy` and `kpoints.npy`. A typical dataset of **DeePTB-SK** task looks like:
2620

27-
> **Important:** The eigenvalues.npy should not contain bands that contributed by the core electrons, which is not setted as the TB orbitals in model setting.
21+
```
22+
data/
23+
-- set.x
24+
-- -- eigenvalues.npy # numpy array of fixed shape [nframes, nkpoints, nbands]
25+
-- -- kpoints.npy # numpy array of fixed shape [nkpoints, 3]
26+
-- -- xdat.traj # ase trajectory file with nframes
27+
-- -- info.json # defining the parameters used in building AtomicData graph data
28+
```
2829
29-
For typical **DeePTB-E3** task, we need to prepare the Hamiltonian/density matrix along with overlap matrix as labels. They are arranged as hdf5 binary format, and named as `hamiltonians.h5`/`density_matrices.h5` and `overlaps.h5` respectively. A typical dataset of **DeePTB-E3** looks like:
30+
The **band structures** data includes the kpoints list and eigenvalues in the binary format of `.npy`. The shape of kpoints data is fixed as **[nkpoints,3]** and eigenvalues is fixed as **[nframes,nkpoints,nbands]**. The `nframes` here must be the same as in **atomic structures** files.
3031
31-
```
32-
data/
33-
-- set.x
34-
-- -- positions.dat # a text file with nframe x natom row and 3 col
35-
-- -- pbc.dat # a text file of three bool variables
36-
-- -- cell.dat # a text file with nframe x 3 row and 3 col, or 3 rol and 3 col.
37-
-- -- atomic_numbers.dat # a text file with nframe x natom row and 1 col
38-
-- -- hamiltonian.h5 # a hdf5 dataset file with group named "0", "1", ..., "nframe". Each group contains a dict of {"i_j_Rx_Ry_Rz": numpy.ndarray}
39-
-- -- overlaps.h5 # a hdf5 dataset file with group named "0", "1", ..., "nframe". Each group contains a dict of {"i_j_Rx_Ry_Rz": numpy.ndarray}
40-
-- -- info.json
41-
```
32+
> **Important:** The eigenvalues.npy should not contain bands that contributed by the core electrons, which is not setted as the TB orbitals in model setting.
33+
34+
- For typical **DeePTB-E3** task, we need to prepare the Hamiltonian/density matrix along with overlap matrix as labels. They are arranged as hdf5 binary format, and named as `hamiltonians.h5`/`density_matrices.h5` and `overlaps.h5` respectively. A typical dataset of **DeePTB-E3** looks like:
35+
```
36+
data/
37+
-- set.x
38+
-- -- positions.dat # a text file with nframe x natom row and 3 col
39+
-- -- cell.dat # a text file with nframe x 3 row and 3 col, or 3 rol and 3 col.
40+
-- -- atomic_numbers.dat # a text file with nframe x natom row and 1 col
41+
-- -- hamiltonian.h5 # a hdf5 dataset file with group named "0", "1", ..., "nframe". Each group contains a dict of {"i_j_Rx_Ry_Rz": numpy.ndarray}
42+
-- -- overlaps.h5 # a hdf5 dataset file with group named "0", "1", ..., "nframe". Each group contains a dict of {"i_j_Rx_Ry_Rz": numpy.ndarray}
43+
-- -- info.json
44+
```
4245
4346
### Data settings: info.json
4447
4548
In **DeePTB**, the **atomic structures** and **band structures** data are stored in AtomicData graph structure. `info.json` defines the key parameters used in building AtomicData graph dataset, which looks like:
46-
```bash
49+
```JSON
4750
{
4851
"nframes": 1,
49-
"pos_type": "ase/cart/frac"
52+
"pos_type": "ase/cart/frac",
53+
"pbc": [true, true, true]
5054
}
5155
```
52-
`nframes` is the length of the trajectory, as we defined in the previous section. `pos_type` defines the input format of the **atomic structures**, which is set to `ase` if ASE `.traj` file is provided, and `cart` or `frac` if cartesian / fractional coordinate in `positions.dat` file provided.
56+
`nframes` is the length of the trajectory, as we defined in the previous section. `pos_type` defines the input format of the **atomic structures**, which is set to `ase` if ASE `.traj` file is provided, and `cart` or `frac` if cartesian / fractional coordinate in `positions.dat` file provided. The `pbc` specifies the periodic boundray condition of the system. The three value coresponding to the three boundary vector set in the unit cell information of the atomic data file.
5357

5458
<!--In the `AtomicData_options` section, the key arguments in defining graph structure is provided. `r_max` is the maximum cutoff in building neighbour list for each atom. `er_max` and `oer_max` are optional value for additional environmental dependence TB parameterization in **DeePTB-SK** mode, such as strain correction and `nnenv`. All cutoff variables have the unit of Angstrom.
5559
For **DeePTB-SK**, We can get the recommended `r_max` value by `DeePTB`'s bond analysis function, using:
@@ -59,11 +63,12 @@ dptb bond <structure path> [[-c] <cutoff>] [[-acc] <accuracy>]
5963
6064
For **DeePTB-E3**, we suggest the user align the `r_max` value to the LCAO basis's cutoff radius used in DFT calculation.
6165
-->
62-
For **DeePTB-SK** model, we should also specify the parameters in `info.json` that controls the fitting eigenvalues:
66+
For **DeePTB-SK** mode, we should also specify the parameters in `info.json` that controls the fitting eigenvalues:
6367
```JSON
6468
{
6569
"nframes": 1,
6670
"pos_type": "ase/cart/frac",
71+
"pbc": [true, true, true],
6772
"bandinfo": {
6873
"band_min": 0,
6974
"band_max": 6,

dptb/entrypoints/train.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ def train(
137137
log.warning(f"{obj} in config file is not consistent with the checkpoint, using the one in checkpoint")
138138
jdata["train_options"][obj] = f["config"]["train_options"][obj]
139139
else:
140-
jdata["train_options"] = f["config"]["train_options"]
140+
jdata["train_options"] = f["config"]["train_options"] # restart can be preceeded without train_options
141141

142142
if jdata.get("model_options", None) is None or jdata["model_options"] != f["config"]["model_options"]:
143143
log.warning("model_options in config file is not consistent with the checkpoint, using the one in checkpoint")
144144
jdata["model_options"] = f["config"]["model_options"] # restart does not allow to change model options
145145
else:
146-
# init model mode, allow model_options change
146+
# init model mode, allow model_options change (Would it cause some error later if the param mismatch?)
147147
if jdata.get("train_options", None) is None:
148148
jdata["train_options"] = f["config"]["train_options"]
149149
if jdata.get("model_options") is None:

dptb/utils/argcheck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,7 @@ def get_cutoffs_from_model_options(model_options):
16231623
oer_max = format_cuts(model_options["nnsk"]["onsite"]["rs"], model_options["nnsk"]["onsite"]["w"], 3)
16241624

16251625
elif model_options.get("dftbsk", None) is not None:
1626-
assert r_max is None, "r_max should not be provided in outside the dftbsk for training dftbsk model."
1626+
assert r_max is None, "r_max should not be provided other than the dftbsk param section for training dftbsk model."
16271627
r_max = model_options["dftbsk"].get("r_max")
16281628

16291629
else:

examples/e3/data/info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"nframes": 1,
33
"pos_type": "cart",
4-
"pbc": true
4+
"pbc": true
55
}

0 commit comments

Comments
 (0)