10
0
mirror of https://github.com/LCPQ/EMSL_Basis_Set_Exchange_Local synced 2024-12-22 20:34:23 +01:00

Add dict for testing

This commit is contained in:
Thomas Applencourt 2015-03-16 19:24:39 +01:00
parent ec0fc43bf8
commit 29f7adaa3f
3 changed files with 44 additions and 30 deletions

View File

@ -77,15 +77,11 @@ if __name__ == '__main__':
if arguments["list_basis"]: if arguments["list_basis"]:
e = EMSL_local(db_path=db_path) e = EMSL_local(db_path=db_path)
elts = arguments["--atom"] l = e.list_basis_available(arguments["--atom"],
amn = arguments["--average_mo_number"]
l = e.get_list_basis_available(elts,
arguments["--basis"], arguments["--basis"],
average_mo_number=amn) arguments["--average_mo_number"])
if amn: if arguments["--average_mo_number"]:
for name, des, avg in l: for name, des, avg in l:
print "- '{}' ({}) || {:<50}".format(name, avg, des) print "- '{}' ({}) || {:<50}".format(name, avg, des)
else: else:
@ -127,6 +123,7 @@ if __name__ == '__main__':
if arguments["--path"]: if arguments["--path"]:
path = arguments["--path"] path = arguments["--path"]
else: else:
# The defaut path is bais
path = "_".join([basis_name, ".".join(elts)]) path = "_".join([basis_name, ".".join(elts)])
path = "/tmp/" + path + ".bs" path = "/tmp/" + path + ".bs"

View File

@ -34,7 +34,7 @@ def checkSQLite3(db_path):
# Check if the file system allows I/O on sqlite3 (lustre) # Check if the file system allows I/O on sqlite3 (lustre)
# If not, copy on /dev/shm and remove after opening # If not, copy on /dev/shm and remove after opening
try: try:
EMSL_local(db_path=db_path).get_list_basis_available() EMSL_local(db_path=db_path).list_basis_available()
except sqlite3.OperationalError: except sqlite3.OperationalError:
print >>sys.stderr, "I/O Error for you file system" print >>sys.stderr, "I/O Error for you file system"
print >>sys.stderr, "Try some fixe" print >>sys.stderr, "Try some fixe"
@ -47,7 +47,7 @@ def checkSQLite3(db_path):
# Try again to check # Try again to check
try: try:
EMSL_local(db_path=db_path).get_list_basis_available() EMSL_local(db_path=db_path).list_basis_available()
except: except:
print >>sys.stderr, "Sorry..." print >>sys.stderr, "Sorry..."
os.system("rm -f /dev/shm/%d.db" % (os.getpid())) os.system("rm -f /dev/shm/%d.db" % (os.getpid()))
@ -136,7 +136,7 @@ class EMSL_local:
self.c.execute("SELECT * from format_tab") self.c.execute("SELECT * from format_tab")
self.format = self.c.fetchone()[0] self.format = self.c.fetchone()[0]
def get_list_basis_available(self, def list_basis_available(self,
elts=[], elts=[],
basis=[], basis=[],
average_mo_number=False): average_mo_number=False):
@ -224,15 +224,10 @@ class EMSL_local:
dict_info = OrderedDict() dict_info = OrderedDict()
# Description : dict_info[name] = [description, nb_mo, nb_ele] # Description : dict_info[name] = [description, nb_mo, nb_ele]
from src.parser import symmetry_dict from src.parser import get_symemetry_function
if average_mo_number: if average_mo_number:
try: f_symmetry = get_symemetry_function(self.format)
l_symmetry = symmetry_dict[self.format]
except KeyError:
print >> sys.stderr, "You need to add a function in symmetry_dict"
print >> sys.stderr, "for your format ({0})".format(self.format)
sys.exit(1)
for name, description, atom_basis in info: for name, description, atom_basis in info:
@ -240,7 +235,7 @@ class EMSL_local:
line = atom_basis.split("\n") line = atom_basis.split("\n")
for type_, _, _ in l_symmetry(line): for type_, _, _ in f_symmetry(line):
nb_mo += string_to_nb_mo(type_) nb_mo += string_to_nb_mo(type_)
try: try:
@ -282,7 +277,7 @@ class EMSL_local:
def get_basis(self, def get_basis(self,
basis_name, elts=None, basis_name, elts=None,
handle_f_format="GAMESS-US", check_format=None): handle_l_format=False, check_format=False):
""" """
Return the data from the basis set Return the data from the basis set
""" """
@ -303,18 +298,18 @@ class EMSL_local:
# ~#~#~#~#~#~#~#~ # # ~#~#~#~#~#~#~#~ #
# h a n d l e _ f # # h a n d l e _ f #
# ~#~#~#~#~#~#~#~ # # ~#~#~#~#~#~#~#~ #
if handle_f_format: if handle_l_format:
from src.parser import handle_f_dict from src.parser import handle_l_dict
try: try:
f = handle_f_dict[self.format] f = handle_l_dict[self.format]
except KeyError: except KeyError:
str_ = "You cannot handle f function with {0} format" str_ = "You cannot handle f function with {0} format"
print >> sys.stderr, str_.format(self.format) print >> sys.stderr, str_.format(self.format)
print >> sys.stderr, "Choose in:" print >> sys.stderr, "Choose in:"
print >> sys.stderr, handle_f_dict.keys() print >> sys.stderr, handle_l_dict.keys()
sys.exit(1) sys.exit(1)
else: else:
l_atom_basis = f(l_atom_basis, self.get_list_symetry) l_atom_basis = f(l_atom_basis)
# ~#~#~#~#~ # # ~#~#~#~#~ #
# C h e c k # # C h e c k #
@ -331,9 +326,12 @@ class EMSL_local:
print >>sys.stderr, str_.format(format(str(d_check.keys()))) print >>sys.stderr, str_.format(format(str(d_check.keys())))
sys.exit(1) sys.exit(1)
else: else:
from src.parser import get_symemetry_function
f_symmetry = get_symemetry_function(self.format)
for atom_basis in l_atom_basis: for atom_basis in l_atom_basis:
lines = atom_basis.split("\n") lines = atom_basis.split("\n")
for type_, _, _ in self.get_list_symetry(lines): for type_, _, _ in f_symmetry(lines):
f(type_) f(type_)
# ~#~#~#~#~#~ # # ~#~#~#~#~#~ #

View File

@ -112,7 +112,7 @@ def l_symmetry_gamess_us(atom_basis):
return l return l
def handle_f_gamess_us(l_atom_basis): def handle_l_gamess_us(l_atom_basis):
""" """
Read l_atom_basis and change the SP in L and P Read l_atom_basis and change the SP in L and P
""" """
@ -192,3 +192,22 @@ format_dict = {"Gaussian94": None,
# |___/ |___/ # |___/ |___/
symmetry_dict = {"GAMESS-US": l_symmetry_gamess_us} 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
# _ _ _ _ _ _ _ _ _ ______ _ _
# | | | | | | | ( | ) | ( | ) | _ (_) | |
# | |_| | __ _ _ __ __| | | ___ V V| | V V | | | |_ ___| |_
# | _ |/ _` | '_ \ / _` | |/ _ \ | | | | | | |/ __| __|
# | | | | (_| | | | | (_| | | __/ | |____ | |/ /| | (__| |_
# \_| |_/\__,_|_| |_|\__,_|_|\___| \_____/ |___/ |_|\___|\__|
handle_l_dict = {"GAMESS-US": handle_l_gamess_us}