File: compare_phbands.py

package info (click to toggle)
abinit 9.10.4-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 518,712 kB
  • sloc: xml: 877,568; f90: 577,240; python: 80,760; perl: 7,019; ansic: 4,585; sh: 1,925; javascript: 601; fortran: 557; cpp: 454; objc: 323; makefile: 77; csh: 42; pascal: 31
file content (64 lines) | stat: -rwxr-xr-x 2,475 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
"""
Script to plot the phonon band structure and compare with the LWF phonon band structure.
 COPYRIGHT
 Copyright (C) 1999-2021 ABINIT group (HeXu)
 This file is distributed under the terms of the
 GNU General Public Licence, see ~abinit/COPYING
 or http://www.gnu.org/copyleft/gpl.txt .
 For the initials of contributors, see ~abinit/doc/developers/contributors.txt .
"""

import os
import argparse
import numpy as np
import matplotlib.pyplot as plt

Ha_cmm1 = 219474.6313705


def plot_file(fname, ax, **kwargs):
    d = np.loadtxt(fname)
    nband = d.shape[1]-1
    for i in range(1, nband+1):
        ax.plot(d[:, 0], d[:, i]*Ha_cmm1, **kwargs)
    ax.set_xlim(d[0, 0], d[-1, 0])
    return ax


def plot_compare(prefix, ax):
    fname1 = prefix+"_PHFRQ"
    fname2 = prefix+"_lwf_PHFRQ"
    if os.path.exists(fname1):
        plot_file(fname1, ax=ax, color='blue', alpha=0.9)
    else:
        raise IOError("Cannot find the file "+fname1+"Please check.")
    if os.path.exists(fname2):
        plot_file(fname2, ax=ax, marker='o', color='green', alpha=0.7)
    ax.axhline(linestyle='--', color='gray')
    ax.set_ylabel("Frequency ($cm^{-1}$)")
    return ax


def main():
    parser = argparse.ArgumentParser(
        description="This is a script to plot the phonon band structure and compare to the lattice Wannier function phonon band structure by comparing the PHFRQ files. If there are two files {prefix}_lwf_PHFRQ, and {prefix}_PHFRQ, the band structures will be compared. If only the  {prefix}_PHFRQ exists, it will plot the full phonon band structure.")
    parser.add_argument("prefix", type=str,
                        help="The prefix of the PHFRQ files, e.g. with the prefix 'run', the run_PHFRQ file contains the phonon bands. ", default="fun")
    parser.add_argument("--output", "-o", type=str,
                        help="The name of the output figure file, should end with usual image file names, like .png, .pdf, etc. If not specified, no file will be saved", default=None)
    parser.add_argument("--show", "-s",
                        action="store_true",
                        help="whether to show the band structure to screen.",
                        default=True)
    args = parser.parse_args()
    _fig, ax = plt.subplots()
    plot_compare(prefix=args.prefix, ax=ax)
    if args.output is not None:
        plt.savefig(args.output)
    if args.show:
        plt.show()


if __name__ == "__main__":
    main()