Skip to content

Commit 3039557

Browse files
author
jiyuang
committed
modify README for plot-tools
1 parent ddf2d24 commit 3039557

File tree

3 files changed

+69
-34
lines changed

3 files changed

+69
-34
lines changed

tools/plot-tools/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ python setup.py install
2020

2121
## Usage
2222
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`
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 Band`
2424
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
2525

2626
### Band Structure
2727
First, prepare a json file e.g. band-input.json:
2828
```json
2929
{
30-
"filename" : "BANDS_1.dat",
30+
"bandfile" : "BANDS_1.dat",
3131
"efermi" : 10.39537843955395,
3232
"energy_range" : [-1.5, 6],
3333
"kptfile" : "KPT"
@@ -39,11 +39,14 @@ First, prepare a json file e.g. band-input.json:
3939
| *efermi* | `float` or `List[float]` | Fermi level in eV |
4040
| *energy_range* | `list` | Range of energy in eV |
4141
| *shift* | `bool` | If set `'true'`, it will evaluate band gap. Default: `'false'` |
42+
| *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]}] |
43+
| *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]}] |
44+
| *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]}] |
4245
| *kptfile* | `str` | K-points file in ABACUS format |
4346
| *label* | `str` or `List[str]` | Label of band structure |
4447
| *color* | `str` or `List[str]` | Color of band structure |
4548

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.
49+
If you want to plot band structure of `nspin=2` or compare two band structure on same k-path, you can set *bandfile*, *efermi*, *label*, *color* in `list` type.
4750

4851
The *kptfile* should be as follows, and notes after `#` will be set as k-points label automatically.
4952
```shell
@@ -60,7 +63,7 @@ Line
6063
```
6164
Then, use the following command to plot band structure:
6265
```shell
63-
abacus-plot -b band-input.json
66+
abacus-plot -b -f band-input.json
6467
```
6568

6669
### DOS

tools/plot-tools/abacus_plot/band.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class Band:
2323
"""Parse Bands data"""
2424

25-
def __init__(self, bandfile: Union[PathLike, Sequence[PathLike]] = None, kptfile: str = '') -> None:
25+
def __init__(self, bandfile: Union[PathLike, Sequence[PathLike]] = None, kptfile: PathLike = '') -> None:
2626
self.bandfile = bandfile
2727
if isinstance(bandfile, list) or isinstance(bandfile, tuple):
2828
self.energy = []
@@ -683,17 +683,19 @@ def plot(self,
683683
outdir: PathLike = './',
684684
cmapname='jet',
685685
**kwargs):
686-
"""Plot parsed partial dos data
686+
"""Plot parsed projected band data
687687
688688
Args:
689689
fig (Figure): object of matplotlib.figure.Figure
690690
ax (Union[axes.Axes, Sequence[axes.Axes]]): object of matplotlib.axes.Axes or a list of this objects
691-
index (Union[Sequence[int], Dict[int, List[int]], Dict[int, Dict[int, List[int]]]], optional): extract PDOS of each atom. Defaults to [].
692-
atom_index (Union[Sequence[int], Dict[int, List[int]], Dict[int, Dict[int, List[int]]]], optional): extract PDOS of each atom with same atom_index. Defaults to [].
693-
species (Union[Sequence[str], Dict[str, List[int]], Dict[str, Dict[int, List[int]]]], optional): extract PDOS of each atom with same species. Defaults to [].
691+
index (Union[Sequence[int], Dict[int, List[int]], Dict[int, Dict[int, List[int]]]], optional): extract PBAND of each atom. Defaults to [].
692+
atom_index (Union[Sequence[int], Dict[int, List[int]], Dict[int, Dict[int, List[int]]]], optional): extract PBAND of each atom with same atom_index. Defaults to [].
693+
species (Union[Sequence[str], Dict[str, List[int]], Dict[str, Dict[int, List[int]]]], optional): extract PBAND of each atom with same species. Defaults to [].
694694
efermi (float, optional): fermi level in unit eV. Defaults to 0.
695695
energy_range (Sequence[float], optional): energy range in unit eV for plotting. Defaults to [].
696696
shift (bool, optional): if shift energy by fermi level and set the VBM to zero, or not. Defaults to False.
697+
outdir (PathLike): Default: './'
698+
cmapname (str): Default: 'jet'
697699
698700
Returns:
699701
BandPlot object: for manually plotting picture with bandplot.ax

