From 0553d82475796d15ef2156baa6a3ddf112d051ba Mon Sep 17 00:00:00 2001 From: anaik Date: Sun, 22 Oct 2023 18:32:09 +0200 Subject: [PATCH 01/11] refactor cli.py for cleaner options on cli help --- lobsterpy/cli.py | 296 ++++++++++++++++++++++++++++------------------- 1 file changed, 176 insertions(+), 120 deletions(-) diff --git a/lobsterpy/cli.py b/lobsterpy/cli.py index 76ce83e8..7fc677b4 100644 --- a/lobsterpy/cli.py +++ b/lobsterpy/cli.py @@ -36,10 +36,26 @@ def get_parser() -> argparse.ArgumentParser: description="Analyze and plot results from Lobster runs." ) - # Arguments common to all actions - input_parent = argparse.ArgumentParser(add_help=False) - input_file_group = input_parent.add_argument_group("Input files") - input_file_group.add_argument( + # Arguments that are needed by different actions, but not always + + incar_file = argparse.ArgumentParser(add_help=False) + incar_file.add_argument( + "--incar", + default="INCAR", + type=Path, + help='path to INCAR. Default is "INCAR".', + ) + + charge_file = argparse.ArgumentParser(add_help=False) + charge_file.add_argument( + "--charge", + default="CHARGE.lobster", + type=Path, + help='path to CHARGE.lobster. Default is "CHARGE.lobster"', + ) + + structure_file = argparse.ArgumentParser(add_help=False) + structure_file.add_argument( "--poscar", "--POSCAR", dest="poscar", @@ -47,80 +63,82 @@ def get_parser() -> argparse.ArgumentParser: type=Path, help='path to POSCAR. Default is "POSCAR"', ) - input_file_group.add_argument( - "--charge", - default="CHARGE.lobster", + + potcar_file = argparse.ArgumentParser(add_help=False) + potcar_file.add_argument( + "--potcar", + default="POTCAR", type=Path, - help='path to CHARGE.lobster. Default is "CHARGE.lobster"', + help='path to POTCAR. Default is "POTCAR".', ) - input_file_group.add_argument( + + icohplist_file = argparse.ArgumentParser(add_help=False) + icohplist_file.add_argument( "--icohplist", default="ICOHPLIST.lobster", type=Path, help='path to ICOHPLIST.lobster. Default is "ICOHPLIST.lobster"', ) - input_file_group.add_argument( + + coxxcar_file = argparse.ArgumentParser(add_help=False) + coxxcar_file.add_argument( "--cohpcar", default="COHPCAR.lobster", type=Path, help='path to COHPCAR.lobster. Default is "COHPCAR.lobster". This argument' "will also be read when COBICARs or COOPCARs are plotted.", ) - input_file_group.add_argument( - "--incar", - default="INCAR", + + doscar_file = argparse.ArgumentParser(add_help=False) + doscar_file.add_argument( + "--doscar", + default="DOSCAR.lobster", type=Path, - help='path to INCAR. Default is "INCAR".', + help='path to DOSCAR.lobster. Default is "DOSCAR.lobster".', ) - input_file_group.add_argument( - "--potcar", - default="POTCAR", - type=Path, - help='path to POTCAR. Default is "POTCAR".', + + # groups of arguments for specific actions + + calc_quality_description_file_parent = argparse.ArgumentParser(add_help=False) + + calc_quality_description_file_group = ( + calc_quality_description_file_parent.add_argument_group( + "Input args for specifically needed for calculation quality description" + ) ) - input_file_group.add_argument( + calc_quality_description_file_group.add_argument( "--potcar-symbols", dest="potcarsymbols", type=_potcar_symbols, # nargs="+", help="List of potcar symbols", ) - - input_file_group.add_argument( - "--lobsterin", - default="lobsterin", - type=Path, - help='path to lobsterin. Default is "lobsterin".', - ) - - input_file_group.add_argument( - "--lobsterout", - default="lobsterout", - type=Path, - help='path to lobsterout. Default is "lobsterout".', - ) - - input_file_group.add_argument( - "--doscar", - default="DOSCAR.lobster", - type=Path, - help='path to DOSCAR.lobster. Default is "DOSCAR.lobster".', - ) - - input_file_group.add_argument( + calc_quality_description_file_group.add_argument( "--vasprun", default="vasprun.xml", type=Path, help='path to vasprun.xml. Default is "vasprun.xml".', ) - - input_file_group.add_argument( + calc_quality_description_file_group.add_argument( "--bandoverlaps", default="bandOverlaps.lobster", type=Path, help='path to bandOverlaps.lobster. Default is "bandOverlaps.lobster".', ) + calc_quality_description_file_group.add_argument( + "--lobsterin", + default="lobsterin", + type=Path, + help='path to lobsterin. Default is "lobsterin".', + ) + calc_quality_description_file_group.add_argument( + "--lobsterout", + default="lobsterout", + type=Path, + help='path to lobsterout. Default is "lobsterout".', + ) + # group of arguments related to writing LOBSTER calcs inputs output_parent = argparse.ArgumentParser(add_help=False) output_file_group = output_parent.add_argument_group("Output files") output_file_group.add_argument( @@ -158,38 +176,16 @@ def get_parser() -> argparse.ArgumentParser: "(e.g., --userbasis Cr.3d.3p.4s N.2s.2p). Default is None.", ) + # General matplotlib plotting arguments common to all kinds of plots + plotting_parent = argparse.ArgumentParser(add_help=False) plotting_group = plotting_parent.add_argument_group("Plotting") - - broadening_group = plotting_group.add_mutually_exclusive_group() - broadening_group.add_argument_group("Broadening") - broadening_group.add_argument( - "--sigma", - type=float, - default=None, - help="Standard deviation of Gaussian broadening.", - ) - - broadening_group.add_argument( - "--fwhm", - type=float, - default=None, - help="Full-width-half-maximum of Gaussian broadening.", - ) - - plotting_group.add_argument( - "--integrated", - action="store_true", - help="Show integrated cohp/cobi/coop plots.", - ) - plotting_group.add_argument( "--hideplot", "--hide-plot", action="store_true", help="Will hide plots generated by automaticplot/auto-plot/autoplot/plot args", ) - plotting_group.add_argument( "--ylim", dest="ylim", @@ -206,7 +202,6 @@ def get_parser() -> argparse.ArgumentParser: type=float, help="COHP/COBI/COOP range for plots", ) - plotting_group.add_argument( "--style", type=str, @@ -244,26 +239,31 @@ def get_parser() -> argparse.ArgumentParser: plotting_group.add_argument( "--fontsize", "--font-size", type=float, default=None, help="Base font size" ) - group = plotting_group.add_mutually_exclusive_group() - group.add_argument( - "--spddos", - "--spd-dos", - action="store_true", - help="Will add spd projected dos to the DOS plot", + broadening_group = plotting_group.add_mutually_exclusive_group() + broadening_group.add_argument_group("Broadening") + broadening_group.add_argument( + "--sigma", + type=float, + default=None, + help="Standard deviation of Gaussian broadening.", ) - group.add_argument( - "--elementdos", - "--el-dos", - action="store_true", - help="Will add DOS projections for each element to the DOS plot", + broadening_group.add_argument( + "--fwhm", + type=float, + default=None, + help="Full-width-half-maximum of Gaussian broadening.", ) - plotting_group.add_argument( + + # Group pf arguments specific to dos plotter + dos_plotting_parent = argparse.ArgumentParser(add_help=False) + dos_plotting_group = dos_plotting_parent.add_argument_group("Plotting") + dos_plotting_group.add_argument( "--summedspins", "--summed-spins", action="store_true", help="Will plot summed DOS", ) - plotting_group.add_argument( + dos_plotting_group.add_argument( "--element", "--el", type=str, @@ -271,7 +271,7 @@ def get_parser() -> argparse.ArgumentParser: default=None, help="Will add spd DOS projections for requested element to the DOS plot", ) - plotting_group.add_argument( + dos_plotting_group.add_argument( "--orbital", "--orb", type=str, @@ -279,14 +279,33 @@ def get_parser() -> argparse.ArgumentParser: default=None, help="Orbital name for the site for which DOS are to be added", ) - plotting_group.add_argument( + dos_plotting_group.add_argument( "--site", type=int, nargs="+", default=None, help="Site index in the crystal structure for " "which DOS need to be added", ) - + dos_plotting_group.add_argument( + "--addtotaldos", + "--add-total-dos", + action="store_true", + help="Will all total dos to the DOS plot", + ) + group = dos_plotting_parent.add_mutually_exclusive_group() + group.add_argument( + "--spddos", + "--spd-dos", + action="store_true", + help="Will add spd projected dos to the DOS plot", + ) + group.add_argument( + "--elementdos", + "--el-dos", + action="store_true", + help="Will add DOS projections for each element to the DOS plot", + ) + # Argument common to COHPs / COOPs / COBIs or DOS plots advanced_plotting_args = argparse.ArgumentParser(add_help=False) advanced_plotting_args.add_argument( "--invertaxis", @@ -294,13 +313,14 @@ def get_parser() -> argparse.ArgumentParser: action="store_true", help="Will invert plot axis of DOS or COOPs COHPs or COBIS", ) - advanced_plotting_args.add_argument( - "--addtotaldos", - "--add-total-dos", + # Argument specific to COHPs / COOPs / COBIs plots + coxx_plotting_args = argparse.ArgumentParser(add_help=False) + coxx_plotting_args.add_argument( + "--integrated", action="store_true", - help="Will all total dos to the DOS plot", + help="Show integrated cohp/cobi/coop plots.", ) - + # Arguments for analysis cohp.analyze.Analysis class auto_parent = argparse.ArgumentParser(add_help=False) auto_group = auto_parent.add_argument_group("Automatic analysis") auto_group.add_argument( @@ -334,7 +354,7 @@ def get_parser() -> argparse.ArgumentParser: help="Only bonds that are stronger than cutoff_icoxx *strongest ICOHP " " (ICOBI or ICOOP) will be considered for automatic analysis.", ) - + # Argument that will help to switch automatic analysis analysis_switch = argparse.ArgumentParser(add_help=False) analysis_group = analysis_switch.add_argument_group( "Switch type of analysis or plots" @@ -353,12 +373,11 @@ def get_parser() -> argparse.ArgumentParser: help="This option will start automatic bonding analysis of COOPs or" " plot COOPs", ) - + # Specific to interactive plotter args interactive_plotter_args = argparse.ArgumentParser(add_help=False) interactive_plotter_group = interactive_plotter_args.add_argument_group( "Options specific to interactive plotter" ) - interactive_plotter_group.add_argument( "--labelresolved", "--label-resolved", @@ -367,8 +386,12 @@ def get_parser() -> argparse.ArgumentParser: "If not set, plots will consists of summed cohps. (This argument works only" "for interactive plots) ", ) - - auto_group.add_argument( + # Args specific to calc quality description dict and texts + calc_quality_args = argparse.ArgumentParser(add_help=False) + calc_quality_args_group = calc_quality_args.add_argument_group( + "Options specific to calculation quality description" + ) + calc_quality_args_group.add_argument( "--calcqualityjson", nargs="?", type=Path, @@ -377,8 +400,7 @@ def get_parser() -> argparse.ArgumentParser: const=Path("calc_quality_json.json"), help="Write a JSON file with the LOBSTER calc quality analysis", ) - - auto_group.add_argument( + calc_quality_args_group.add_argument( "--erange", dest="erange", nargs=2, @@ -386,31 +408,28 @@ def get_parser() -> argparse.ArgumentParser: type=int, help="Energy range for DOS comparisons", ) - - auto_group.add_argument( + calc_quality_args_group.add_argument( "--nbins", dest="nbins", default=None, type=int, help="Number of bins for DOS comparisons", ) - - auto_group.add_argument( + calc_quality_args_group.add_argument( "--doscomp", "--dos-comp", action="store_true", default=False, help="This option will force the DOS comparison in automatic LOBSTER calc quality analysis ", ) - - auto_group.add_argument( + calc_quality_args_group.add_argument( "--bvacomp", "--bva-comp", action="store_true", default=False, help="This option will force the BVA charge comparison in automatic LOBSTER calc quality analysis ", ) - + # Build the actions using arguments defined earlier subparsers = parser.add_subparsers( dest="action", required=True, @@ -418,7 +437,14 @@ def get_parser() -> argparse.ArgumentParser: ) subparsers.add_parser( "description", - parents=[input_parent, auto_parent, analysis_switch], + parents=[ + charge_file, + coxxcar_file, + structure_file, + icohplist_file, + auto_parent, + analysis_switch, + ], help=( "Deliver a text description of the COHPs or COBIS or COOP results from Lobster " "and VASP" @@ -426,7 +452,14 @@ def get_parser() -> argparse.ArgumentParser: ) subparsers.add_parser( "calc-description", - parents=[input_parent, auto_parent], + parents=[ + calc_quality_description_file_group, + charge_file, + doscar_file, + structure_file, + potcar_file, + calc_quality_args_group, + ], help=( "Deliver a text description of the LOBSTER calc quality analysis. " "Mandatory required files: POSCAR, POTCAR, lobsterout, lobsterin. " @@ -434,24 +467,35 @@ def get_parser() -> argparse.ArgumentParser: "(DOS comparison): DOSCAR.lobster, Vasprun.xml." ), ) - subparsers.add_parser( "automatic-plot", aliases=["automaticplot", "auto-plot", "autoplot"], - parents=[input_parent, auto_parent, plotting_parent, analysis_switch], + parents=[ + charge_file, + coxxcar_file, + structure_file, + icohplist_file, + auto_parent, + plotting_parent, + coxx_plotting_args, + analysis_switch, + ], help=( "Plot most important COHPs or COBIs or COOPs automatically." " This option also includes an automatic description." ), ) - subparsers.add_parser( "automatic-plot-ia", aliases=["automaticplotia", "autoplotia", "auto-plot-ia"], parents=[ - input_parent, + charge_file, + structure_file, + icohplist_file, + coxxcar_file, auto_parent, plotting_parent, + coxx_plotting_args, interactive_plotter_args, analysis_switch, ], @@ -459,42 +503,55 @@ def get_parser() -> argparse.ArgumentParser: "Creates an interactive plot of most important COHPs or COBIs or COOPs automatically." ), ) - subparsers.add_parser( "create-inputs", aliases=["createinputs"], - parents=[input_parent, output_parent], + parents=[incar_file, structure_file, potcar_file, output_parent], help=( "Will create inputs for lobster computation. It only works with PBE POTCARs." ), ) - subparsers.add_parser( "plot-dos", aliases=["plotdos"], - parents=[input_parent, plotting_parent, advanced_plotting_args], + parents=[ + doscar_file, + structure_file, + plotting_parent, + dos_plotting_parent, + advanced_plotting_args, + ], help=("Will plot DOS from lobster computation."), ) subparsers.add_parser( "plot-icohps-distances", aliases=["ploticohpsdistances"], - parents=[input_parent, plotting_parent, analysis_switch], + parents=[icohplist_file, plotting_parent, analysis_switch], help=("Will plot icohps with respect to bond lengths"), ) - # Mode for normal plotting (without automatic detection of relevant COHPs) plot_parser = subparsers.add_parser( "plot", - parents=[input_parent, plotting_parent, analysis_switch], + parents=[ + coxxcar_file, + structure_file, + plotting_parent, + analysis_switch, + advanced_plotting_args, + ], help="Plot specific COHPs/COBIs/COOPs based on bond numbers.", ) - plot_parser.add_argument( "bond_numbers", nargs="+", type=int, help="List of bond numbers, determining COHPs/COBIs/COOPs to include in plot.", ) + plot_parser.add_argument( + "--integrated", + action="store_true", + help="Show integrated cohp/cobi/coop plots.", + ) plot_grouping = plot_parser.add_mutually_exclusive_group() plot_grouping.add_argument( "--summed", @@ -578,7 +635,6 @@ def run(args): "auto-plot", "description", "automatic-plot", - "plot", "automatic-plot-ia", "interactplot", "automaticplotia", From 43761998255934f93c6b76be4d3d7ced10de8e6e Mon Sep 17 00:00:00 2001 From: anaik Date: Sun, 22 Oct 2023 18:50:16 +0200 Subject: [PATCH 02/11] fix mypy error --- lobsterpy/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lobsterpy/cli.py b/lobsterpy/cli.py index 7fc677b4..5ec43896 100644 --- a/lobsterpy/cli.py +++ b/lobsterpy/cli.py @@ -453,12 +453,12 @@ def get_parser() -> argparse.ArgumentParser: subparsers.add_parser( "calc-description", parents=[ - calc_quality_description_file_group, + calc_quality_description_file_parent, charge_file, doscar_file, structure_file, potcar_file, - calc_quality_args_group, + calc_quality_args, ], help=( "Deliver a text description of the LOBSTER calc quality analysis. " From fb6d821a7f6183697f5ea0ba96efe7d2f0ef6dd7 Mon Sep 17 00:00:00 2001 From: anaik Date: Tue, 24 Oct 2023 06:53:34 +0200 Subject: [PATCH 03/11] run black for linting error --- lobsterpy/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lobsterpy/cli.py b/lobsterpy/cli.py index 3b37d453..be06de97 100644 --- a/lobsterpy/cli.py +++ b/lobsterpy/cli.py @@ -370,7 +370,7 @@ def get_parser() -> argparse.ArgumentParser: "and only orbital interactions that are stronger than orbitalintcutoff * 100 of relevant " "bonds (ICOHP or ICOBI or ICOOP) will be considered in automatic analysis.", ) - + # Argument that will help to switch automatic analysis analysis_switch = argparse.ArgumentParser(add_help=False) analysis_group = analysis_switch.add_argument_group( @@ -411,7 +411,7 @@ def get_parser() -> argparse.ArgumentParser: "If used along with --labelresolved arg, plots will be further label resolved else," "plots will consists of summed orbital cohps. ", ) - + # Args specific to calc quality description dict and texts calc_quality_args = argparse.ArgumentParser(add_help=False) calc_quality_args_group = calc_quality_args.add_argument_group( From a7c616c88d7aaefeb8284c4df89a3de8c0c1b833 Mon Sep 17 00:00:00 2001 From: anaik Date: Tue, 24 Oct 2023 10:39:55 +0200 Subject: [PATCH 04/11] update help description, set default for plotdos arg, update test to check default plot-dos --- lobsterpy/cli.py | 83 ++++++++++++++++++++++++-------------- lobsterpy/test/test_cli.py | 8 ++++ 2 files changed, 60 insertions(+), 31 deletions(-) diff --git a/lobsterpy/cli.py b/lobsterpy/cli.py index be06de97..92f5a556 100644 --- a/lobsterpy/cli.py +++ b/lobsterpy/cli.py @@ -86,7 +86,8 @@ def get_parser() -> argparse.ArgumentParser: default="COHPCAR.lobster", type=Path, help='path to COHPCAR.lobster. Default is "COHPCAR.lobster". This argument' - "will also be read when COBICARs or COOPCARs are plotted.", + "can also read COBICARs or COOPCARs. One needs to use appropriate --cobis or " + "--coops options along with this argument when plotting", ) doscar_file = argparse.ArgumentParser(add_help=False) @@ -97,6 +98,18 @@ def get_parser() -> argparse.ArgumentParser: help='path to DOSCAR.lobster. Default is "DOSCAR.lobster".', ) + user_basis_arg = argparse.ArgumentParser(add_help=False) + user_basis_arg.add_argument( + "--userbasis", + "--user-basis", + default=None, + type=_element_basis, + nargs="+", + help="Setting this arg will use the specific basis provided by the user to " + "generate the inputs(e.g., --userbasis Cr.3d.3p.4s N.2s.2p). " + "Default is None.", + ) + # groups of arguments for specific actions calc_quality_description_file_parent = argparse.ArgumentParser(add_help=False) @@ -166,16 +179,6 @@ def get_parser() -> argparse.ArgumentParser: help="overwrites already created INCARs an lobsterins with the give name.", ) # TODO: Add some output arguments: options to supply your own basis - output_file_group.add_argument( - "--userbasis", - "--user-basis", - default=None, - type=_element_basis, - nargs="+", - help="This setting will rely on a specific basis provided by the user " - "(e.g., --userbasis Cr.3d.3p.4s N.2s.2p). Default is None.", - ) - # General matplotlib plotting arguments common to all kinds of plots plotting_parent = argparse.ArgumentParser(add_help=False) @@ -192,7 +195,7 @@ def get_parser() -> argparse.ArgumentParser: nargs=2, default=None, type=float, - help="Energy range for plots", + help="Set y-axis limits for the plots", ) plotting_group.add_argument( "--xlim", @@ -200,7 +203,7 @@ def get_parser() -> argparse.ArgumentParser: nargs=2, default=None, type=float, - help="COHP/COBI/COOP range for plots", + help="Set x-axis limits for the plots", ) plotting_group.add_argument( "--style", @@ -261,7 +264,7 @@ def get_parser() -> argparse.ArgumentParser: "--summedspins", "--summed-spins", action="store_true", - help="Will plot summed DOS", + help="Will plot summed spins DOS", ) dos_plotting_group.add_argument( "--element", @@ -320,7 +323,8 @@ def get_parser() -> argparse.ArgumentParser: action="store_true", help="Show integrated cohp/cobi/coop plots.", ) - # Arguments for analysis cohp.analyze.Analysis class + # Arguments specific to lobsterpy.cohp.analyze.Analysis and + # lobsterpy.cohp.describe.Description class auto_parent = argparse.ArgumentParser(add_help=False) auto_group = auto_parent.add_argument_group("Automatic analysis") auto_group.add_argument( @@ -374,21 +378,22 @@ def get_parser() -> argparse.ArgumentParser: # Argument that will help to switch automatic analysis analysis_switch = argparse.ArgumentParser(add_help=False) analysis_group = analysis_switch.add_argument_group( - "Switch type of analysis or plots" + "Switches type files analyzed for automatic analysis" + " (Also indicates file type for 'plot/plot-icohps-distances' action in cli)" ) analysis_group.add_argument( "--cobis", "--cobis", action="store_true", - help="This option will start automatic bonding analysis of COBIs or" - " plot COBIs", + help="Setting this option starts automatic bonding analysis using COBIs" + " (Also indicates plotter that input file contains COBI data)", ) analysis_group.add_argument( "--coops", "--coops", action="store_true", - help="This option will start automatic bonding analysis of COOPs or" - " plot COOPs", + help="Setting this option starts automatic bonding analysis using COOPs" + " (Also indicates plotter that input file contains COOP data)", ) # Specific to interactive plotter args interactive_plotter_args = argparse.ArgumentParser(add_help=False) @@ -400,16 +405,16 @@ def get_parser() -> argparse.ArgumentParser: "--label-resolved", action="store_true", help="Will create automatic interactive plots with all relevant bond labels. " - "If not set, plots will consists of summed cohps. (This argument works only" - "for interactive plots) ", + "If not set, plots will consists of summed cohps.", ) interactive_plotter_group.add_argument( "--orbitalplot", "--orbital-plot", action="store_true", - help="Will generate automatic interactive (I)COHP or (I)COBI or (I)COOP plots with all relevant orbitals " - "If used along with --labelresolved arg, plots will be further label resolved else," - "plots will consists of summed orbital cohps. ", + help="Will generate automatic interactive (I)COHP or (I)COBI or (I)COOP plots with all relevant orbitals" + "(Will work only when '--orbitalresolved' arg is set : i.e Orbital resolved analysis is switched on). " + "If used along with '--labelresolved' arg, plots will be further label resolved else," + "plots will consists of summed orbital cohps.", ) # Args specific to calc quality description dict and texts @@ -446,14 +451,14 @@ def get_parser() -> argparse.ArgumentParser: "--dos-comp", action="store_true", default=False, - help="This option will force the DOS comparison in automatic LOBSTER calc quality analysis ", + help="This option will enable the DOS comparison in automatic LOBSTER calc quality analysis ", ) calc_quality_args_group.add_argument( "--bvacomp", "--bva-comp", action="store_true", default=False, - help="This option will force the BVA charge comparison in automatic LOBSTER calc quality analysis ", + help="This option will enable the BVA charge comparison in automatic LOBSTER calc quality analysis ", ) # Build the actions using arguments defined earlier subparsers = parser.add_subparsers( @@ -490,7 +495,7 @@ def get_parser() -> argparse.ArgumentParser: "Deliver a text description of the LOBSTER calc quality analysis. " "Mandatory required files: POSCAR, POTCAR, lobsterout, lobsterin. " "Optional files (BVA comparison): CHARGE.lobster, " - "(DOS comparison): DOSCAR.lobster, Vasprun.xml." + "(DOS comparison): DOSCAR.lobster/ DOSCAR.LSO.lobster, Vasprun.xml." ), ) subparsers.add_parser( @@ -532,7 +537,13 @@ def get_parser() -> argparse.ArgumentParser: subparsers.add_parser( "create-inputs", aliases=["createinputs"], - parents=[incar_file, structure_file, potcar_file, output_parent], + parents=[ + incar_file, + structure_file, + potcar_file, + user_basis_arg, + output_parent, + ], help=( "Will create inputs for lobster computation. It only works with PBE POTCARs." ), @@ -547,13 +558,13 @@ def get_parser() -> argparse.ArgumentParser: dos_plotting_parent, advanced_plotting_args, ], - help=("Will plot DOS from lobster computation."), + help="Plots DOS from lobster computation.", ) subparsers.add_parser( "plot-icohps-distances", aliases=["ploticohpsdistances"], parents=[icohplist_file, plotting_parent, analysis_switch], - help=("Will plot icohps with respect to bond lengths"), + help="Will plot ICOHPs or ICOOPs or ICOBIs with respect to bond lengths", ) # Mode for normal plotting (without automatic detection of relevant COHPs) plot_parser = subparsers.add_parser( @@ -1173,6 +1184,16 @@ def run(args): dos_plotter.add_site_orbital_dos( site_index=site, orbital=orbital, dos=lobs_dos ) + elif ( + args.site is None + and not args.orbital + and not args.element + and not args.spddos + and not args.elementdos + and not args.addtotaldos + ): + dos_plotter.add_dos(dos=lobs_dos, label="Total DOS") + dos_plotter.add_dos_dict(dos_dict=lobs_dos.get_element_dos()) elif (args.site is None or not args.orbital) and ( not args.element and not args.spddos and not args.elementdos diff --git a/lobsterpy/test/test_cli.py b/lobsterpy/test/test_cli.py index c6631de1..8befd122 100644 --- a/lobsterpy/test/test_cli.py +++ b/lobsterpy/test/test_cli.py @@ -505,6 +505,14 @@ def test_dos_plot(self, tmp_path): test = get_parser().parse_args(args) run(test) + os.chdir(TestDir / "TestData/NaCl_comp_range") + args = [ + "plot-dos", + ] + + test = get_parser().parse_args(args) + run(test) + def test_cli_exceptions(self): # Calc files missing exception test with pytest.raises(ValueError) as err: From 7f7ca05e301d9d98f7f6110c3be432b59afda8d0 Mon Sep 17 00:00:00 2001 From: JaGeo Date: Tue, 24 Oct 2023 15:05:50 +0200 Subject: [PATCH 05/11] Fix input warning cli --- lobsterpy/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lobsterpy/cli.py b/lobsterpy/cli.py index 92f5a556..6a0541e7 100644 --- a/lobsterpy/cli.py +++ b/lobsterpy/cli.py @@ -967,7 +967,7 @@ def run(args): setattr(args, arg_name, gz_file_path) else: raise ValueError( - "Files necessary for creating puts for LOBSTER calcs not found in the current directory." + "Files necessary for creating inputs for LOBSTER calcs not found in the current directory." ) if args.userbasis is None: From 0dce1b683e3f6425709d896639b4ec3e4952ba5f Mon Sep 17 00:00:00 2001 From: JaGeo Date: Tue, 24 Oct 2023 15:35:53 +0200 Subject: [PATCH 06/11] unify language --- lobsterpy/cli.py | 57 ++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/lobsterpy/cli.py b/lobsterpy/cli.py index 6a0541e7..1278be9e 100644 --- a/lobsterpy/cli.py +++ b/lobsterpy/cli.py @@ -105,8 +105,8 @@ def get_parser() -> argparse.ArgumentParser: default=None, type=_element_basis, nargs="+", - help="Setting this arg will use the specific basis provided by the user to " - "generate the inputs(e.g., --userbasis Cr.3d.3p.4s N.2s.2p). " + help="Use the specific basis provided by the user to " + "generate the inputs (e.g., --userbasis Cr.3d.3p.4s N.2s.2p). " "Default is None.", ) @@ -160,7 +160,7 @@ def get_parser() -> argparse.ArgumentParser: dest="incarout", default="INCAR.lobsterpy", type=Path, - help='path to INCAR that will be generated by lobsterpy. Default is "INCAR.lobsterpy"', + help='path to INCAR that lobsterpy generates. Default is "INCAR.lobsterpy"', ) output_file_group.add_argument( "--lobsterin-out", @@ -168,7 +168,7 @@ def get_parser() -> argparse.ArgumentParser: dest="lobsterinout", default="lobsterin.lobsterpy", type=Path, - help='base for path to lobsterins that will be generated by lobsterpy. Default is "lobsterin.lobsterpy"', + help='Base for path to lobsterins that lobsterpy generates. Default is "lobsterin.lobsterpy"', ) output_file_group.add_argument( "--overwrite", @@ -187,7 +187,7 @@ def get_parser() -> argparse.ArgumentParser: "--hideplot", "--hide-plot", action="store_true", - help="Will hide plots generated by automaticplot/auto-plot/autoplot/plot args", + help="Hide plot output. Especially relevant when plots are saved.", ) plotting_group.add_argument( "--ylim", @@ -264,7 +264,7 @@ def get_parser() -> argparse.ArgumentParser: "--summedspins", "--summed-spins", action="store_true", - help="Will plot summed spins DOS", + help="Plot summed spins DOS", ) dos_plotting_group.add_argument( "--element", @@ -272,7 +272,7 @@ def get_parser() -> argparse.ArgumentParser: type=str, nargs="+", default=None, - help="Will add spd DOS projections for requested element to the DOS plot", + help="Add spd DOS projections for requested element to the DOS plot", ) dos_plotting_group.add_argument( "--orbital", @@ -293,20 +293,20 @@ def get_parser() -> argparse.ArgumentParser: "--addtotaldos", "--add-total-dos", action="store_true", - help="Will all total dos to the DOS plot", + help="Add total dos to DOS plot.", ) group = dos_plotting_parent.add_mutually_exclusive_group() group.add_argument( "--spddos", "--spd-dos", action="store_true", - help="Will add spd projected dos to the DOS plot", + help="Add spd projected dos to the DOS plot", ) group.add_argument( "--elementdos", "--el-dos", action="store_true", - help="Will add DOS projections for each element to the DOS plot", + help="Add DOS projections for each element to the DOS plot", ) # Argument common to COHPs / COOPs / COBIs or DOS plots advanced_plotting_args = argparse.ArgumentParser(add_help=False) @@ -314,7 +314,7 @@ def get_parser() -> argparse.ArgumentParser: "--invertaxis", "--invert-axis", action="store_true", - help="Will invert plot axis of DOS or COOPs COHPs or COBIS", + help="Invert plot axis of DOS or COOPs COHPs or COBIS", ) # Argument specific to COHPs / COOPs / COBIs plots coxx_plotting_args = argparse.ArgumentParser(add_help=False) @@ -341,8 +341,8 @@ def get_parser() -> argparse.ArgumentParser: "--all-bonds", action="store_true", default=False, - help="This option will force the automatc analysis to consider" - " all bonds, not only cation-anion bonds (default) ", + help="Consider all bonds during the automatic analysis," + " not only cation-anion bonds (default) ", ) auto_group.add_argument( "--noisecutoff", @@ -355,24 +355,23 @@ def get_parser() -> argparse.ArgumentParser: "--cutofficohp", type=float, default=0.1, - help="Only bonds that are stronger than cutoff_icoxx *strongest ICOHP " - " (ICOBI or ICOOP) will be considered for automatic analysis.", + help="Consider only bonds that are stronger than cutoff_icoxx *strongest ICOHP " + " (ICOBI or ICOOP) for automatic analysis.", ) auto_group.add_argument( "--orbitalresolved", "--orbital-resolved", action="store_true", default=False, - help="Will switch on orbital resolved analysis of (I)COHPs or (I)COBIs or (I)COOPs with all relevant orbitals.", + help="Switch on orbital resolved analysis of (I)COHPs or (I)COBIs or (I)COOPs with all relevant orbitals.", ) auto_group.add_argument( "--orbitalcutoff", "--orbital-cutoff", type=float, default=0.05, - help="Will only work when orbital wise analysis is switched on (--orbitalresolved) " - "and only orbital interactions that are stronger than orbitalintcutoff * 100 of relevant " - "bonds (ICOHP or ICOBI or ICOOP) will be considered in automatic analysis.", + help="Consider only orbital interactions that are stronger than orbitalintcutoff * 100 of relevant bonds (ICOHP or ICOBI or ICOOP)." + "Can only be used in combination with orbital-resolved automatic analysis (--orbitalresolved).", ) # Argument that will help to switch automatic analysis @@ -404,17 +403,17 @@ def get_parser() -> argparse.ArgumentParser: "--labelresolved", "--label-resolved", action="store_true", - help="Will create automatic interactive plots with all relevant bond labels. " - "If not set, plots will consists of summed cohps.", + help="Create automatic interactive plots with all relevant bond labels. " + "If not set, plots consist of summed cohps.", ) interactive_plotter_group.add_argument( "--orbitalplot", "--orbital-plot", action="store_true", - help="Will generate automatic interactive (I)COHP or (I)COBI or (I)COOP plots with all relevant orbitals" - "(Will work only when '--orbitalresolved' arg is set : i.e Orbital resolved analysis is switched on). " - "If used along with '--labelresolved' arg, plots will be further label resolved else," - "plots will consists of summed orbital cohps.", + help="Generate automatic interactive (I)COHP or (I)COBI or (I)COOP plots with all relevant orbitals" + "(Works only when '--orbitalresolved' arg is set : i.e Orbital resolved analysis is switched on). " + "If used along with '--labelresolved' arg, the plots are label resolved." + "Otherwise, the plots consist of summed orbital-resolved cohps.", ) # Args specific to calc quality description dict and texts @@ -451,14 +450,14 @@ def get_parser() -> argparse.ArgumentParser: "--dos-comp", action="store_true", default=False, - help="This option will enable the DOS comparison in automatic LOBSTER calc quality analysis ", + help="Enable the DOS comparison in automatic LOBSTER calc quality analysis ", ) calc_quality_args_group.add_argument( "--bvacomp", "--bva-comp", action="store_true", default=False, - help="This option will enable the BVA charge comparison in automatic LOBSTER calc quality analysis ", + help="Enable the BVA charge comparison in automatic LOBSTER calc quality analysis ", ) # Build the actions using arguments defined earlier subparsers = parser.add_subparsers( @@ -545,7 +544,7 @@ def get_parser() -> argparse.ArgumentParser: output_parent, ], help=( - "Will create inputs for lobster computation. It only works with PBE POTCARs." + "Create inputs for lobster computation. It works only with PBE POTCARs." ), ) subparsers.add_parser( @@ -564,7 +563,7 @@ def get_parser() -> argparse.ArgumentParser: "plot-icohps-distances", aliases=["ploticohpsdistances"], parents=[icohplist_file, plotting_parent, analysis_switch], - help="Will plot ICOHPs or ICOOPs or ICOBIs with respect to bond lengths", + help="Plot ICOHPs or ICOOPs or ICOBIs with respect to bond lengths", ) # Mode for normal plotting (without automatic detection of relevant COHPs) plot_parser = subparsers.add_parser( From aa9181ce722dc0febb840af4b61b8e720ea367dd Mon Sep 17 00:00:00 2001 From: anaik Date: Tue, 24 Oct 2023 16:41:20 +0200 Subject: [PATCH 07/11] linting fix --- lobsterpy/cli.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lobsterpy/cli.py b/lobsterpy/cli.py index 1278be9e..5ff92578 100644 --- a/lobsterpy/cli.py +++ b/lobsterpy/cli.py @@ -370,8 +370,9 @@ def get_parser() -> argparse.ArgumentParser: "--orbital-cutoff", type=float, default=0.05, - help="Consider only orbital interactions that are stronger than orbitalintcutoff * 100 of relevant bonds (ICOHP or ICOBI or ICOOP)." - "Can only be used in combination with orbital-resolved automatic analysis (--orbitalresolved).", + help="Consider only orbital interactions that are stronger than orbitalintcutoff * 100 of " + "relevant bonds (ICOHP or ICOBI or ICOOP). Can only be used in combination " + "with orbital-resolved automatic analysis (--orbitalresolved).", ) # Argument that will help to switch automatic analysis @@ -543,9 +544,7 @@ def get_parser() -> argparse.ArgumentParser: user_basis_arg, output_parent, ], - help=( - "Create inputs for lobster computation. It works only with PBE POTCARs." - ), + help="Create inputs for lobster computation. It works only with PBE POTCARs.", ) subparsers.add_parser( "plot-dos", From 5e3ead37ef2372bd3e59409b55615177b22b0bc2 Mon Sep 17 00:00:00 2001 From: anaik Date: Thu, 26 Oct 2023 12:29:45 +0200 Subject: [PATCH 08/11] rename args, aplhabetical order, update tests --- lobsterpy/cli.py | 416 +++++++++++++++++++------------------ lobsterpy/test/test_cli.py | 59 +++--- 2 files changed, 251 insertions(+), 224 deletions(-) diff --git a/lobsterpy/cli.py b/lobsterpy/cli.py index 5ff92578..b99f2c84 100644 --- a/lobsterpy/cli.py +++ b/lobsterpy/cli.py @@ -12,6 +12,7 @@ from pathlib import Path import matplotlib.style +from monty.os.path import zpath from pymatgen.electronic_structure.cohp import CompleteCohp from pymatgen.io.lobster import Icohplist from lobsterpy.cohp.analyze import Analysis @@ -40,50 +41,54 @@ def get_parser() -> argparse.ArgumentParser: incar_file = argparse.ArgumentParser(add_help=False) incar_file.add_argument( - "--incar", + "--file-incar", default="INCAR", + dest="incar", type=Path, help='path to INCAR. Default is "INCAR".', ) charge_file = argparse.ArgumentParser(add_help=False) charge_file.add_argument( - "--charge", + "--file-charge", default="CHARGE.lobster", + dest="charge", type=Path, help='path to CHARGE.lobster. Default is "CHARGE.lobster"', ) structure_file = argparse.ArgumentParser(add_help=False) structure_file.add_argument( - "--poscar", - "--POSCAR", - dest="poscar", + "--file-structure", default="POSCAR", + dest="structure", type=Path, - help='path to POSCAR. Default is "POSCAR"', + help='path to structure file. Default is "POSCAR"', ) potcar_file = argparse.ArgumentParser(add_help=False) potcar_file.add_argument( - "--potcar", + "--file-potcar", default="POTCAR", + dest="potcar", type=Path, help='path to POTCAR. Default is "POTCAR".', ) icohplist_file = argparse.ArgumentParser(add_help=False) icohplist_file.add_argument( - "--icohplist", + "--file-icohplist", default="ICOHPLIST.lobster", + dest="icohplist", type=Path, help='path to ICOHPLIST.lobster. Default is "ICOHPLIST.lobster"', ) coxxcar_file = argparse.ArgumentParser(add_help=False) coxxcar_file.add_argument( - "--cohpcar", + "--file-cohpcar", default="COHPCAR.lobster", + dest="cohpcar", type=Path, help='path to COHPCAR.lobster. Default is "COHPCAR.lobster". This argument' "can also read COBICARs or COOPCARs. One needs to use appropriate --cobis or " @@ -92,8 +97,9 @@ def get_parser() -> argparse.ArgumentParser: doscar_file = argparse.ArgumentParser(add_help=False) doscar_file.add_argument( - "--doscar", + "--file-doscar", default="DOSCAR.lobster", + dest="doscar", type=Path, help='path to DOSCAR.lobster. Default is "DOSCAR.lobster".', ) @@ -114,59 +120,60 @@ def get_parser() -> argparse.ArgumentParser: calc_quality_description_file_parent = argparse.ArgumentParser(add_help=False) + # Input args for specifically needed for calculation quality description calc_quality_description_file_group = ( - calc_quality_description_file_parent.add_argument_group( - "Input args for specifically needed for calculation quality description" - ) - ) - calc_quality_description_file_group.add_argument( - "--potcar-symbols", - dest="potcarsymbols", - type=_potcar_symbols, - # nargs="+", - help="List of potcar symbols", + calc_quality_description_file_parent.add_argument_group() ) calc_quality_description_file_group.add_argument( - "--vasprun", + "--file-vasprun", default="vasprun.xml", + dest="vasprun", type=Path, help='path to vasprun.xml. Default is "vasprun.xml".', ) calc_quality_description_file_group.add_argument( - "--bandoverlaps", + "--file-bandoverlaps", default="bandOverlaps.lobster", + dest="bandoverlaps", type=Path, help='path to bandOverlaps.lobster. Default is "bandOverlaps.lobster".', ) calc_quality_description_file_group.add_argument( - "--lobsterin", + "--file-lobsterin", default="lobsterin", + dest="lobsterin", type=Path, help='path to lobsterin. Default is "lobsterin".', ) calc_quality_description_file_group.add_argument( - "--lobsterout", + "--file-lobsterout", default="lobsterout", + dest="lobsterout", type=Path, help='path to lobsterout. Default is "lobsterout".', ) + calc_quality_description_file_group.add_argument( + "--potcar-symbols", + dest="potcarsymbols", + type=_potcar_symbols, + # nargs="+", + help="List of potcar symbols", + ) # group of arguments related to writing LOBSTER calcs inputs output_parent = argparse.ArgumentParser(add_help=False) output_file_group = output_parent.add_argument_group("Output files") output_file_group.add_argument( - "--incar-out", - "--incarout", - dest="incarout", + "--file-incar-out", default="INCAR.lobsterpy", + dest="incarout", type=Path, help='path to INCAR that lobsterpy generates. Default is "INCAR.lobsterpy"', ) output_file_group.add_argument( - "--lobsterin-out", - "--lobsterinout", - dest="lobsterinout", + "--file-lobsterin-out", default="lobsterin.lobsterpy", + dest="lobsterinout", type=Path, help='Base for path to lobsterins that lobsterpy generates. Default is "lobsterin.lobsterpy"', ) @@ -184,33 +191,16 @@ def get_parser() -> argparse.ArgumentParser: plotting_parent = argparse.ArgumentParser(add_help=False) plotting_group = plotting_parent.add_argument_group("Plotting") plotting_group.add_argument( - "--hideplot", - "--hide-plot", - action="store_true", - help="Hide plot output. Especially relevant when plots are saved.", - ) - plotting_group.add_argument( - "--ylim", - dest="ylim", - nargs=2, - default=None, - type=float, - help="Set y-axis limits for the plots", + "--fontsize", "--font-size", type=float, default=None, help="Base font size" ) plotting_group.add_argument( - "--xlim", - dest="xlim", - nargs=2, - default=None, - type=float, - help="Set x-axis limits for the plots", + "--height", type=float, default=None, help="Plot height in inches" ) plotting_group.add_argument( - "--style", - type=str, - nargs="+", - default=None, - help="Matplotlib style sheet(s) for plot appearance", + "--hideplot", + "--hide-plot", + action="store_true", + help="Hide plot output. Especially relevant when plots are saved.", ) plotting_group.add_argument( "--no-base-style", @@ -222,7 +212,13 @@ def get_parser() -> argparse.ArgumentParser: "stylesheets when using --style." ), ) - plotting_group.add_argument("--title", type=str, default="", help="Plot title") + plotting_group.add_argument( + "--style", + type=str, + nargs="+", + default=None, + help="Matplotlib style sheet(s) for plot appearance", + ) plotting_group.add_argument( "--save-plot", "--saveplot", @@ -233,38 +229,48 @@ def get_parser() -> argparse.ArgumentParser: dest="save_plot", help="Save plot to file", ) + plotting_group.add_argument("--title", type=str, default="", help="Plot title") plotting_group.add_argument( "--width", type=float, default=None, help="Plot width in inches" ) plotting_group.add_argument( - "--height", type=float, default=None, help="Plot height in inches" + "--xlim", + dest="xlim", + nargs=2, + default=None, + type=float, + help="Set x-axis limits for the plots", ) plotting_group.add_argument( - "--fontsize", "--font-size", type=float, default=None, help="Base font size" + "--ylim", + dest="ylim", + nargs=2, + default=None, + type=float, + help="Set y-axis limits for the plots", ) broadening_group = plotting_group.add_mutually_exclusive_group() broadening_group.add_argument_group("Broadening") broadening_group.add_argument( - "--sigma", + "--fwhm", type=float, default=None, - help="Standard deviation of Gaussian broadening.", + help="Full-width-half-maximum of Gaussian broadening.", ) broadening_group.add_argument( - "--fwhm", + "--sigma", type=float, default=None, - help="Full-width-half-maximum of Gaussian broadening.", + help="Standard deviation of Gaussian broadening.", ) - # Group pf arguments specific to dos plotter dos_plotting_parent = argparse.ArgumentParser(add_help=False) dos_plotting_group = dos_plotting_parent.add_argument_group("Plotting") dos_plotting_group.add_argument( - "--summedspins", - "--summed-spins", + "--addtotaldos", + "--add-total-dos", action="store_true", - help="Plot summed spins DOS", + help="Add total dos to DOS plot.", ) dos_plotting_group.add_argument( "--element", @@ -290,24 +296,25 @@ def get_parser() -> argparse.ArgumentParser: help="Site index in the crystal structure for " "which DOS need to be added", ) dos_plotting_group.add_argument( - "--addtotaldos", - "--add-total-dos", + "--summedspins", + "--summed-spins", action="store_true", - help="Add total dos to DOS plot.", + help="Plot summed spins DOS", ) + group = dos_plotting_parent.add_mutually_exclusive_group() - group.add_argument( - "--spddos", - "--spd-dos", - action="store_true", - help="Add spd projected dos to the DOS plot", - ) group.add_argument( "--elementdos", "--el-dos", action="store_true", help="Add DOS projections for each element to the DOS plot", ) + group.add_argument( + "--spddos", + "--spd-dos", + action="store_true", + help="Add spd projected dos to the DOS plot", + ) # Argument common to COHPs / COOPs / COBIs or DOS plots advanced_plotting_args = argparse.ArgumentParser(add_help=False) advanced_plotting_args.add_argument( @@ -326,15 +333,8 @@ def get_parser() -> argparse.ArgumentParser: # Arguments specific to lobsterpy.cohp.analyze.Analysis and # lobsterpy.cohp.describe.Description class auto_parent = argparse.ArgumentParser(add_help=False) - auto_group = auto_parent.add_argument_group("Automatic analysis") - auto_group.add_argument( - "--json", - nargs="?", - type=Path, - default=None, - metavar="FILENAME", - const=Path("lobsterpy.json"), - help="Write a JSON file with the most important information", + auto_group = auto_parent.add_argument_group( + "Adjustable automatic analysis parameters" ) auto_group.add_argument( "--allbonds", @@ -345,18 +345,27 @@ def get_parser() -> argparse.ArgumentParser: " not only cation-anion bonds (default) ", ) auto_group.add_argument( - "--noisecutoff", + "--cutofficohp", type=float, + default=0.1, + help="Consider only bonds that are stronger than cutoff_icoxx * strongest ICOXX " + " (ICOHP or ICOBI or ICOOP) for automatic analysis.", + ) + auto_group.add_argument( + "--file-json", + nargs="?", + type=Path, default=None, - help="Sets the lower limit of icohps or icoops or icobis considered in" - " automatic analysis", + metavar="FILENAME", + const=Path("lobsterpy.json"), + help="Write a JSON file with the most important information", ) auto_group.add_argument( - "--cutofficohp", + "--noisecutoff", type=float, - default=0.1, - help="Consider only bonds that are stronger than cutoff_icoxx *strongest ICOHP " - " (ICOBI or ICOOP) for automatic analysis.", + default=None, + help="Sets the lower limit of icohps or icoops or icobis considered in" + " automatic analysis", ) auto_group.add_argument( "--orbitalresolved", @@ -378,8 +387,8 @@ def get_parser() -> argparse.ArgumentParser: # Argument that will help to switch automatic analysis analysis_switch = argparse.ArgumentParser(add_help=False) analysis_group = analysis_switch.add_argument_group( - "Switches type files analyzed for automatic analysis" - " (Also indicates file type for 'plot/plot-icohps-distances' action in cli)" + "Arguments to switches type of files analyzed during automatic analysis" + " (Also indicates file type for 'plot/plot-icohp-distance' action in cli)" ) analysis_group.add_argument( "--cobis", @@ -420,16 +429,21 @@ def get_parser() -> argparse.ArgumentParser: # Args specific to calc quality description dict and texts calc_quality_args = argparse.ArgumentParser(add_help=False) calc_quality_args_group = calc_quality_args.add_argument_group( - "Options specific to calculation quality description" + "Options to change default output of quality description" ) calc_quality_args_group.add_argument( - "--calcqualityjson", - nargs="?", - type=Path, - default=None, - metavar="FILENAME", - const=Path("calc_quality_json.json"), - help="Write a JSON file with the LOBSTER calc quality analysis", + "--bvacomp", + "--bva-comp", + action="store_true", + default=False, + help="Enable the BVA charge comparison in automatic LOBSTER calc quality analysis ", + ) + calc_quality_args_group.add_argument( + "--doscomp", + "--dos-comp", + action="store_true", + default=False, + help="Enable the DOS comparison in automatic LOBSTER calc quality analysis ", ) calc_quality_args_group.add_argument( "--erange", @@ -439,6 +453,15 @@ def get_parser() -> argparse.ArgumentParser: type=int, help="Energy range for DOS comparisons", ) + calc_quality_args_group.add_argument( + "--file-calc-quality-json", + nargs="?", + type=Path, + default=None, + metavar="FILENAME", + const=Path("calc_quality_json.json"), + help="Write a JSON file with the LOBSTER calc quality analysis", + ) calc_quality_args_group.add_argument( "--nbins", dest="nbins", @@ -446,33 +469,31 @@ def get_parser() -> argparse.ArgumentParser: type=int, help="Number of bins for DOS comparisons", ) - calc_quality_args_group.add_argument( - "--doscomp", - "--dos-comp", - action="store_true", - default=False, - help="Enable the DOS comparison in automatic LOBSTER calc quality analysis ", - ) - calc_quality_args_group.add_argument( - "--bvacomp", - "--bva-comp", - action="store_true", - default=False, - help="Enable the BVA charge comparison in automatic LOBSTER calc quality analysis ", - ) # Build the actions using arguments defined earlier subparsers = parser.add_subparsers( dest="action", required=True, help="Use -h/--help after the chosen subcommand to see further options.", ) + subparsers.add_parser( + "create-inputs", + aliases=["createinputs"], + parents=[ + incar_file, + structure_file, + potcar_file, + user_basis_arg, + output_parent, + ], + help="Create inputs for lobster computation. It works only with PBE POTCARs.", + ) subparsers.add_parser( "description", parents=[ charge_file, coxxcar_file, - structure_file, icohplist_file, + structure_file, auto_parent, analysis_switch, ], @@ -482,13 +503,13 @@ def get_parser() -> argparse.ArgumentParser: ), ) subparsers.add_parser( - "calc-description", + "description-quality", parents=[ calc_quality_description_file_parent, charge_file, doscar_file, - structure_file, potcar_file, + structure_file, calc_quality_args, ], help=( @@ -499,13 +520,19 @@ def get_parser() -> argparse.ArgumentParser: ), ) subparsers.add_parser( - "automatic-plot", - aliases=["automaticplot", "auto-plot", "autoplot"], + "plot-automatic", + aliases=[ + "plot-auto", + "automatic-plot", + "automaticplot", + "auto-plot", + "autoplot", + ], parents=[ charge_file, coxxcar_file, - structure_file, icohplist_file, + structure_file, auto_parent, plotting_parent, coxx_plotting_args, @@ -517,13 +544,19 @@ def get_parser() -> argparse.ArgumentParser: ), ) subparsers.add_parser( - "automatic-plot-ia", - aliases=["automaticplotia", "autoplotia", "auto-plot-ia"], + "plot-automatic-ia", + aliases=[ + "plot-auto-ia", + "automatic-plot-ia", + "automaticplotia", + "autoplotia", + "auto-plot-ia", + ], parents=[ charge_file, - structure_file, - icohplist_file, coxxcar_file, + icohplist_file, + structure_file, auto_parent, plotting_parent, coxx_plotting_args, @@ -534,33 +567,21 @@ def get_parser() -> argparse.ArgumentParser: "Creates an interactive plot of most important COHPs or COBIs or COOPs automatically." ), ) - subparsers.add_parser( - "create-inputs", - aliases=["createinputs"], - parents=[ - incar_file, - structure_file, - potcar_file, - user_basis_arg, - output_parent, - ], - help="Create inputs for lobster computation. It works only with PBE POTCARs.", - ) subparsers.add_parser( "plot-dos", aliases=["plotdos"], parents=[ doscar_file, structure_file, - plotting_parent, dos_plotting_parent, advanced_plotting_args, + plotting_parent, ], help="Plots DOS from lobster computation.", ) subparsers.add_parser( - "plot-icohps-distances", - aliases=["ploticohpsdistances"], + "plot-icohp-distance", + aliases=["ploticohpdistance"], parents=[icohplist_file, plotting_parent, analysis_switch], help="Plot ICOHPs or ICOOPs or ICOBIs with respect to bond lengths", ) @@ -571,8 +592,8 @@ def get_parser() -> argparse.ArgumentParser: coxxcar_file, structure_file, plotting_parent, - analysis_switch, advanced_plotting_args, + analysis_switch, ], help="Plot specific COHPs/COBIs/COOPs based on bond numbers.", ) @@ -665,20 +686,23 @@ def run(args): """ if args.action in [ + "plot-automatic", + "plot-auto", + "automatic-plot", "automaticplot", "autoplot", "auto-plot", "description", - "automatic-plot", + "plot-automatic-ia", + "plot-auto-ia", "automatic-plot-ia", - "interactplot", "automaticplotia", "auto-plot-ia", "autoplotia", ]: # Check for .gz files exist for default values and update accordingly default_files = { - "poscar": "POSCAR", + "structure": "POSCAR", "charge": "CHARGE.lobster", "icohplist": "ICOHPLIST.lobster", "cohpcar": "COHPCAR.lobster", @@ -687,7 +711,7 @@ def run(args): for arg_name, _ in default_files.items(): file_path = getattr(args, arg_name) if not file_path.exists(): - gz_file_path = file_path.with_name(file_path.name + ".gz") + gz_file_path = file_path.with_name(zpath(file_path.name)) if gz_file_path.exists(): setattr(args, arg_name, gz_file_path) else: @@ -710,7 +734,7 @@ def run(args): setattr(args, arg_name, Path(file_name)) file_path = getattr(args, arg_name) if not file_path.exists(): - gz_file_path = file_path.with_name(file_path.name + ".gz") + gz_file_path = file_path.with_name(zpath(file_path.name)) if gz_file_path.exists(): setattr(args, arg_name, gz_file_path) else: @@ -733,7 +757,7 @@ def run(args): setattr(args, arg_name, Path(file_name)) file_path = getattr(args, arg_name) if not file_path.exists(): - gz_file_path = file_path.with_name(file_path.name + ".gz") + gz_file_path = file_path.with_name(zpath(file_path.name)) if gz_file_path.exists(): setattr(args, arg_name, gz_file_path) else: @@ -742,27 +766,32 @@ def run(args): " COBICAR.lobster) not found in the directory" ) - if args.action in ["automaticplot", "autoplot", "auto-plot"]: - args.action = "automatic-plot" - - if args.action in ["automaticplotia", "automatic-plot-ia", "auto-plot-ia"]: - args.action = "automaticplotia" - if args.action in [ - "description", + "plot-auto", "automatic-plot", + "automaticplot", + "auto-plot", + "autoplot", + ]: + args.action = "plot-automatic" + + if args.action in [ + "plot-auto-ia", "automatic-plot-ia", "automaticplotia", - "auto-plot-ia", "autoplotia", + "auto-plot-ia", ]: + args.action = "plot-automatic-ia" + + if args.action in ["description", "plot-automatic", "plot-automatic-ia"]: if args.allbonds: which_bonds = "all" else: which_bonds = "cation-anion" analyse = Analysis( - path_to_poscar=args.poscar, + path_to_poscar=args.structure, path_to_charge=args.charge, path_to_cohpcar=args.cohpcar, path_to_icohplist=args.icohplist, @@ -778,22 +807,19 @@ def run(args): describe = Description(analysis_object=analyse) describe.write_description() - if args.json is not None: + if args.file_json is not None: analysedict = analyse.condensed_bonding_analysis - with open(args.json, "w") as fd: + with open(args.file_json, "w") as fd: json.dump(analysedict, fd) if args.action in [ "plot", - "automatic-plot", - "automaticplotia", - "automatic-plot-ia", - "auto-plot-ia", - "autoplotia", + "plot-automatic", + "plot-automatic-ia", "plot-dos", "plotdos", - "plot-icohps-distances", - "ploticohpsdistances", + "plot-icohp-distance", + "ploticohpdistance", ]: style_kwargs = {} style_kwargs.update(_user_figsize(args.width, args.height)) @@ -812,7 +838,7 @@ def run(args): else: sigma = None - if args.action in ["automatic-plot"]: + if args.action in ["plot-automatic"]: describe.plot_cohps( ylim=args.ylim, xlim=args.xlim, @@ -824,12 +850,7 @@ def run(args): hide=args.hideplot, ) - if args.action in [ - "automatic-plot-ia", - "automaticplotia", - "auto-plot-ia", - "autoplotia", - ]: + if args.action in ["plot-automatic-ia"]: describe.plot_interactive_cohps( ylim=args.ylim, xlim=args.xlim, @@ -847,21 +868,21 @@ def run(args): if args.cobis: filename = args.cohpcar.parent / "COBICAR.lobster" if not filename.exists(): - filename = filename.with_name(filename.name + ".gz") + filename = filename.with_name(zpath(filename.name)) options = {"are_cobis": True, "are_coops": False} elif args.coops: filename = args.cohpcar.parent / "COOPCAR.lobster" if not filename.exists(): - filename = filename.with_name(filename.name + ".gz") + filename = filename.with_name(zpath(filename.name)) options = {"are_cobis": False, "are_coops": True} else: filename = args.cohpcar.parent / "COHPCAR.lobster" if not filename.exists(): - filename = filename.with_name(filename.name + ".gz") + filename = filename.with_name(zpath(filename.name)) options = {"are_cobis": False, "are_coops": False} completecohp = CompleteCohp.from_file( - fmt="LOBSTER", filename=filename, structure_file=args.poscar, **options + fmt="LOBSTER", filename=filename, structure_file=args.structure, **options ) cp = PlainCohpPlotter(**options) @@ -952,7 +973,7 @@ def run(args): # Check for .gz files exist for default values and update accordingly default_files = { - "poscar": "POSCAR", + "structure": "POSCAR", "potcar": "POTCAR", "incar": "INCAR", } @@ -960,7 +981,7 @@ def run(args): for arg_name, _ in default_files.items(): file_path = getattr(args, arg_name) if not file_path.exists(): - gz_file_path = file_path.with_name(file_path.name + ".gz") + gz_file_path = file_path.with_name(zpath(file_path.name)) if gz_file_path.exists(): setattr(args, arg_name, gz_file_path) else: @@ -974,12 +995,13 @@ def run(args): potcar_names = Lobsterin._get_potcar_symbols(POTCAR_input=args.potcar) list_basis_dict = Lobsterin.get_all_possible_basis_functions( - structure=Structure.from_file(args.poscar), potcar_symbols=potcar_names + structure=Structure.from_file(args.structure), + potcar_symbols=potcar_names, ) for ibasis, basis_dict in enumerate(list_basis_dict): lobsterinput = Lobsterin.standard_calculations_from_vasp_files( - args.poscar, + args.structure, args.incar, None, option="standard", @@ -996,7 +1018,7 @@ def run(args): lobsterinput.write_INCAR( incar_input=args.incar, incar_output=incar_path, - poscar_input=args.poscar, + poscar_input=args.structure, isym=0, ) else: @@ -1010,7 +1032,7 @@ def run(args): userbasis[userbasis_single[0]] = userbasis_single[1] lobsterinput = Lobsterin.standard_calculations_from_vasp_files( - args.poscar, + args.structure, args.incar, None, option="standard", @@ -1027,7 +1049,7 @@ def run(args): lobsterinput.write_INCAR( incar_input=args.incar, incar_output=incar_path, - poscar_input=args.poscar, + poscar_input=args.structure, isym=0, ) else: @@ -1035,10 +1057,10 @@ def run(args): 'please use "--overwrite" if you would like to overwrite existing lobster inputs' ) - if args.action in ["calc-description"]: + if args.action in ["description-quality"]: # Check for .gz files exist for default values and update accordingly mandatory_files = { - "poscar": "POSCAR", + "structure": "POSCAR", "lobsterin": "lobsterin", "lobsterout": "lobsterout", } @@ -1046,7 +1068,7 @@ def run(args): for arg_name, _ in mandatory_files.items(): file_path = getattr(args, arg_name) if not file_path.exists(): - gz_file_path = file_path.with_name(file_path.name + ".gz") + gz_file_path = file_path.with_name(zpath(file_path.name)) if gz_file_path.exists(): setattr(args, arg_name, gz_file_path) else: @@ -1062,7 +1084,7 @@ def run(args): for arg_name, _ in optional_file.items(): file_path = getattr(args, arg_name) if not file_path.exists(): - gz_file_path = file_path.with_name(file_path.name + ".gz") + gz_file_path = file_path.with_name(zpath(file_path.name)) if gz_file_path.exists(): setattr(args, arg_name, gz_file_path) @@ -1075,7 +1097,7 @@ def run(args): for arg_name, _ in bva_files.items(): file_path = getattr(args, arg_name) if not file_path.exists(): - gz_file_path = file_path.with_name(file_path.name + ".gz") + gz_file_path = file_path.with_name(zpath(file_path.name)) if gz_file_path.exists(): setattr(args, arg_name, gz_file_path) else: @@ -1094,7 +1116,7 @@ def run(args): for arg_name, _ in dos_files.items(): file_path = getattr(args, arg_name) if not file_path.exists(): - gz_file_path = file_path.with_name(file_path.name + ".gz") + gz_file_path = file_path.with_name(zpath(file_path.name)) if gz_file_path.exists(): setattr(args, arg_name, gz_file_path) else: @@ -1104,7 +1126,7 @@ def run(args): potcar_file_path = getattr(args, "potcar") quality_dict = Analysis.get_lobster_calc_quality_summary( - path_to_poscar=args.poscar, + path_to_poscar=args.structure, path_to_charge=args.charge, path_to_lobsterout=args.lobsterout, path_to_lobsterin=args.lobsterin, @@ -1122,20 +1144,20 @@ def run(args): quality_text = Description.get_calc_quality_description(quality_dict) Description.write_calc_quality_description(quality_text) - if args.calcqualityjson is not None: - with open(args.calcqualityjson, "w") as fd: + if args.file_calc_quality_json is not None: + with open(args.file_calc_quality_json, "w") as fd: json.dump(quality_dict, fd) if args.action in ["plot-dos", "plotdos"]: mandatory_files = { "doscar": "DOSCAR.lobster", - "poscar": "POSCAR", + "structure": "POSCAR", } for arg_name, _ in mandatory_files.items(): file_path = getattr(args, arg_name) if not file_path.exists(): - gz_file_path = file_path.with_name(file_path.name + ".gz") + gz_file_path = file_path.with_name(zpath(file_path.name)) if gz_file_path.exists(): setattr(args, arg_name, gz_file_path) else: @@ -1146,7 +1168,7 @@ def run(args): from pymatgen.io.lobster import Doscar - lobs_dos = Doscar(doscar=args.doscar, structure_file=args.poscar).completedos + lobs_dos = Doscar(doscar=args.doscar, structure_file=args.structure).completedos dos_plotter = PlainDosPlotter(summed=args.summedspins, sigma=args.sigma) if args.addtotaldos: @@ -1219,21 +1241,21 @@ def run(args): if args.save_plot and args.hideplot: plt.savefig(args.save_plot) - if args.action in ["plot-icohps-distances", "ploticohpsdistances"]: + if args.action in ["plot-icohp-distance", "ploticohpdistance"]: if args.cobis: filename = args.icohplist.parent / "ICOBILIST.lobster" if not filename.exists(): - filename = filename.with_name(filename.name + ".gz") + filename = filename.with_name(zpath(filename.name)) options = {"are_cobis": True, "are_coops": False} elif args.coops: filename = args.icohplist.parent / "ICOOPLIST.lobster" if not filename.exists(): - filename = filename.with_name(filename.name + ".gz") + filename = filename.with_name(zpath(filename.name)) options = {"are_cobis": False, "are_coops": True} else: filename = args.icohplist.parent / "ICOHPLIST.lobster" if not filename.exists(): - filename = filename.with_name(filename.name + ".gz") + filename = filename.with_name(zpath(filename.name)) options = {"are_cobis": False, "are_coops": False} icohpcollection = Icohplist(filename=filename, **options).icohpcollection diff --git a/lobsterpy/test/test_cli.py b/lobsterpy/test/test_cli.py index 8befd122..5131c56d 100644 --- a/lobsterpy/test/test_cli.py +++ b/lobsterpy/test/test_cli.py @@ -106,7 +106,7 @@ def test_plot_saved(self, tmp_path, inject_mocks, clean_plot): def test_json_saved(self, tmp_path, inject_mocks, clean_plot): json_path = tmp_path / "data.json" - args = ["automatic-plot", "--json", str(json_path)] + args = ["automatic-plot", "--file-json", str(json_path)] test = get_parser().parse_args(args) run(test) self.assert_is_finite_file(json_path) @@ -182,7 +182,7 @@ def test_cli_interactive_plotter_coops(self): def test_icohpplot_saved(self, tmp_path, inject_mocks, clean_plot): plot_path = tmp_path / "plot.png" - args = ["ploticohpsdistances", "--hideplot", "--saveplot", str(plot_path)] + args = ["ploticohpdistance", "--hideplot", "--saveplot", str(plot_path)] test = get_parser().parse_args(args) run(test) self.assert_is_finite_file(plot_path) @@ -193,9 +193,9 @@ def test_lobsterin_generation(self, tmp_path): INCARpath = tmp_path / "INCAR.lobsterpy" args = [ "create-inputs", - "--lobsterin-out", + "--file-lobsterin-out", str(lobsterinpath), - "--incar-out", + "--file-incar-out", str(INCARpath), ] test = get_parser().parse_args(args) @@ -215,9 +215,9 @@ def test_lobsterin_generation(self, tmp_path): INCARpath = tmp_path / "INCAR.lobsterpy" args = [ "createinputs", - "--lobsterin-out", + "--file-lobsterin-out", str(lobsterinpath), - "--incar-out", + "--file-incar-out", str(INCARpath), "--overwrite", ] @@ -232,9 +232,9 @@ def test_lobsterin_generation_error(self, tmp_path): INCARpath = tmp_path / "INCAR.lobsterpy" args = [ "create-inputs", - "--lobsterin-out", + "--file-lobsterin-out", str(lobsterinpath), - "--incar-out", + "--file-incar-out", str(INCARpath), ] test = get_parser().parse_args(args) @@ -249,9 +249,9 @@ def test_lobsterin_generation_error(self, tmp_path): args = [ "create-inputs", - "--lobsterin-out", + "--file-lobsterin-out", str(lobsterinpath), - "--incar-out", + "--file-incar-out", str(INCARpath), ] test = get_parser().parse_args(args) @@ -284,9 +284,9 @@ def test_lobsterin_generation_error_userbasis(self, tmp_path): INCARpath = tmp_path / "INCAR.lobsterpy" args = [ "create-inputs", - "--lobsterin-out", + "--file-lobsterin-out", str(lobsterinpath), - "--incar-out", + "--file-incar-out", str(INCARpath), "--userbasis", "Na.3s.3p Cl.3s.3p", @@ -309,7 +309,7 @@ def test_calc_quality_summary_NaCl(self, tmp_path): os.chdir(TestDir / "TestData/NaCl_comp_range") calc_quality_json_path = tmp_path / "calc_quality_json.json" args = [ - "calc-description", + "description-quality", "--potcar-symbols", "Na_pv Cl", "--bvacomp", @@ -317,7 +317,7 @@ def test_calc_quality_summary_NaCl(self, tmp_path): "--erange", "-20", "0", - "--calcqualityjson", + "--file-calc-quality-json", str(calc_quality_json_path), ] captured_output = io.StringIO() @@ -348,17 +348,17 @@ def test_calc_quality_summary_K3Sb(self, tmp_path): os.chdir(TestDir / "TestData/K3Sb") calc_quality_json_path = tmp_path / "calc_quality_json.json" args = [ - "calc-description", + "description-quality", "--bvacomp", "--potcar-symbols", "K_sv Sb", "--doscomp", - "--doscar", + "--file-doscar", "DOSCAR.LSO.lobster", "--erange", "-20", "0", - "--calcqualityjson", + "--file-calc-quality-json", str(calc_quality_json_path), ] captured_output = io.StringIO() @@ -393,7 +393,7 @@ def test_dos_plot(self, tmp_path): args = [ "plot-dos", "--spddos", - "--doscar", + "--file-doscar", "DOSCAR.LSO.lobster", "--sigma", "0.2", @@ -414,7 +414,7 @@ def test_dos_plot(self, tmp_path): args = [ "plot-dos", "--elementdos", - "--doscar", + "--file-doscar", "DOSCAR.LSO.lobster", "--ylim", "-5", @@ -431,7 +431,7 @@ def test_dos_plot(self, tmp_path): os.chdir(TestDir / "TestData/K3Sb") args = [ "plot-dos", - "--doscar", + "--file-doscar", "DOSCAR.LSO.lobster", "--element", "K", @@ -518,7 +518,7 @@ def test_cli_exceptions(self): with pytest.raises(ValueError) as err: os.chdir(TestDir) args = [ - "calc-description", + "description-quality", ] test = get_parser().parse_args(args) @@ -533,7 +533,7 @@ def test_cli_exceptions(self): with pytest.raises(ValueError) as err: os.chdir(TestDir / "TestData/NaCl") args = [ - "calc-description", + "description-quality", "--doscomp", ] @@ -548,7 +548,12 @@ def test_cli_exceptions(self): # BVA comparison exceptions test with pytest.raises(ValueError) as err: os.chdir(TestDir / "TestData/NaCl") - args = ["calc-description", "--bvacomp", "--charge", "../CHARGE.lobster"] + args = [ + "description-quality", + "--bvacomp", + "--file-charge", + "../CHARGE.lobster", + ] test = get_parser().parse_args(args) run(test) @@ -591,7 +596,7 @@ def test_cli_exceptions(self): os.chdir(TestDir / "TestData/K3Sb") args = [ "plot-dos", - "--doscar", + "--file-doscar", "DOSCAR.LSO.lobster", "--site", "1", @@ -615,7 +620,7 @@ def test_gz_file_cli(self, tmp_path, inject_mocks, clean_plot): # test autoplot and json generation fron gz input files json_path = tmp_path / "data.json" - args = ["automatic-plot", "--all-bonds", "--json", str(json_path)] + args = ["automatic-plot", "--all-bonds", "--file-json", str(json_path)] test = get_parser().parse_args(args) run(test) self.assert_is_finite_file(json_path) @@ -626,9 +631,9 @@ def test_gz_file_cli_lobsterinput_generation(self, tmp_path): INCARpath = tmp_path / "INCAR.lobsterpy" args = [ "create-inputs", - "--lobsterin-out", + "--file-lobsterin-out", str(lobsterinpath), - "--incar-out", + "--file-incar-out", str(INCARpath), "--userbasis", "Na.3s.3p Cl.3s.3p", From 925a8704494273926ab2926d6ccde14424986d32 Mon Sep 17 00:00:00 2001 From: anaik Date: Fri, 27 Oct 2023 13:51:29 +0200 Subject: [PATCH 09/11] add more options for cli.py --- lobsterpy/cli.py | 133 ++++++++++++++++++++++++++++++----------------- 1 file changed, 84 insertions(+), 49 deletions(-) diff --git a/lobsterpy/cli.py b/lobsterpy/cli.py index b99f2c84..20f1c06a 100644 --- a/lobsterpy/cli.py +++ b/lobsterpy/cli.py @@ -41,6 +41,7 @@ def get_parser() -> argparse.ArgumentParser: incar_file = argparse.ArgumentParser(add_help=False) incar_file.add_argument( + "-fincar", "--file-incar", default="INCAR", dest="incar", @@ -50,6 +51,7 @@ def get_parser() -> argparse.ArgumentParser: charge_file = argparse.ArgumentParser(add_help=False) charge_file.add_argument( + "-fcharge", "--file-charge", default="CHARGE.lobster", dest="charge", @@ -59,6 +61,7 @@ def get_parser() -> argparse.ArgumentParser: structure_file = argparse.ArgumentParser(add_help=False) structure_file.add_argument( + "-fstruct", "--file-structure", default="POSCAR", dest="structure", @@ -68,6 +71,7 @@ def get_parser() -> argparse.ArgumentParser: potcar_file = argparse.ArgumentParser(add_help=False) potcar_file.add_argument( + "-fpotcar", "--file-potcar", default="POTCAR", dest="potcar", @@ -77,6 +81,7 @@ def get_parser() -> argparse.ArgumentParser: icohplist_file = argparse.ArgumentParser(add_help=False) icohplist_file.add_argument( + "-ficohp", "--file-icohplist", default="ICOHPLIST.lobster", dest="icohplist", @@ -86,6 +91,7 @@ def get_parser() -> argparse.ArgumentParser: coxxcar_file = argparse.ArgumentParser(add_help=False) coxxcar_file.add_argument( + "-fcohp", "--file-cohpcar", default="COHPCAR.lobster", dest="cohpcar", @@ -97,6 +103,7 @@ def get_parser() -> argparse.ArgumentParser: doscar_file = argparse.ArgumentParser(add_help=False) doscar_file.add_argument( + "-fdos", "--file-doscar", default="DOSCAR.lobster", dest="doscar", @@ -125,6 +132,7 @@ def get_parser() -> argparse.ArgumentParser: calc_quality_description_file_parent.add_argument_group() ) calc_quality_description_file_group.add_argument( + "-fvasprun", "--file-vasprun", default="vasprun.xml", dest="vasprun", @@ -132,6 +140,7 @@ def get_parser() -> argparse.ArgumentParser: help='path to vasprun.xml. Default is "vasprun.xml".', ) calc_quality_description_file_group.add_argument( + "-fbandoverlap", "--file-bandoverlaps", default="bandOverlaps.lobster", dest="bandoverlaps", @@ -139,6 +148,7 @@ def get_parser() -> argparse.ArgumentParser: help='path to bandOverlaps.lobster. Default is "bandOverlaps.lobster".', ) calc_quality_description_file_group.add_argument( + "-flobsin", "--file-lobsterin", default="lobsterin", dest="lobsterin", @@ -146,6 +156,7 @@ def get_parser() -> argparse.ArgumentParser: help='path to lobsterin. Default is "lobsterin".', ) calc_quality_description_file_group.add_argument( + "-flobsout", "--file-lobsterout", default="lobsterout", dest="lobsterout", @@ -153,6 +164,7 @@ def get_parser() -> argparse.ArgumentParser: help='path to lobsterout. Default is "lobsterout".', ) calc_quality_description_file_group.add_argument( + "-potsymbols", "--potcar-symbols", dest="potcarsymbols", type=_potcar_symbols, @@ -164,6 +176,7 @@ def get_parser() -> argparse.ArgumentParser: output_parent = argparse.ArgumentParser(add_help=False) output_file_group = output_parent.add_argument_group("Output files") output_file_group.add_argument( + "-fincarout", "--file-incar-out", default="INCAR.lobsterpy", dest="incarout", @@ -171,6 +184,7 @@ def get_parser() -> argparse.ArgumentParser: help='path to INCAR that lobsterpy generates. Default is "INCAR.lobsterpy"', ) output_file_group.add_argument( + "-flobsinout", "--file-lobsterin-out", default="lobsterin.lobsterpy", dest="lobsterinout", @@ -191,18 +205,31 @@ def get_parser() -> argparse.ArgumentParser: plotting_parent = argparse.ArgumentParser(add_help=False) plotting_group = plotting_parent.add_argument_group("Plotting") plotting_group.add_argument( - "--fontsize", "--font-size", type=float, default=None, help="Base font size" + "-fs", + "--fontsize", + "--font-size", + type=float, + dest="fontsize", + default=None, + help="Base font size", ) plotting_group.add_argument( - "--height", type=float, default=None, help="Plot height in inches" + "-ht", + "--height", + type=float, + dest="height", + default=None, + help="Plot height in inches", ) plotting_group.add_argument( "--hideplot", "--hide-plot", + dest="hideplot", action="store_true", help="Hide plot output. Especially relevant when plots are saved.", ) plotting_group.add_argument( + "-nbs", "--no-base-style", "--nobasestyle", action="store_true", @@ -213,9 +240,11 @@ def get_parser() -> argparse.ArgumentParser: ), ) plotting_group.add_argument( + "-sty", "--style", type=str, nargs="+", + dest="style", default=None, help="Matplotlib style sheet(s) for plot appearance", ) @@ -231,9 +260,15 @@ def get_parser() -> argparse.ArgumentParser: ) plotting_group.add_argument("--title", type=str, default="", help="Plot title") plotting_group.add_argument( - "--width", type=float, default=None, help="Plot width in inches" + "-wd", + "--width", + type=float, + dest="width", + default=None, + help="Plot width in inches", ) plotting_group.add_argument( + "-x", "--xlim", dest="xlim", nargs=2, @@ -242,6 +277,7 @@ def get_parser() -> argparse.ArgumentParser: help="Set x-axis limits for the plots", ) plotting_group.add_argument( + "-y", "--ylim", dest="ylim", nargs=2, @@ -267,23 +303,26 @@ def get_parser() -> argparse.ArgumentParser: dos_plotting_parent = argparse.ArgumentParser(add_help=False) dos_plotting_group = dos_plotting_parent.add_argument_group("Plotting") dos_plotting_group.add_argument( + "-addtdos", "--addtotaldos", "--add-total-dos", action="store_true", help="Add total dos to DOS plot.", ) dos_plotting_group.add_argument( + "-el", "--element", - "--el", type=str, + dest="element", nargs="+", default=None, help="Add spd DOS projections for requested element to the DOS plot", ) dos_plotting_group.add_argument( + "-orb", "--orbital", - "--orb", type=str, + dest="orbital", nargs="+", default=None, help="Orbital name for the site for which DOS are to be added", @@ -291,27 +330,32 @@ def get_parser() -> argparse.ArgumentParser: dos_plotting_group.add_argument( "--site", type=int, + dest="site", nargs="+", default=None, help="Site index in the crystal structure for " "which DOS need to be added", ) dos_plotting_group.add_argument( + "-sspin", "--summedspins", "--summed-spins", + dest="summedspins", action="store_true", help="Plot summed spins DOS", ) group = dos_plotting_parent.add_mutually_exclusive_group() group.add_argument( + "-eldos", "--elementdos", - "--el-dos", + dest="elementdos", action="store_true", help="Add DOS projections for each element to the DOS plot", ) group.add_argument( "--spddos", "--spd-dos", + dest="spddos", action="store_true", help="Add spd projected dos to the DOS plot", ) @@ -320,13 +364,15 @@ def get_parser() -> argparse.ArgumentParser: advanced_plotting_args.add_argument( "--invertaxis", "--invert-axis", + dest="invertaxis", action="store_true", help="Invert plot axis of DOS or COOPs COHPs or COBIS", ) # Argument specific to COHPs / COOPs / COBIs plots coxx_plotting_args = argparse.ArgumentParser(add_help=False) coxx_plotting_args.add_argument( - "--integrated", + "-integr" "--integrated", + dest="integrated", action="store_true", help="Show integrated cohp/cobi/coop plots.", ) @@ -337,6 +383,7 @@ def get_parser() -> argparse.ArgumentParser: "Adjustable automatic analysis parameters" ) auto_group.add_argument( + "-allb", "--allbonds", "--all-bonds", action="store_true", @@ -352,6 +399,7 @@ def get_parser() -> argparse.ArgumentParser: " (ICOHP or ICOBI or ICOOP) for automatic analysis.", ) auto_group.add_argument( + "-fjson", "--file-json", nargs="?", type=Path, @@ -368,6 +416,7 @@ def get_parser() -> argparse.ArgumentParser: " automatic analysis", ) auto_group.add_argument( + "-orbresol", "--orbitalresolved", "--orbital-resolved", action="store_true", @@ -375,6 +424,7 @@ def get_parser() -> argparse.ArgumentParser: help="Switch on orbital resolved analysis of (I)COHPs or (I)COBIs or (I)COOPs with all relevant orbitals.", ) auto_group.add_argument( + "-orbcutoff", "--orbitalcutoff", "--orbital-cutoff", type=float, @@ -410,6 +460,7 @@ def get_parser() -> argparse.ArgumentParser: "Options specific to interactive plotter" ) interactive_plotter_group.add_argument( + "-labresol", "--labelresolved", "--label-resolved", action="store_true", @@ -417,6 +468,7 @@ def get_parser() -> argparse.ArgumentParser: "If not set, plots consist of summed cohps.", ) interactive_plotter_group.add_argument( + "-orbplot", "--orbitalplot", "--orbital-plot", action="store_true", @@ -454,6 +506,7 @@ def get_parser() -> argparse.ArgumentParser: help="Energy range for DOS comparisons", ) calc_quality_args_group.add_argument( + "-fcalcqualjson", "--file-calc-quality-json", nargs="?", type=Path, @@ -604,6 +657,7 @@ def get_parser() -> argparse.ArgumentParser: help="List of bond numbers, determining COHPs/COBIs/COOPs to include in plot.", ) plot_parser.add_argument( + "-integr", "--integrated", action="store_true", help="Show integrated cohp/cobi/coop plots.", @@ -615,6 +669,7 @@ def get_parser() -> argparse.ArgumentParser: help="Show a summed COHP", ) plot_grouping.add_argument( + "-orbwise", "--orbitalwise", dest="orbitalwise", nargs="+", @@ -686,19 +741,27 @@ def run(args): """ if args.action in [ - "plot-automatic", "plot-auto", "automatic-plot", "automaticplot", - "autoplot", "auto-plot", - "description", - "plot-automatic-ia", + "autoplot", + ]: + args.action = "plot-automatic" + + if args.action in [ "plot-auto-ia", "automatic-plot-ia", "automaticplotia", - "auto-plot-ia", "autoplotia", + "auto-plot-ia", + ]: + args.action = "plot-automatic-ia" + + if args.action in [ + "description", + "plot-automatic", + "plot-automatic-ia", ]: # Check for .gz files exist for default values and update accordingly default_files = { @@ -721,15 +784,10 @@ def run(args): ) if args.coops: - if args.action != "plot": - default_files_coops = { - "icohplist": "ICOOPLIST.lobster", - "cohpcar": "COOPCAR.lobster", - } - else: - default_files_coops = { - "cohpcar": "COOPCAR.lobster", - } + default_files_coops = { + "icohplist": "ICOOPLIST.lobster", + "cohpcar": "COOPCAR.lobster", + } for arg_name, file_name in default_files_coops.items(): setattr(args, arg_name, Path(file_name)) file_path = getattr(args, arg_name) @@ -744,15 +802,10 @@ def run(args): ) if args.cobis: - if args.action != "plot": - default_files_cobis = { - "icohplist": "ICOBILIST.lobster", - "cohpcar": "COBICAR.lobster", - } - else: - default_files_cobis = { - "cohpcar": "COBICAR.lobster", - } + default_files_cobis = { + "icohplist": "ICOBILIST.lobster", + "cohpcar": "COBICAR.lobster", + } for arg_name, file_name in default_files_cobis.items(): setattr(args, arg_name, Path(file_name)) file_path = getattr(args, arg_name) @@ -762,28 +815,10 @@ def run(args): setattr(args, arg_name, gz_file_path) else: raise ValueError( - "Files required for automatic analysis of COOPs (ICOBILIST.lobster and" + "Files required for automatic analysis of COBIs (ICOBILIST.lobster and" " COBICAR.lobster) not found in the directory" ) - if args.action in [ - "plot-auto", - "automatic-plot", - "automaticplot", - "auto-plot", - "autoplot", - ]: - args.action = "plot-automatic" - - if args.action in [ - "plot-auto-ia", - "automatic-plot-ia", - "automaticplotia", - "autoplotia", - "auto-plot-ia", - ]: - args.action = "plot-automatic-ia" - if args.action in ["description", "plot-automatic", "plot-automatic-ia"]: if args.allbonds: which_bonds = "all" From 8e947c4b1bf0b9160e1dd9f8bbb0afbce99696d5 Mon Sep 17 00:00:00 2001 From: anaik Date: Wed, 1 Nov 2023 10:28:59 +0100 Subject: [PATCH 10/11] address review comments --- lobsterpy/cli.py | 18 +++++++++--------- lobsterpy/test/test_cli.py | 17 ++++++++--------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lobsterpy/cli.py b/lobsterpy/cli.py index 20f1c06a..8b9b8e3b 100644 --- a/lobsterpy/cli.py +++ b/lobsterpy/cli.py @@ -140,7 +140,7 @@ def get_parser() -> argparse.ArgumentParser: help='path to vasprun.xml. Default is "vasprun.xml".', ) calc_quality_description_file_group.add_argument( - "-fbandoverlap", + "-fbandoverlaps", "--file-bandoverlaps", default="bandOverlaps.lobster", dest="bandoverlaps", @@ -148,7 +148,7 @@ def get_parser() -> argparse.ArgumentParser: help='path to bandOverlaps.lobster. Default is "bandOverlaps.lobster".', ) calc_quality_description_file_group.add_argument( - "-flobsin", + "-flobsterin", "--file-lobsterin", default="lobsterin", dest="lobsterin", @@ -156,7 +156,7 @@ def get_parser() -> argparse.ArgumentParser: help='path to lobsterin. Default is "lobsterin".', ) calc_quality_description_file_group.add_argument( - "-flobsout", + "-flobsterout", "--file-lobsterout", default="lobsterout", dest="lobsterout", @@ -184,8 +184,8 @@ def get_parser() -> argparse.ArgumentParser: help='path to INCAR that lobsterpy generates. Default is "INCAR.lobsterpy"', ) output_file_group.add_argument( - "-flobsinout", - "--file-lobsterin-out", + "-flobsterin", + "--file-lobsterin", default="lobsterin.lobsterpy", dest="lobsterinout", type=Path, @@ -304,8 +304,8 @@ def get_parser() -> argparse.ArgumentParser: dos_plotting_group = dos_plotting_parent.add_argument_group("Plotting") dos_plotting_group.add_argument( "-addtdos", - "--addtotaldos", - "--add-total-dos", + "--addtotal", + "--add-total", action="store_true", help="Add total dos to DOS plot.", ) @@ -1206,7 +1206,7 @@ def run(args): lobs_dos = Doscar(doscar=args.doscar, structure_file=args.structure).completedos dos_plotter = PlainDosPlotter(summed=args.summedspins, sigma=args.sigma) - if args.addtotaldos: + if args.addtotal: dos_plotter.add_dos(dos=lobs_dos, label="Total DOS") if args.spddos: dos_plotter.add_dos_dict(dos_dict=lobs_dos.get_spd_dos()) @@ -1245,7 +1245,7 @@ def run(args): and not args.element and not args.spddos and not args.elementdos - and not args.addtotaldos + and not args.addtotal ): dos_plotter.add_dos(dos=lobs_dos, label="Total DOS") dos_plotter.add_dos_dict(dos_dict=lobs_dos.get_element_dos()) diff --git a/lobsterpy/test/test_cli.py b/lobsterpy/test/test_cli.py index 5131c56d..13720432 100644 --- a/lobsterpy/test/test_cli.py +++ b/lobsterpy/test/test_cli.py @@ -193,9 +193,9 @@ def test_lobsterin_generation(self, tmp_path): INCARpath = tmp_path / "INCAR.lobsterpy" args = [ "create-inputs", - "--file-lobsterin-out", + "-flobsterin", str(lobsterinpath), - "--file-incar-out", + "-fincarout", str(INCARpath), ] test = get_parser().parse_args(args) @@ -215,7 +215,7 @@ def test_lobsterin_generation(self, tmp_path): INCARpath = tmp_path / "INCAR.lobsterpy" args = [ "createinputs", - "--file-lobsterin-out", + "--file-lobsterin", str(lobsterinpath), "--file-incar-out", str(INCARpath), @@ -232,7 +232,7 @@ def test_lobsterin_generation_error(self, tmp_path): INCARpath = tmp_path / "INCAR.lobsterpy" args = [ "create-inputs", - "--file-lobsterin-out", + "--file-lobsterin", str(lobsterinpath), "--file-incar-out", str(INCARpath), @@ -249,7 +249,7 @@ def test_lobsterin_generation_error(self, tmp_path): args = [ "create-inputs", - "--file-lobsterin-out", + "--file-lobsterin", str(lobsterinpath), "--file-incar-out", str(INCARpath), @@ -284,7 +284,7 @@ def test_lobsterin_generation_error_userbasis(self, tmp_path): INCARpath = tmp_path / "INCAR.lobsterpy" args = [ "create-inputs", - "--file-lobsterin-out", + "--file-lobsterin", str(lobsterinpath), "--file-incar-out", str(INCARpath), @@ -631,7 +631,7 @@ def test_gz_file_cli_lobsterinput_generation(self, tmp_path): INCARpath = tmp_path / "INCAR.lobsterpy" args = [ "create-inputs", - "--file-lobsterin-out", + "--file-lobsterin", str(lobsterinpath), "--file-incar-out", str(INCARpath), @@ -651,9 +651,8 @@ def test_gz_file_cli_lobsterinput_generation(self, tmp_path): ]: self.assert_is_finite_file(filepath) - os.chdir(TestDir / "TestData/NaCl") - def test_gz_cli_plot(self, tmp_path): + os.chdir(TestDir / "TestData/NaCl") plot_path = tmp_path / "plot.png" args = ["plot", "3", "--saveplot", str(plot_path)] From 51c92699b802f14c6dda786a7f08cdf0abb75179 Mon Sep 17 00:00:00 2001 From: anaik Date: Wed, 1 Nov 2023 10:42:55 +0100 Subject: [PATCH 11/11] remove confusing -fs arg for fontsize --- lobsterpy/cli.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lobsterpy/cli.py b/lobsterpy/cli.py index 8b9b8e3b..27828255 100644 --- a/lobsterpy/cli.py +++ b/lobsterpy/cli.py @@ -205,7 +205,6 @@ def get_parser() -> argparse.ArgumentParser: plotting_parent = argparse.ArgumentParser(add_help=False) plotting_group = plotting_parent.add_argument_group("Plotting") plotting_group.add_argument( - "-fs", "--fontsize", "--font-size", type=float,