Skip to content

Commit 4a04e74

Browse files
Merge pull request #17 from Lonya0/main
Add PYATB parse mode.
2 parents 9f89dd4 + 50f6af4 commit 4a04e74

5 files changed

Lines changed: 161 additions & 15 deletions

File tree

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ However, the user can always manage the dependency themselves, here are the pack
1616
Current:
1717

1818
| Package | Structure | Eigenvalues | Hamiltonian | Density matrix | Overlap matrix |
19-
| :----: | :----: | :----: | :----: | :----: | :----: |
20-
| ABACUS ||||||
21-
| RESCU || || ||
22-
| SIESTA || ||||
23-
| Gaussian || ||||
24-
| VASP ||| | | |
19+
|:--------:|:---------:|:-----------:| :----: | :----: | :----: |
20+
| ABACUS ||||||
21+
| RESCU || || ||
22+
| SIESTA || ||||
23+
| Gaussian || ||||
24+
| VASP ||| | | |
25+
| PYATB ||| | | |
2526

2627
Ongoing:
2728

@@ -35,15 +36,15 @@ Ongoing:
3536
To parse the DFT output files into readable data format, user can follows:
3637

3738
```bash
38-
dftio parse [-h] [-ll {DEBUG,3,INFO,2,WARNING,1,ERROR,0}] [-lp LOG_PATH] [-m MODE] [-n NUM_WORKERS] [-r ROOT] [-p PREFIX] [-o OUTROOT] [-f FORMAT] [-ham] [-ovp] [-dm] [-eig]
39+
usage: dftio parse [-h] [-ll {DEBUG,3,INFO,2,WARNING,1,ERROR,0}] [-lp LOG_PATH] [-m MODE] [-n NUM_WORKERS] [-r ROOT] [-p PREFIX] [-o OUTROOT] [-f FORMAT] [-ham] [-ovp] [-dm] [-eig] [-min BAND_INDEX_MIN]
3940

40-
optional arguments:
41+
options:
4142
-h, --help show this help message and exit
4243
-ll {DEBUG,3,INFO,2,WARNING,1,ERROR,0}, --log-level {DEBUG,3,INFO,2,WARNING,1,ERROR,0}
4344
set verbosity level by string or number, 0=ERROR, 1=WARNING, 2=INFO and 3=DEBUG (default: INFO)
4445
-lp LOG_PATH, --log-path LOG_PATH
4546
set log file to log messages to disk, if not specified, the logs will only be output to console (default: None)
46-
-m MODE, --mode MODE The name of the DFT software. (default: abacus)
47+
-m MODE, --mode MODE The name of the DFT software, currently support abacus/rescu/siesta/gaussian/pyatb (default: abacus)
4748
-n NUM_WORKERS, --num_workers NUM_WORKERS
4849
The number of workers used to parse the dataset. (For n>1, we use the multiprocessing to accelerate io.) (default: 1)
4950
-r ROOT, --root ROOT The root directory of the DFT files. (default: ./)
@@ -52,12 +53,14 @@ optional arguments:
5253
-o OUTROOT, --outroot OUTROOT
5354
The output root directory. (default: ./)
5455
-f FORMAT, --format FORMAT
55-
The output root directory. (default: dat)
56+
The output file format, should be dat, ase or lmdb. (default: dat)
5657
-ham, --hamiltonian Whether to parse the Hamiltonian matrix. (default: False)
5758
-ovp, --overlap Whether to parse the Overlap matrix (default: False)
5859
-dm, --density_matrix
5960
Whether to parse the Density matrix (default: False)
6061
-eig, --eigenvalue Whether to parse the kpoints and eigenvalues (default: False)
62+
-min BAND_INDEX_MIN, --band_index_min BAND_INDEX_MIN
63+
The initial band index for eigenvalues to save.(0-band_index_min) bands will be ignored! (default: 0)
6164
```
6265
6366
## Call for Contributors

dftio/__main__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def main_parser() -> argparse.ArgumentParser:
7777
"--mode",
7878
type=str,
7979
default="abacus",
80-
help="The name of the DFT software, currently support abacus/rescu/siesta/gaussian",
80+
help="The name of the DFT software, currently support abacus/rescu/siesta/gaussian/pyatb",
8181
)
8282

