Skip to content

Commit

Permalink
Added exception catching and manual error printing for the command li…
Browse files Browse the repository at this point in the history
…ne usage
  • Loading branch information
RaphaelRobidas committed Jan 18, 2022
1 parent 01aef2e commit d0977ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
13 changes: 9 additions & 4 deletions ccinput/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
class InvalidParameter(Exception):

# Base exception class for the project to make all exceptions easy to catch selectively
class CCInputException(Exception):
pass

class InvalidParameter(CCInputException):
pass

class InvalidXYZ(InvalidParameter):
pass

class ImpossibleCalculation(Exception):
class ImpossibleCalculation(CCInputException):
pass

class MissingParameter(Exception):
class MissingParameter(CCInputException):
pass

class InternalError(Exception):
class InternalError(CCInputException):
pass
18 changes: 11 additions & 7 deletions ccinput/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def write_input(filename, **args):

def get_parser():
import argparse
parser = argparse.ArgumentParser(description='Generation an input for a computational chemistry package')
parser = argparse.ArgumentParser(description='Generates an input for a computational chemistry package')
parser.add_argument('software', help='Desired software package (Gaussian or ORCA)')

parser.add_argument('type', help='Calculation type (opt, freq, sp, ...)')
Expand Down Expand Up @@ -122,12 +122,16 @@ def cmd():
parser = get_parser()
args = parser.parse_args()

inp = gen_input(software=args.software, type=args.type, method=args.method, \
basis_set=args.basis_set, solvent=args.solvent, solvation_model=args.solvation_model, \
solvation_radii=args.solvation_radii, specifications=args.specifications, density_fitting=args.density_fitting, \
custom_basis_sets=args.custom_basis_sets, xyz=args.xyz, in_file=args.file, constraints=args.constraints, \
nproc=args.nproc, mem=args.mem, charge=args.charge, multiplicity=args.mult, \
name=args.name, header=args.header)
try:
inp = gen_input(software=args.software, type=args.type, method=args.method, \
basis_set=args.basis_set, solvent=args.solvent, solvation_model=args.solvation_model, \
solvation_radii=args.solvation_radii, specifications=args.specifications, density_fitting=args.density_fitting, \
custom_basis_sets=args.custom_basis_sets, xyz=args.xyz, in_file=args.file, constraints=args.constraints, \
nproc=args.nproc, mem=args.mem, charge=args.charge, multiplicity=args.mult, \
name=args.name, header=args.header)
except CCInputException as e:
print("*** {} ***".format(str(e)))
return

if args.output != "":
with open(args.output, 'w') as out:
Expand Down

0 comments on commit d0977ef

Please sign in to comment.