-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix failing tests and migrate to importlib #216
Changes from all commits
9b3f3b1
49af89e
10ddb82
f9f226c
052eb96
9936c01
16e707a
47cc9f9
d388cfc
82d987c
ae0c43b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,14 @@ | |
import sys | ||
import warnings | ||
|
||
try: | ||
from importlib.resources import files as ilr_files | ||
except ImportError: # Python < 3.9 | ||
from importlib_resources import files as ilr_files | ||
import matplotlib as mpl | ||
from pkg_resources import Requirement, resource_filename | ||
from pymatgen.electronic_structure.bandstructure import get_reconstructed_band_structure | ||
from pymatgen.electronic_structure.bandstructure import ( | ||
get_reconstructed_band_structure, | ||
) | ||
from pymatgen.electronic_structure.core import Spin | ||
from pymatgen.io.vasp.outputs import BSVasprun | ||
|
||
|
@@ -339,6 +344,7 @@ def bandplot( | |
|
||
# currently not supported as it is a pain to make subplots within subplots, | ||
# although need to check this is still the case | ||
# FIXME: is this necessary if mode can only be "rgb" and "stacked"? | ||
if "split" in mode and dos_file: | ||
logging.error( | ||
"ERROR: Plotting split projected band structure with DOS" | ||
|
@@ -387,7 +393,9 @@ def bandplot( | |
else: | ||
logging.info(f"Found PDOS file {pdos_file}") | ||
else: | ||
logging.info(f"Cell file {cell_file} does not exist, cannot plot PDOS.") | ||
logging.info( | ||
f"Cell file {cell_file} does not exist, cannot plot PDOS." | ||
) | ||
|
||
dos, pdos = read_castep_dos( | ||
dos_file, | ||
|
@@ -609,7 +617,8 @@ def _get_parser(): | |
"-c", | ||
"--code", | ||
default="vasp", | ||
help="Electronic structure code (default: vasp)." '"questaal" also supported.', | ||
help="Electronic structure code (default: vasp)." | ||
'"questaal" also supported.', | ||
) | ||
parser.add_argument( | ||
"-p", "--prefix", metavar="P", help="prefix for the files generated" | ||
|
@@ -750,7 +759,10 @@ def _get_parser(): | |
"--orbitals", | ||
type=_el_orb, | ||
metavar="O", | ||
help=("orbitals to split into lm-decomposed " 'contributions (e.g. "Ru.d")'), | ||
help=( | ||
"orbitals to split into lm-decomposed " | ||
'contributions (e.g. "Ru.d")' | ||
), | ||
) | ||
parser.add_argument( | ||
"--atoms", | ||
|
@@ -814,7 +826,9 @@ def _get_parser(): | |
parser.add_argument( | ||
"--height", type=float, default=None, help="height of the graph" | ||
) | ||
parser.add_argument("--width", type=float, default=None, help="width of the graph") | ||
parser.add_argument( | ||
"--width", type=float, default=None, help="width of the graph" | ||
) | ||
parser.add_argument( | ||
"--ymin", type=float, default=-6.0, help="minimum energy on the y-axis" | ||
) | ||
|
@@ -865,16 +879,18 @@ def main(): | |
logging.getLogger("").addHandler(console) | ||
|
||
if args.config is None: | ||
config_path = resource_filename( | ||
Requirement.parse("sumo"), "sumo/plotting/orbital_colours.conf" | ||
config_path = os.path.join( | ||
ilr_files("sumo.plotting"), "orbital_colours.conf" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think with importlib.resources.files we can have |
||
) | ||
else: | ||
config_path = args.config | ||
colours = configparser.ConfigParser() | ||
colours.read(os.path.abspath(config_path)) | ||
|
||
warnings.filterwarnings("ignore", category=UserWarning, module="matplotlib") | ||
warnings.filterwarnings("ignore", category=UnicodeWarning, module="matplotlib") | ||
warnings.filterwarnings( | ||
"ignore", category=UnicodeWarning, module="matplotlib" | ||
) | ||
warnings.filterwarnings("ignore", category=UserWarning, module="pymatgen") | ||
|
||
bandplot( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,10 @@ | |
|
||
import matplotlib as mpl | ||
import numpy as np | ||
from pkg_resources import Requirement, resource_filename | ||
try: | ||
from importlib.resources import files as ilr_files | ||
except ImportError: # Python < 3.9 | ||
from importlib_resources import files as ilr_files | ||
|
||
mpl.use("Agg") | ||
|
||
|
@@ -205,7 +208,6 @@ def dosplot( | |
) | ||
|
||
elif code.lower() == "castep": | ||
|
||
if filename: | ||
bands_file = filename | ||
else: | ||
|
@@ -261,7 +263,13 @@ def dosplot( | |
else: | ||
pdos_candidates = glob("dos.*") | ||
for candidate in pdos_candidates: | ||
if candidate.split(".")[-1] in ("pdf", "png", "svg", "jpg", "jpeg"): | ||
if candidate.split(".")[-1] in ( | ||
"pdf", | ||
"png", | ||
"svg", | ||
"jpg", | ||
"jpeg", | ||
): | ||
continue | ||
elif candidate.split(".")[-1].lower() in ("gz", "z", "bz2"): | ||
pdos_file = candidate | ||
|
@@ -422,14 +430,20 @@ def _get_parser(): | |
) | ||
|
||
parser.add_argument( | ||
"-f", "--filename", help="vasprun.xml file to plot", default=None, metavar="F" | ||
"-f", | ||
"--filename", | ||
help="vasprun.xml file to plot", | ||
default=None, | ||
metavar="F", | ||
) | ||
parser.add_argument( | ||
"-c", | ||
"--code", | ||
default="vasp", | ||
metavar="C", | ||
help=('Input file format: "vasp" (vasprun.xml) or ' '"questaal" (opt.ext)'), | ||
help=( | ||
'Input file format: "vasp" (vasprun.xml) or ' '"questaal" (opt.ext)' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More absurdity from linters. This should be a single string. |
||
), | ||
) | ||
parser.add_argument( | ||
"-p", "--prefix", metavar="P", help="prefix for the files generated" | ||
|
@@ -449,7 +463,10 @@ def _get_parser(): | |
"--orbitals", | ||
type=_el_orb, | ||
metavar="O", | ||
help=("orbitals to split into lm-decomposed " 'contributions (e.g. "Ru.d")'), | ||
help=( | ||
"orbitals to split into lm-decomposed " | ||
'contributions (e.g. "Ru.d")' | ||
), | ||
) | ||
parser.add_argument( | ||
"-a", | ||
|
@@ -500,7 +517,10 @@ def _get_parser(): | |
), | ||
) | ||
parser.add_argument( | ||
"--no-legend", action="store_false", dest="legend", help="hide the plot legend" | ||
"--no-legend", | ||
action="store_false", | ||
dest="legend", | ||
help="hide the plot legend", | ||
) | ||
parser.add_argument( | ||
"--legend-frame", | ||
|
@@ -540,7 +560,9 @@ def _get_parser(): | |
parser.add_argument( | ||
"--height", type=float, default=None, help="height of the graph" | ||
) | ||
parser.add_argument("--width", type=float, default=None, help="width of the graph") | ||
parser.add_argument( | ||
"--width", type=float, default=None, help="width of the graph" | ||
) | ||
parser.add_argument( | ||
"--xmin", type=float, default=-6.0, help="minimum energy on the x-axis" | ||
) | ||
|
@@ -570,7 +592,10 @@ def _get_parser(): | |
help="x-axis (i.e. energy) label/units", | ||
) | ||
parser.add_argument( | ||
"--ylabel", type=str, default="DOS", help="y-axis (i.e. DOS) label/units" | ||
"--ylabel", | ||
type=str, | ||
default="DOS", | ||
help="y-axis (i.e. DOS) label/units", | ||
) | ||
parser.add_argument( | ||
"--yscale", type=float, default=1, help="scaling factor for the y-axis" | ||
|
@@ -609,16 +634,18 @@ def main(): | |
logging.getLogger("").addHandler(console) | ||
|
||
if args.config is None: | ||
config_path = resource_filename( | ||
Requirement.parse("sumo"), "sumo/plotting/orbital_colours.conf" | ||
config_path = os.path.join( | ||
ilr_files("sumo.plotting"), "orbital_colours.conf" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, I think the |
||
) | ||
else: | ||
config_path = args.config | ||
colours = configparser.ConfigParser() | ||
colours.read(os.path.abspath(config_path)) | ||
|
||
warnings.filterwarnings("ignore", category=UserWarning, module="matplotlib") | ||
warnings.filterwarnings("ignore", category=UnicodeWarning, module="matplotlib") | ||
warnings.filterwarnings( | ||
"ignore", category=UnicodeWarning, module="matplotlib" | ||
) | ||
warnings.filterwarnings("ignore", category=UserWarning, module="pymatgen") | ||
|
||
if args.zero_energy is not None: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what is going on with the linting here.
Obviously a human would never have written the existing version. Did some other auto-linter remove the line-break? And if so, did it break PEP8 in the process? @utf any idea?
This is why I dislike auto-formatters...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the blame, and indeed this was ruined by
black
. The original version was