mirror of
https://github.com/LCPQ/EMSL_Basis_Set_Exchange_Local
synced 2024-10-31 19:23:42 +01:00
Add check_validity.py
This commit is contained in:
parent
29f7adaa3f
commit
2c6a77cbf8
@ -14,7 +14,7 @@ Usage:
|
||||
[--atom=<atom_name>...]
|
||||
[--db_path=<db_path>]
|
||||
[(--save [--path=<path>])]
|
||||
[--check]
|
||||
[--check=<program_name>]
|
||||
[--treat_l]
|
||||
EMSL_api.py list_formats
|
||||
EMSL_api.py create_db --db_path=<db_path>
|
||||
|
@ -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:
|
||||
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):
|
||||
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 #
|
||||
|
52
src/check_validity.py
Normal file
52
src/check_validity.py
Normal file
@ -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
|
@ -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):
|
||||
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:
|
||||
l_symmetry = symmetry_dict[format]
|
||||
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 l_symmetry
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user