Skip to content

Commit 36dbead

Browse files
author
jiyuang
committed
modify README of of plot-tools
1 parent aff6b0d commit 36dbead

File tree

4 files changed

+67
-54
lines changed

4 files changed

+67
-54
lines changed

tools/plot-tools/README.md

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- [NumPy](https://numpy.org/)
1212
- [Matplotlib](https://matplotlib.org/)
1313
- [lxml](https://lxml.de/)
14+
- [setuptools](https://setuptools.pypa.io/en/latest/index.html)
1415

1516
## Installation
1617
Use the following command to install this tool:
@@ -21,30 +22,30 @@ python setup.py install
2122
## Usage
2223
There are two ways to use this tool:
2324
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`
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+
2. Command-line tools are also supported in this tool. In this way, you need prepare an input file and execute some commands (see below). You can use `abacus-plot -h` to check command-line information
2526

2627
### Band Structure
27-
First, prepare a json file e.g. band-input.json:
28+
First, prepare a file named 'config.json' in json format:
2829
```json
2930
{
3031
"bandfile" : "BANDS_1.dat",
31-
"efermi" : 10.39537843955395,
32+
"efermi" : 6.585653952007503,
3233
"energy_range" : [-1.5, 6],
3334
"kptfile" : "KPT"
3435
}
3536
```
36-
| Property | Type | Note |
37-
| :------------: | :----------------------: | :------------------------------------------------------------: |
38-
| *bandfile* | `str` or `List[str]` | Bands data file output from ABACUS |
39-
| *efermi* | `float` or `List[float]` | Fermi level in eV |
40-
| *energy_range* | `list` | Range of energy in eV |
41-
| *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]}] |
45-
| *kptfile* | `str` | K-points file in ABACUS format |
46-
| *label* | `str` or `List[str]` | Label of band structure |
47-
| *color* | `str` or `List[str]` | Color of band structure |
37+
| Property | Type | Note |
38+
| :------------: | :-------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
39+
| *bandfile* | `str` or `List[str]` | Bands data file output from ABACUS. 'BANDS_*.dat' for band structure and 'PBANDS_*' for projected band structure |
40+
| *efermi* | `float` or `List[float]` | Fermi level in eV |
41+
| *energy_range* | `list` | Range of energy in eV |
42+
| *shift* | `bool` | If set `'true'`, it will evaluate band gap (only for semiconductors and insulators). Default: `'false'` |
43+
| *index* | `List[int]` or `Dict[str, List[int]]` or `Dict[str, Dict[int, List[int]]]]` | Extract PBANDS of each atom from 'PBANDS_*' file e.g. [index_0, index_1...] or {index_0:[l_0, l_1, ...], ...}, [index_0:{l_0:[m_0, m_1, ...], ...}, ...] |
44+
| *atom_index* | `List[int]` or `Dict[str, List[int]]` or `Dict[str, Dict[int, List[int]]]]` | Extract PBANDS of each atom with same atom_index from 'PBANDS_*' file e.g. [atom_index_0, atom_index_1...] or {atom_index_0:[l_0, l_1, ...], ...}, [atom_index_0:{l_0:[m_0, m_1, ...], ...}, ...] |
45+
| *species* | `List[str]` or `Dict[str, List[int]]` or `Dict[str, Dict[int, List[int]]]]` | Extract PBANDS of each atom with same species from 'PBANDS_*' file e.g. [elem_0, elem_1...] or {elem_0:[l_0, l_1, ...], ...}, [elem_0:{l_0:[m_0, m_1, ...], ...}, ...] |
46+
| *kptfile* | `str` | K-points file with `Line` mode in ABACUS format |
47+
| *label* | `str` or `List[str]` | Label of band structure |
48+
| *color* | `str` or `List[str]` | Color of band structure |
4849

4950
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.
5051

@@ -63,15 +64,25 @@ Line
6364
```
6465
Then, use the following command to plot band structure:
6566
```shell
66-
abacus-plot -b -f band-input.json
67+
abacus-plot -b
68+
```
69+
70+
Then, the following command will plot projected band structure and figures output to directory `PBAND*_FIG` ($*=1$ for $nspin=1$, $*=2$ for $nspin=2$):
71+
```shell
72+
abacus-plot -d -p
73+
```
74+
75+
Then, the following command will output parsed partial DOS to directory `PBAND*_FILE` ($*=1$ for $nspin=1$, $*=2$ for $nspin=2$):
76+
```shell
77+
abacus-plot -d -o
6778
```
6879

6980
### DOS
70-
First, prepare a json file e.g. dos-input.json:
81+
First, prepare a file named 'config.json' in json format:
7182
```json
7283
{
7384
"pdosfile": "PDOS",
74-
"efermi": 10.39537843955395,
85+
"efermi": 6.585653952007503,
7586
"energy_range": [
7687
-5,
7788
7
@@ -82,10 +93,10 @@ First, prepare a json file e.g. dos-input.json:
8293
],
8394
"species": {
8495
"C": {
85-
0: [
96+
"0": [
8697
0
8798
],
88-
1: [
99+
"1": [
89100
0,
90101
1
91102
]
@@ -99,30 +110,30 @@ First, prepare a json file e.g. dos-input.json:
99110
}
100111
```
101112
If you only want to plot total DOS, you can modify `pdosfile` to `tdosfile` and do not set `species` and `pdosfig`.
102-
| Property | Type | Note |
103-
| :------------: | :-------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------: |
104-
| *tdosfile* | `str` | Total DOS data file output from ABACUS |
105-
| *pdosfile* | `str` | Partial DOS data file output from ABACUS in xml format |
106-
| *efermi* | `float` | Fermi level in eV |
107-
| *energy_range* | `list` | Range of energy in eV |
108-
| *shift* | `bool` | If set `'true'`, it will evaluate band gap. Default: `'false'` |
109-
| *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]}] |
110-
| *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]}] |
111-
| *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]}] |
112-
| *tdosfig* | `str` | Output picture of total DOS |
113-
| *pdosfig* | `str` | Output picture of partial DOS |
113+
| Property | Type | Note |
114+
| :------------: | :-------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
115+
| *tdosfile* | `str` | Total DOS data file output from ABACUS |
116+
| *pdosfile* | `str` | Partial DOS data file output from ABACUS in xml format |
117+
| *efermi* | `float` | Fermi level in eV |
118+
| *energy_range* | `list` | Range of energy in eV |
119+
| *shift* | `bool` | If set `'true'`, it will evaluate band gap. Default: `'false'` |
120+
| *index* | `List[int]` or `Dict[str, List[int]]` or `Dict[str, Dict[str, List[int]]]]` | Extract PDOS of each atom e.g. [index_0, index_1...] or {index_0:[l_0, l_1, ...], ...}, [index_0:{l_0:[m_0, m_1, ...], ...}, ...] |
121+
| *atom_index* | `List[int]` or `Dict[str, List[int]]` or `Dict[str, Dict[str, List[int]]]]` | Extract PDOS of each atom with same atom_index e.g. [atom_index_0, atom_index_1...] or {atom_index_0:[l_0, l_1, ...], ...}, [atom_index_0:{l_0:[m_0, m_1, ...], ...}, ...] |
122+
| *species* | `List[str]` or `Dict[str, List[int]]` or `Dict[str, Dict[str, List[int]]]]` | Extract PDOS of each atom with same species e.g. [elem_0, elem_1...] or {elem_0:[l_0, l_1, ...], ...}, [elem_0:{l_0:[m_0, m_1, ...], ...}, ...] |
123+
| *tdosfig* | `str` | Output picture of total DOS |
124+
| *pdosfig* | `str` | Output picture of partial DOS |
114125

