diff --git a/EMSL_api.py b/EMSL_api.py index 42a4409..a18fbca 100755 --- a/EMSL_api.py +++ b/EMSL_api.py @@ -14,7 +14,7 @@ Usage: [--atom=...] [--db_path=] [(--save [--path=])] - [--check] + [--check=] [--treat_l] EMSL_api.py list_formats EMSL_api.py create_db --db_path= diff --git a/src/EMSL_local.py b/src/EMSL_local.py index 6315a3a..d37374d 100755 --- a/src/EMSL_local.py +++ b/src/EMSL_local.py @@ -85,38 +85,6 @@ def string_to_nb_mo(str_type): else: raise BaseException - -# _ -# / |_ _ _ | _. | o _| o _|_ -# \_ | | (/_ (_ |< \/ (_| | | (_| | |_ \/ -# / - -def check_gamess(str_type): - """Check is the orbital type is handle by gamess""" - - assert len(str_type) == 1 - - if str_type in "S P D".split(): - return True - elif str_type == "L": - raise BaseException - else: - return True - - -def check_NWChem(str_type): - """Check is the orbital type is handle by gamess""" - - assert len(str_type) == 1 - - if str_type in "S P D".split(): - return True - elif str_type > "I" or str_type in "K L M".split(): - raise BaseException - else: - return True - - # _ __ # |_ |\/| (_ | | _ _ _. | # |_ | | __) |_ |_ (_) (_ (_| | @@ -224,10 +192,10 @@ class EMSL_local: dict_info = OrderedDict() # Description : dict_info[name] = [description, nb_mo, nb_ele] - from src.parser import get_symemetry_function + from src.parser import get_symmetry_function if average_mo_number: - f_symmetry = get_symemetry_function(self.format) + f_symmetry = get_symmetry_function(self.format) for name, description, atom_basis in info: @@ -277,7 +245,7 @@ class EMSL_local: def get_basis(self, basis_name, elts=None, - handle_l_format=False, check_format=False): + handle_l_format=False, check_format=None): """ Return the data from the basis set """ @@ -299,40 +267,32 @@ class EMSL_local: # h a n d l e _ f # # ~#~#~#~#~#~#~#~ # if handle_l_format: - from src.parser import handle_l_dict - try: - f = handle_l_dict[self.format] - except KeyError: - str_ = "You cannot handle f function with {0} format" - print >> sys.stderr, str_.format(self.format) - print >> sys.stderr, "Choose in:" - print >> sys.stderr, handle_l_dict.keys() - sys.exit(1) - else: - l_atom_basis = f(l_atom_basis) - + from src.parser import get_handle_l_function + f = get_handle_l_function(self.format) + l_atom_basis = f(l_atom_basis) # ~#~#~#~#~ # # C h e c k # # ~#~#~#~#~ # - d_check = {"GAMESS-US": check_gamess, - "NWChem": check_NWChem} - if check_format: - try: - f = d_check[self.format] - except KeyError: - str_ = """This format is not handle. Chose one of : {}""" - print >>sys.stderr, str_.format(format(str(d_check.keys()))) - sys.exit(1) - else: - from src.parser import get_symemetry_function - f_symmetry = get_symemetry_function(self.format) + + from src.parser import get_symmetry_function + from src.check_validity import get_check_function + + f = get_check_function(check_format) + f_symmetry = get_symmetry_function(self.format) for atom_basis in l_atom_basis: lines = atom_basis.split("\n") for type_, _, _ in f_symmetry(lines): - f(type_) + try: + f(type_) + except AssertionError: + print "False. You have somme special function like SP" + sys.exit(1) + except BaseException: + print "Fail !" + sys.exit(1) # ~#~#~#~#~#~ # # R e t u r n # diff --git a/src/check_validity.py b/src/check_validity.py new file mode 100644 index 0000000..708cf09 --- /dev/null +++ b/src/check_validity.py @@ -0,0 +1,52 @@ +# _ +# / |_ _ _ | _. | o _| o _|_ +# \_ | | (/_ (_ |< \/ (_| | | (_| | |_ \/ +# / +# Do this After the L special case traitement. + +import sys + + +def check_gamess(str_type): + """Check is the orbital type is handle by gamess""" + + assert len(str_type) == 1 + + if str_type in "S P D".split(): + return True + elif str_type == "SP": + raise BaseException + else: + return True + + +def check_NWChem(str_type): + """Check is the orbital type is handle by gamess""" + + assert len(str_type) == 1 + + if str_type in "S P D".split(): + return True + elif str_type > "I" or str_type in "K L M".split(): + raise BaseException + else: + return True + + +d_check = {"GAMESS-US": check_gamess, + "NWChem": check_NWChem} + + +def get_check_function(name_program): + """ + Tranforme SP special function (create using get_symmetry_function) + into S and P + """ + try: + f = d_check[name_program] + except KeyError: + str_ = "You need to add a check funtion for your program {0}" + print >> sys.stderr, str_.format(name_program) + print >> sys.stderr, "This one are avalaible {0}".format(d_check.keys()) + sys.exit(1) + return f diff --git a/src/parser.py b/src/parser.py index 654ccfe..486e948 100644 --- a/src/parser.py +++ b/src/parser.py @@ -191,17 +191,28 @@ format_dict = {"Gaussian94": None, # __/ | __/ | # |___/ |___/ +""" +Return the begin and the end of all the type of orbital +input: atom_basis = [name, S 1, 12 0.12 12212, ...] +output: [ [type, begin, end], ...] +""" + symmetry_dict = {"GAMESS-US": l_symmetry_gamess_us} -def get_symemetry_function(format): - try: - l_symmetry = symmetry_dict[format] - except KeyError: - 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 l_symmetry +def get_symmetry_function(format): + """ + Return the begin and the end of all the type of orbital + input: atom_basis = [name, S 1, 12 0.12 12212, ...] + output: [ [type, begin, end], ...] + """ + try: + f = symmetry_dict[format] + except KeyError: + 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 # _ _ _ _ _ _ _ _ _ ______ _ _ # | | | | | | | ( | ) | ( | ) | _ (_) | | @@ -210,4 +221,22 @@ def get_symemetry_function(format): # | | | | (_| | | | | (_| | | __/ | |____ | |/ /| | (__| |_ # \_| |_/\__,_|_| |_|\__,_|_|\___| \_____/ |___/ |_|\___|\__| +""" +Tranforme SP special function (create using get_symmetry_function) into S and P +""" + handle_l_dict = {"GAMESS-US": handle_l_gamess_us} + + +def get_handle_l_function(format): + """ + Tranforme SP special function (create using get_symmetry_function) + into S and P + """ + try: + f = handle_l_dict[format] + except KeyError: + 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