Skip to content

Commit

Permalink
Make -f argument optional; allow filename as positional arg
Browse files Browse the repository at this point in the history
  • Loading branch information
ajjackson committed Jan 25, 2018
1 parent dea86f0 commit 379e91e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
31 changes: 21 additions & 10 deletions kgrid/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ def calc_grid(cutoff_length,

def main():
parser = ArgumentParser()
parser.add_argument(
"structure",
type=str,
help="Path to input file",
nargs='?',
default=None
)
parser.add_argument(
"-f",
"--file",
action="store",
type=str,
dest="file",
default="geometry.in",
help="Path to input file [default: ./geometry.in]")
threshold = parser.add_mutually_exclusive_group()
threshold.add_argument(
"-c",
Expand All @@ -68,15 +83,6 @@ def main():
type=float,
dest="kspacing",
help="Reciprocal space distance like KSPACING in VASP")

parser.add_argument(
"-f",
"--file",
action="store",
type=str,
dest="file",
default="geometry.in",
help="Path to input file [default: ./geometry.in]")
parser.add_argument(
"-t",
"--type",
Expand All @@ -103,10 +109,15 @@ def main():
mode = 'default'
cutoff = args.cutoff_length

if args.structure is None:
filename = args.file
else:
filename = args.structure

calc_grid(
cutoff,
mode=mode,
filename=args.file,
filename=filename,
filetype=args.type,
realspace=args.realspace,
pretty_print=True)
Expand Down
26 changes: 20 additions & 6 deletions kgrid/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,20 @@ def kspacing_series(atoms, l_min, l_max, decimals=4):
def main():
parser = ArgumentParser("Calculate a systematic series of k-point samples")
parser.add_argument(
'-f',
'--file',
"structure",
type=str,
default='geometry.in',
help='Crystal structure file')
help="Path to input file",
nargs='?',
default=None
)
parser.add_argument(
"-f",
"--file",
action="store",
type=str,
dest="file",
default="geometry.in",
help="Path to input file [default: ./geometry.in]")
parser.add_argument(
'-t',
'--type',
Expand All @@ -117,10 +126,15 @@ def main():

args = parser.parse_args()

if args.structure is None:
filename = args.file
else:
filename = args.structure

if args.type:
atoms = ase.io.read(args.file, format=args.type)
atoms = ase.io.read(filename, format=args.type)
else:
atoms = ase.io.read(args.file)
atoms = ase.io.read(filename)

cutoffs = cutoff_series(atoms, args.min, args.max)

Expand Down

0 comments on commit 379e91e

Please sign in to comment.