8383
parser_parse.add_argument(
@@ -244,9 +244,6 @@ def main():
244244
with Pool(args.num_workers) as p:
245245
list(tqdm(p.imap(wapper(dict_args), range(len(parser))), total=len(parser), desc="Parsing the DFT files: "))
246246
else:
247-
parser = ParserRegister(
248-
**dict_args
249-
)
250247
for i in tqdm(range(len(parser)), desc="Parsing the DFT files: "):
251248
parser.write(idx=i, **dict_args)
252249

dftio/io/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
from dftio.io.gaussian.gaussian_parser import GaussianParser
44
from dftio.io.siesta.siesta_parser import SiestaParser
55
from dftio.io.vasp.vasp_parser import VASPParser
6+
from dftio.io.pyatb.pyatb_parser import PyatbParser
67

78

89
__all__ = [
910
"AbacusParser",
1011
"RescuParser",
1112
"GaussianParser",
1213
"SiestaParser",
13-
"VASPParser"
14+
"VASPParser",
15+
"PyatbParser"
1416
]

dftio/io/pyatb/pyatb_parser.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import ase
2+
import dpdata
3+
import os
4+
import numpy as np
5+
from dftio.io.parse import Parser, ParserRegister
6+
from dftio.register import Register
7+
from dftio.data import _keys
8+
9+
@ParserRegister.register("pyatb")
10+
class PyatbParser(Parser):
11+
"""
12+
PYATB parser is commonly used for normal input file generated by 'pyatb_input ... --band' and running 'pyatb'
13+
locally in generated 'pyatb' directory.
14+
15+
Which should be like:
16+
pyatb/
17+
|-- Input
18+
|-- Out
19+
| |-- Band_Structure
20+
| | |-- band.dat *
21+
| | |-- band.pdf
22+
| | |-- band_info.dat
23+
| | |-- high_symmetry_kpoint.dat
24+
| | |-- kpt.dat *
25+
| | |-- plot_band.py
26+
| | `-- x_coor_array.dat
27+
| |-- input.json
28+
| `-- running.log
29+
|-- STRU *
30+
`-- get_Energy.out
31+
32+
* means essential, but normally you will get other output files as well.
33+
"""
34+
35+
def __init__(
36+
self,
37+
root,
38+
prefix,
39+
**kwargs
40+
):
41+
super(PyatbParser, self).__init__(root, prefix)
42+
self.raw_sys = [
43+
dpdata.System(os.path.join(self.raw_datas[idx], 'pyatb', "STRU"), fmt="abacus/stru") for
44+
idx in range(len(self.raw_datas))]
45+
46+
# essential
47+
def get_structure(self, idx):
48+
sys = self.raw_sys[idx]
49+
50+
structure = {
51+
_keys.ATOMIC_NUMBERS_KEY: np.array([ase.atom.atomic_numbers[i] for i in sys.data["atom_names"]], dtype=np.int32)[sys.data["atom_types"]],
52+
_keys.PBC_KEY: np.array([True, True, True]) # abacus does not allow non-pbc structure
53+
}
54+
structure[_keys.POSITIONS_KEY] = sys.data["coords"].astype(np.float32)
55+
structure[_keys.CELL_KEY] = sys.data["cells"].astype(np.float32)
56+
57+
return structure
58+
59+
# essential
60+
def get_eigenvalue(self, idx, band_index_min=0):
61+
path = self.raw_datas[idx]
62+
63+
assert os.path.exists(os.path.join(path, 'pyatb', "Out", "Band_Structure", "band.dat"))
64+
eigs = np.loadtxt(os.path.join(path, 'pyatb', "Out", "Band_Structure", "band.dat"))[np.newaxis, :, band_index_min:]
65+
assert os.path.exists(os.path.join(path, 'pyatb', "Out", "Band_Structure", "kpt.dat"))
66+
kpts = np.loadtxt(os.path.join(path, 'pyatb', "Out", "Band_Structure", "kpt.dat"))
67+
68+
return {_keys.ENERGY_EIGENVALUE_KEY: eigs.astype(np.float32), _keys.KPOINT_KEY: kpts.astype(np.float32)}
69+
70+
# essential
71+
def get_basis(self, idx):
72+
raise NotImplementedError("PYATB does not support block parsing yet.")
73+
74+
# essential
75+
def get_blocks(self, idx, hamiltonian=True, overlap=False, density_matrix=False):
76+
raise NotImplementedError("PYATB does not support block parsing yet.")

example/pyatb/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# How to use PYATB mode
2+
PYATB parser is commonly used for normal input file generated by `pyatb_input ... --band` without changing default config and running `pyatb`
3+
locally in generated 'pyatb' directory.
4+
5+
Which should be like:
6+
7+
pyatb/
8+
|-- Input
9+
|-- Out
10+
| |-- Band_Structure
11+
| | |-- band.dat *
12+
| | |-- band.pdf
13+
| | |-- band_info.dat
14+
| | |-- high_symmetry_kpoint.dat
15+
| | |-- kpt.dat *
16+
| | |-- plot_band.py
17+
| | `-- x_coor_array.dat
18+
| |-- input.json
19+
| `-- running.log
20+
|-- STRU *
21+
`-- get_Energy.out
22+
23+
\* means essential, but normally you will get other output files as well.
24+
25+
Then the root (or root + prefix) should be the directory that contain pyatb directory.
26+
27+
# Example:
28+
29+
I have a directory:
30+
31+
abacus_pyatb_test/
32+
|-- task.001
33+
| |-- INPUT
34+
| |-- STRU
35+
| |-- OUT.ABACUS
36+
| | |-- INPUT
37+
| | |-- STRU.cif
38+
| | |-- data-HR-sparse_SPIN0.csr
39+
| | |-- data-SR-sparse_SPIN0.csr
40+
| | |-- data-rR-sparse.csr
41+
| | |-- kpoints
42+
| | `-- running_scf.log
43+
| |-- Out
44+
| | `-- running.log
45+
| `-- pyatb
46+
| |-- Input
47+
| |-- STRU *
48+
| |-- get_Energy.out
49+
| `-- Out
50+
| |-- input.json
51+
| |-- running.log
52+
| `-- Band_Structure
53+
| |-- band.dat *
54+
| |-- band.pdf
55+
| |-- band_info.dat
56+
| |-- high_symmetry_kpoint.dat
57+
| |-- kpt.dat *
58+
| |-- plot_band.py
59+
| `-- x_coor_array.dat
60+
|-- ...
61+
62+
In `/task.001` run `pyatb_input -i . --band`, which generate `pyatb/Input`, `pyatb/STRU` and `pyatb/get_Energy.out`.
63+
64+
Then in `/pyatb` run `pyatb`, which generate `Band_Structure/band.dat` and `Band_Structure/kpt.dat`.
65+
66+
Without changing output directory name, you will get same directory structure!
67+
68+
Files with * are to be read, if any is missing, you could add by yourself.

0 commit comments

Comments
 (0)