115126
Then, the following command will plot total DOS:
116127
```shell
117-
abacus-plot -t tdos-input.json
128+
abacus-plot -d
118129
```
119130

120131
Then, the following command will plot partial DOS:
121132
```shell
122-
abacus-plot -p pdos-input.json
133+
abacus-plot -d -p
123134
```
124135

125136
Then, the following command will output parsed partial DOS to directory `PDOS_FILE`:
126137
```shell
127-
abacus-plot -o pdos-input.json
138+
abacus-plot -d -o
128139
```

tools/plot-tools/abacus_plot/band.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -745,19 +745,16 @@ def plot(self,
745745
parent = Path(r"C:\Users\YY.Ji\Desktop")
746746
name = "PBANDS_1"
747747
path = parent/name
748-
# notes = {'s': '(b)'}
749-
# datafile = [path/"soc.dat", path/"non-soc.dat"]
750-
# kptfile = path/"KPT"
751748
fig, ax = plt.subplots(figsize=(12, 6))
752-
# label = ["with SOC", "without SOC"]
753-
# color = ["r", "g"]
754-
# linestyle = ["solid", "dashed"]
755749
energy_range = [-5, 6]
756750
efermi = 4.417301755850272
757751
shift = False
758752
#species = {"Ag": [2], "Cl": [1], "In": [0]}
759753
atom_index = {8: {2: [1, 2]}, 4: {2: [1, 2]}, 10: [1, 2]}
760754
pband = PBand(str(path))
755+
756+
# if you want to specify `species` or `index`, you need to
757+
# set `species=species` or `index=index` in the following two functions
761758
pband.plot(fig, ax, atom_index=atom_index, efermi=efermi,
762-
energy_range=energy_range, shift=shift)
759+
energy_range=energy_range, shift=shift)
763760
pband.write(atom_index=atom_index)