tools/plot-tools/abacus_plot/main.py

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
'''
77

88
import argparse
9-
from os import PathLike
109
import matplotlib.pyplot as plt
1110

12-
from abacus_plot.band import BandPlot
11+
from abacus_plot.band import Band, PBand
1312
from abacus_plot.dos import TDOS, PDOS
1413
from abacus_plot.utils import read_json
1514

@@ -19,25 +18,50 @@ class Show:
1918

2019
@classmethod
2120
def show_cmdline(cls, args):
22-
if args.band:
23-
text = read_json(args.band)
24-
datafile = text["bandfile"]
21+
if args.band and not args.projected and not args.out:
22+
text = read_json(args.file)
23+
bandfile = text["bandfile"]
2524
kptfile = text["kptfile"]
2625
efermi = text.pop("efermi", 0.0)
2726
energy_range = text.pop("energy_range", [])
2827
shift = text.pop("shift", False)
2928
figsize = text.pop("figsize", (12, 10))
3029
fig, ax = plt.subplots(figsize=figsize)
31-
band = BandPlot(fig, ax)
32-
if isinstance(datafile, (str, PathLike)):
33-
band.singleplot(datafile, kptfile, efermi, energy_range, shift)
34-
elif isinstance(datafile, (list, tuple)):
35-
band.multiplot(datafile, kptfile, efermi, energy_range, shift)
30+
band = Band(bandfile, kptfile)
31+
band.plot(fig=fig, ax=ax, efermi=efermi, energy_range=energy_range, shift=shift, **text)
3632
dpi = text.pop("dpi", 400)
3733
fig.savefig(text.pop("outfile", "band.png"), dpi=dpi)
3834

39-
if args.tdos:
40-
text = read_json(args.tdos)
35+
if args.band and args.projected:
36+
text = read_json(args.file)
37+
bandfile = text["bandfile"]
38+
kptfile = text["kptfile"]
39+
efermi = text.pop("efermi", 0.0)
40+
energy_range = text.pop("energy_range", [])
41+
shift = text.pop("shift", False)
42+
figsize = text.pop("figsize", (12, 10))
43+
fig, ax = plt.subplots(figsize=figsize)
44+
index = text.pop("index", [])
45+
atom_index = text.pop("atom_index", [])
46+
species = text.pop("species", [])
47+
outdir = text.pop("outdir", './')
48+
cmapname = text.pop("cmapname", 'jet')
49+
pband = PBand(bandfile, kptfile)
50+
pband.plot(fig=fig, ax=ax, index=index, atom_index=atom_index, species=species, efermi=efermi, energy_range=energy_range, shift=shift, outdir=outdir, cmapname=cmapname, **text)
51+
52+
if args.band and args.out:
53+
text = read_json(args.file)
54+
bandfile = text["bandfile"]
55+
kptfile = text["kptfile"]
56+
index = text.pop("index", [])
57+
atom_index = text.pop("atom_index", [])
58+
species = text.pop("species", [])
59+
outdir = text.pop("outdir", './')
60+
pdos = PBand(bandfile, kptfile)
61+
pdos.write(index=index, atom_index=atom_index, species=species, outdir=outdir)
62+
63+
if args.dos and not args.projected and not args.out:
64+
text = read_json(args.file)
4165
tdosfile = text.pop("tdosfile", '')
4266
efermi = text.pop("efermi", 0.0)
4367
energy_range = text.pop("energy_range", [])
@@ -52,45 +76,51 @@ def show_cmdline(cls, args):
5276
dpi = text.pop("dpi", 400)
5377
fig.savefig(text.pop("tdosfig", "tdos.png"), dpi=dpi)
5478

55-
if args.pdos:
56-
text = read_json(args.pdos)
79+
if args.dos and args.projected:
80+
text = read_json(args.file)
5781
pdosfile = text.pop("pdosfile", '')
5882
efermi = text.pop("efermi", 0.0)
5983
energy_range = text.pop("energy_range", [])
6084
dos_range = text.pop("dos_range", [])
6185
shift = text.pop("shift", False)
86+
index = text.pop("index", [])
87+
atom_index = text.pop("atom_index", [])
6288
species = text.pop("species", [])
6389
figsize = text.pop("figsize", (12, 10))
6490
fig, ax = plt.subplots(
6591
len(species), 1, sharex=True, figsize=figsize)
6692
prec = text.pop("prec", 0.01)
6793
pdos = PDOS(pdosfile)
68-
pdos.plot(fig, ax, species, efermi=efermi, shift=shift,
94+
pdos.plot(fig=fig, ax=ax, index=index, atom_index=atom_index, species=species, efermi=efermi, shift=shift,
6995
energy_range=energy_range, dos_range=dos_range, prec=prec, **text)
7096
dpi = text.pop("dpi", 400)
7197
fig.savefig(text.pop("pdosfig", "pdos.png"), dpi=dpi)
7298

73-
if args.out_pdos:
74-
text = read_json(args.out_pdos)
99+
if args.dos and args.out:
100+
text = read_json(args.file)
75101
pdosfile = text.pop("pdosfile", '')
102+
index = text.pop("index", [])
103+
atom_index = text.pop("atom_index", [])
76104
species = text.pop("species", [])
77105
outdir = text.pop("outdir", './')
78106
pdos = PDOS(pdosfile)
79-
pdos.write(species, outdir)
107+
pdos.write(index=index, atom_index=atom_index, species=species, outdir=outdir)
80108

81109
def main():
82110
parser = argparse.ArgumentParser(
83111
prog='abacus-plot', description='Plotting tools for ABACUS')
84112

85113
# Show
86-
parser.add_argument('-b', '--band', dest='band', type=str,
114+
parser.add_argument('-f', '--file', dest='file', type=str, nargs='?', const='config.json',
115+
default='config.json', help='profile with format json')
116+
parser.add_argument('-b', '--band', dest='band', nargs='?', const=1, type=int,
87117
default=None, help='plot band structure and show band information.')
88-
parser.add_argument('-t', '--tdos', dest='tdos', type=str,
89-
default=None, help='plot total density of state(TDOS).')
90-
parser.add_argument('-p', '--pdos', dest='pdos', type=str,
91-
default=None, help='plot partial density of state(PDOS).')
92-
parser.add_argument('-o', '--out_pdos', dest='out_pdos', type=str,
93-
default=None, help='output partial density of state(PDOS).')
118+
parser.add_argument('-d', '--dos', dest='dos', nargs='?', const=1, type=int,
119+
default=None, help='plot density of state(DOS).')
120+
parser.add_argument('-p', '--projected', dest='projected', nargs='?', const=1, type=int,
121+
default=None, help='plot projected band structure or partial density of state(PDOS), should be used with `-b` or `-d`.')
122+
parser.add_argument('-o', '--out_parsed_data', dest='out', nargs='?', const=1, type=int,
123+
default=None, help='output projected band structure or partial density of state(PDOS) to files, should be used with `-b` or `-d`.')
94124
parser.set_defaults(func=Show().show_cmdline)
95125

96126
args = parser.parse_args()

0 commit comments

Comments
 (0)