Skip to content

Commit c907538

Browse files
author
jiyuang
committed
extract PDOS by index(atom_index) using plot-tools
1 parent 13d0a5e commit c907538

File tree

3 files changed

+185
-55
lines changed

3 files changed

+185
-55
lines changed

tools/plot-tools/README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ python setup.py install
1919
```
2020

2121
## Usage
22+
There are two ways to use this tool:
23+
1. Specify parameters in `band.py` or `dos.py` directly, and then `python band.py` or `python dos.py`. And you can also import module in your own script e.g. `from abacus_plot.band import BandPlot`
24+
2. Command-line tools are also supported in this tool. In this way, you need prepare an input file and execute some commands as follows
25+
2226
### Band Structure
2327
First, prepare a json file e.g. band-input.json:
2428
```json
@@ -39,7 +43,7 @@ First, prepare a json file e.g. band-input.json:
3943
| *label* | `str` or `List[str]` | Label of band structure |
4044
| *color* | `str` or `List[str]` | Color of band structure |
4145

42-
If you want to plot band structure of `nspin=2` or compare to band structure on same k-path, you can set *filename*, *efermi*, *label*, *color* in `list` type.
46+
If you want to plot band structure of `nspin=2` or compare two band structure on same k-path, you can set *filename*, *efermi*, *label*, *color* in `list` type.
4347

4448
The *kptfile* should be as follows, and notes after `#` will be set as k-points label automatically.
4549
```shell
@@ -75,10 +79,10 @@ First, prepare a json file e.g. dos-input.json:
7579
],
7680
"species": {
7781
"C": {
78-
"0": [
82+
0: [
7983
0
8084
],
81-
"1": [
85+
1: [
8286
0,
8387
1
8488
]
@@ -88,7 +92,7 @@ First, prepare a json file e.g. dos-input.json:
8892
1
8993
]
9094
},
91-
"pdosfig": "pdos.png",
95+
"pdosfig": "pdos.png"
9296
}
9397
```
9498
If you only want to plot total DOS, you can modify `pdosfile` to `tdosfile` and do not set `species` and `pdosfig`.
@@ -99,7 +103,9 @@ If you only want to plot total DOS, you can modify `pdosfile` to `tdosfile` and
99103
| *efermi* | `float` | Fermi level in eV |
100104
| *energy_range* | `list` | Range of energy in eV |
101105
| *shift* | `bool` | If set `'true'`, it will evaluate band gap. Default: `'false'` |
102-
| *species* | `List[str]` or `Dict[str, List[int]]` or `Dict[str, Dict[str, List[int]]]]` | Three ways to plot partial DOS e.g. ["C", "Si"], {"C":[0, 1], "Si":[0]}, ["C":{"0":[0]}, "Si":{"1":[0, 1]}] |
106+
| *index* | `List[int]` or `Dict[int, List[int]]` or `Dict[int, Dict[int, List[int]]]]` | Extract PDOS of each atom e.g. [0, 1], {0:[0, 1], 1:[0]}, [0:{0:[0]}, 1:{1:[0, 1]}] |
107+
| *atom_index* | `List[int]` or `Dict[int, List[int]]` or `Dict[int, Dict[int, List[int]]]]` | Extract PDOS of each atom with same atom_index e.g. [0, 1], {0:[0, 1], 1:[0]}, [0:{0:[0]}, 1:{1:[0, 1]}] |
108+
| *species* | `List[str]` or `Dict[str, List[int]]` or `Dict[str, Dict[int, List[int]]]]` | Extract PDOS of each atom with same species e.g. ["C", "Si"], {"C":[0, 1], "Si":[0]}, ["C":{0:[0]}, "Si":{1:[0, 1]}] |
103109
| *tdosfig* | `str` | Output picture of total DOS |
104110
| *pdosfig* | `str` | Output picture of partial DOS |
105111

tools/plot-tools/abacus_plot/band.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,19 @@ def multiplot(self, datafile: Sequence[PathLike], kptfile: str = '', efermi: Seq
239239
index = kpt.label_special_k
240240
self._set_figure(index, energy_range)
241241

242+
@classmethod
243+
def direct_bandgap(cls, vb: namedtuple, cb: namedtuple, klength: int):
244+
"""Calculate direct band gap"""
245+
246+
gap_list = []
247+
i_index = []
248+
for i in range(klength):
249+
gap_list.append(np.min(cb.band[:, i])-np.max(vb.band[:, i]))
250+
i_index.append(i)
251+
dgap = np.min(gap_list)
252+
253+
return dgap, i_index[np.argmin(gap_list)]
254+
242255
@classmethod
243256
def bandgap(cls, vb: namedtuple, cb: namedtuple):
244257
"""Calculate band gap"""
@@ -247,6 +260,19 @@ def bandgap(cls, vb: namedtuple, cb: namedtuple):
247260

248261
return gap
249262

263+
@classmethod
264+
def band_type(cls, vb: namedtuple, cb: namedtuple):
265+
vbm_x, cbm_x = vb.k_index, cb.k_index
266+
longone, shortone = (vbm_x, cbm_x) if len(
267+
vbm_x) >= len(cbm_x) else (cbm_x, vbm_x)
268+
for i in shortone:
269+
if i in longone:
270+
btype = "Direct"
271+
else:
272+
btype = "Indirect"
273+
274+
return btype
275+
250276
@classmethod
251277
def info(cls, kpath: Sequence, vb: namedtuple, cb: namedtuple):
252278
"""Output the information of band structure
@@ -255,22 +281,18 @@ def info(cls, kpath: Sequence, vb: namedtuple, cb: namedtuple):
255281
:params energy: band energy after subtracting the Fermi level
256282
"""
257283

258-
def band_type(vbm_x, cbm_x):
259-
longone, shortone = (vbm_x, cbm_x) if len(
260-
vbm_x) >= len(cbm_x) else (cbm_x, vbm_x)
261-
for i in shortone:
262-
if i in longone:
263-
btype = "Direct"
264-
else:
265-
btype = "Indirect"
266-
return btype
267-
268284
gap = cls.bandgap(vb, cb)
285+
dgap, d_i = cls.direct_bandgap(vb, cb, len(kpath))
286+
btype = cls.band_type(vb, cb)
269287
print(
270288
"--------------------------Band Structure--------------------------", flush=True)
271289
print(
272-
f"{'Band character:'.ljust(30)}{band_type(vb.k_index, cb.k_index)}", flush=True)
273-
print(f"{'Band gap(eV):'.ljust(30)}{gap: .4f}", flush=True)
290+
f"{'Band character:'.ljust(30)}{btype}", flush=True)
291+
if btype == "Indirect":
292+
print(f"{'Direct Band gap(eV):'.ljust(30)}{dgap: .4f}", flush=True)
293+
print(f"{'Indirect Band gap(eV):'.ljust(30)}{gap: .4f}", flush=True)
294+
elif btype == "Direct":
295+
print(f"{'Band gap(eV):'.ljust(30)}{gap: .4f}", flush=True)
274296
print(f"{'Band index:'.ljust(30)}{'HOMO'.ljust(10)}{'LUMO'}", flush=True)
275297
print(
276298
f"{''.ljust(30)}{str(vb.band_index[-1]).ljust(10)}{str(cb.band_index[0])}", flush=True)

0 commit comments

Comments
 (0)