From cfb4759273f5d4d159038929ca11f043ea40c002 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Tue, 17 Mar 2015 18:03:03 +0100 Subject: [PATCH] Doc --- src/EMSL_dump.py | 22 ++++++---------------- src/parser_handler.py | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/EMSL_dump.py b/src/EMSL_dump.py index 687ae33..66df9a6 100644 --- a/src/EMSL_dump.py +++ b/src/EMSL_dump.py @@ -5,7 +5,6 @@ import time import sqlite3 from collections import OrderedDict -from src.parser_handler import format_dict def install_with_pip(name): @@ -40,21 +39,11 @@ class EMSL_dump: def __init__(self, db_path=None, format="GAMESS-US", contraction="True"): - if format not in format_dict: - print >> sys.stderr, "Format {0} doesn't exist. Choose in:".format( - format) - print >> sys.stderr, format_dict.keys() - sys.exit(1) - else: - self.format = format + from src.parser_handler import get_parser_function + from src.parser_handler import check_format - if format_dict[self.format]: - self.parser = format_dict[self.format] - else: - print >> sys.stderr, "We have no parser for this format" - print >> sys.stderr, "Fill free to Fock /pull request" - print >> sys.stderr, "You just need to add a function like" - print >> sys.stderr, "'parse_basis_data_gamess_us' to parse you'r format" + self.format = check_format(format) + self.parser = get_parser_function(self.format) if db_path: self.db_path = db_path @@ -75,7 +64,8 @@ class EMSL_dump: def get_list_format(self): """List all the format available in EMSL""" - return format_dict + from src.parser_handler import parser_dict + return parser_dict.keys() def set_db_path(self, path): """Define the database path""" diff --git a/src/parser_handler.py b/src/parser_handler.py index ea255ee..fa9d634 100644 --- a/src/parser_handler.py +++ b/src/parser_handler.py @@ -29,8 +29,9 @@ from src.parser.gaussian94 import parse_basis_data_gaussian94 from src.parser.nwchem import parse_basis_data_nwchem -format_dict = {"Gaussian94": parse_basis_data_gaussian94, +parser_dict = {"Gaussian94": parse_basis_data_gaussian94, "GAMESS-US": parse_basis_data_gamess_us, + "NWChem": parse_basis_data_nwchem, "GAMESS-UK": None, "Turbomole": None, "TX93": None, @@ -43,8 +44,34 @@ format_dict = {"Gaussian94": parse_basis_data_gaussian94, "Dalton": None, "deMon-KS": None, "deMon2k": None, - "AcesII": None, - "NWChem": parse_basis_data_nwchem} + "AcesII": None} + + +def check_format(format): + try: + parser_dict[format] + except KeyError: + str_ = ["This format ({0}) is not available in EMSL".format(format), + "EMSL provide this list : {0}".format(parser_dict.keys())] + print >> sys.stderr, "\n".join(str_) + sys.exit(1) + else: + return format + + +def get_parser_function(format): + if not parser_dict[format]: + list_parser = [k for k, v in parser_dict.iteritems() if v] + + str_ = ["We have no parser for this format {0}".format(format), + "We only support {0}".format(list_parser), + "Fill free to Fock /pull request", + "You just need to add a function like this one:", + "'src.pars.gamess_us.parse_basis_data_gamess_us'"] + print >> sys.stderr, "\n".join(str_) + sys.exit(1) + else: + return parser_dict[format] # _____ _ _ _ _ # / ___| | | | (_) | | @@ -78,7 +105,8 @@ def get_symmetry_function(format): print >> sys.stderr, "You need to add a function in symmetry_dict" print >> sys.stderr, "for your format ({0})".format(format) sys.exit(1) - return f + else: + return f # _ _ _ _ _ _ _ _ _ ______ _ _ # | | | | | | | ( | ) | ( | ) | _ (_) | | @@ -106,4 +134,5 @@ def get_handle_l_function(format): print >> sys.stderr, "You need to add a function in handle_l_dict" print >> sys.stderr, "for your format ({0})".format(format) sys.exit(1) - return f + else: + return f