tools/plot-tools/abacus_plot/dos.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def _set_figure(self, energy_range: Sequence = [], dos_range: Sequence = [], not
109109
# y-axis
110110
if dos_range:
111111
self.ax.set_ylim(dos_range[0], dos_range[1])
112-
if "xlabel_params" in self.plot_params.keys():
112+
if "ylabel_params" in self.plot_params.keys():
113113
self.ax.set_ylabel("DOS", **self.plot_params["ylabel_params"])
114114
else:
115115
self.ax.set_ylabel("DOS", size=25)
@@ -506,23 +506,26 @@ def plot(self,
506506

507507
if __name__ == "__main__":
508508
import matplotlib.pyplot as plt
509+
#tdosfile = r"C:\Users\YY.Ji\Desktop\TDOS"
510+
#tdos = TDOS(tdosfile)
511+
#fig, ax = plt.subplots()
512+
#energy_range = [-6, 10]
513+
#dos_range = [0, 5]
514+
# dosplots = tdos.plot(fig, ax, efermi=5, shift=True,
515+
# energy_range=energy_range, dos_range=dos_range, notes={'s': '(a)'})
516+
# fig.savefig("tdos.png")
517+
509518
pdosfile = r"C:\Users\YY.Ji\Desktop\PDOS"
510519
pdos = PDOS(pdosfile)
511520
#species = {"Ag": [2], "Cl": [1], "In": [0]}
512521
atom_index = {8: {2: [1, 2]}, 4: {2: [1, 2]}, 10: [1, 2]}
513522
fig, ax = plt.subplots(3, 1, sharex=True)
514523
energy_range = [-1.5, 6]
515524
dos_range = [0, 5]
525+
526+
# if you want to specify `species` or `index`, you need to
527+
# set `species=species` or `index=index` in the following two functions
516528
dosplots = pdos.plot(fig, ax, atom_index=atom_index, efermi=5, shift=True,
517529
energy_range=energy_range, dos_range=dos_range, notes=[{'s': '(a)'}, {'s': '(b)'}, {'s': '(c)'}])
518530
fig.savefig("pdos.png")
519-
pdos.write(atom_index=atom_index)
520-
521-
#tdosfile = r"C:\Users\YY.Ji\Desktop\TDOS"
522-
#tdos = TDOS(tdosfile)
523-
#fig, ax = plt.subplots()
524-
#energy_range = [-6, 10]
525-
#dos_range = [0, 5]
526-
# dosplots = tdos.plot(fig, ax, efermi=5, shift=True,
527-
# energy_range=energy_range, dos_range=dos_range, notes={'s': '(a)'})
528-
# fig.savefig("tdos.png")
531+
pdos.write(atom_index=atom_index)

tools/plot-tools/setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@
1616
author='jiyuyang',
1717
author_email='[email protected]',
1818
url='None',
19-
entry_points={'console_scripts': ['abacus-plot=abacus_plot.main:main']}
19+
entry_points={'console_scripts': ['abacus-plot=abacus_plot.main:main']},
20+
install_requires=['matplotlib', 'numpy', 'setuptools', 'lxml'],
21+
python_requires='>=3.4'
2022
)

0 commit comments

Comments
 (0)