mirror of
https://github.com/LCPQ/EMSL_Basis_Set_Exchange_Local
synced 2025-01-03 01:55:54 +01:00
Need format un get_basis_data now. For test ! Need cleaning.
This commit is contained in:
parent
b6503406f8
commit
a773c4ed06
11
EMSL_api.py
11
EMSL_api.py
@ -11,10 +11,12 @@ Usage:
|
|||||||
EMSL_api.py list_atoms --basis=<basis_name>
|
EMSL_api.py list_atoms --basis=<basis_name>
|
||||||
[--db_path=<db_path>]
|
[--db_path=<db_path>]
|
||||||
EMSL_api.py get_basis_data --basis=<basis_name>
|
EMSL_api.py get_basis_data --basis=<basis_name>
|
||||||
|
--format=<format>
|
||||||
[--atom=<atom_name>...]
|
[--atom=<atom_name>...]
|
||||||
[--db_path=<db_path>]
|
[--db_path=<db_path>]
|
||||||
[(--save [--path=<path>])]
|
[(--save [--path=<path>])]
|
||||||
[--check=<format>]
|
[--check]
|
||||||
|
[--treat_l]
|
||||||
EMSL_api.py list_formats
|
EMSL_api.py list_formats
|
||||||
EMSL_api.py create_db --db_path=<db_path>
|
EMSL_api.py create_db --db_path=<db_path>
|
||||||
--format=<format>
|
--format=<format>
|
||||||
@ -39,7 +41,6 @@ Example of use:
|
|||||||
|
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from src.docopt import docopt
|
from src.docopt import docopt
|
||||||
@ -112,11 +113,13 @@ if __name__ == '__main__':
|
|||||||
# | |_/ / (_| \__ \ \__ \ | (_| | (_| | || (_| |
|
# | |_/ / (_| \__ \ \__ \ | (_| | (_| | || (_| |
|
||||||
# \____/ \__,_|___/_|___/ \__,_|\__,_|\__\__,_|
|
# \____/ \__,_|___/_|___/ \__,_|\__,_|\__\__,_|
|
||||||
if arguments["get_basis_data"]:
|
if arguments["get_basis_data"]:
|
||||||
e = EMSL_local(db_path=db_path)
|
e = EMSL_local(db_path=db_path, format=arguments["--format"])
|
||||||
basis_name = arguments["--basis"][0]
|
basis_name = arguments["--basis"][0]
|
||||||
elts = arguments["--atom"]
|
elts = arguments["--atom"]
|
||||||
|
|
||||||
l_atom_basis = e.get_basis(basis_name, elts, arguments["--check"])
|
l_atom_basis = e.get_basis(basis_name, elts,
|
||||||
|
arguments["--treat_l"],
|
||||||
|
arguments["--check"])
|
||||||
# Add separation between atoms, and a empty last line
|
# Add separation between atoms, and a empty last line
|
||||||
str_ = "\n\n".join(l_atom_basis) + "\n"
|
str_ = "\n\n".join(l_atom_basis) + "\n"
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ def check_gamess(str_type):
|
|||||||
|
|
||||||
if str_type in "S P D".split():
|
if str_type in "S P D".split():
|
||||||
return True
|
return True
|
||||||
elif str_type > "L":
|
elif str_type == "L":
|
||||||
raise BaseException
|
raise BaseException
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
@ -127,11 +127,12 @@ class EMSL_local:
|
|||||||
All the method for using the EMSL db localy
|
All the method for using the EMSL db localy
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, db_path=None):
|
def __init__(self, db_path=None, format=None):
|
||||||
self.db_path = db_path
|
self.db_path = db_path
|
||||||
self.p = re.compile(ur'^(\w)\s+\d+\b')
|
self.p = re.compile(ur'^(\w)\s+\d+\b')
|
||||||
|
self.format = format
|
||||||
|
|
||||||
def get_list_type(self, atom_basis):
|
def get_list_symetry(self, atom_basis):
|
||||||
"""
|
"""
|
||||||
Return the begin and the end of all the type of orbital
|
Return the begin and the end of all the type of orbital
|
||||||
input: atom_basis = [name, ]
|
input: atom_basis = [name, ]
|
||||||
@ -223,7 +224,9 @@ class EMSL_local:
|
|||||||
if average_mo_number:
|
if average_mo_number:
|
||||||
column_to_fech += ", data"
|
column_to_fech += ", data"
|
||||||
|
|
||||||
filter_where = " ({}) AND ({})".format(cmd_filter_ele, cmd_filter_basis)
|
filter_where = " ({}) AND ({})".format(
|
||||||
|
cmd_filter_ele,
|
||||||
|
cmd_filter_basis)
|
||||||
|
|
||||||
cmd = """SELECT DISTINCT {0}
|
cmd = """SELECT DISTINCT {0}
|
||||||
FROM output_tab
|
FROM output_tab
|
||||||
@ -248,10 +251,14 @@ class EMSL_local:
|
|||||||
# Description : dict_info[name] = [description, nb_mo, nb_ele]
|
# Description : dict_info[name] = [description, nb_mo, nb_ele]
|
||||||
|
|
||||||
if average_mo_number:
|
if average_mo_number:
|
||||||
|
|
||||||
|
print "WARNING DO NOT SUPPORT L COUNTING"
|
||||||
|
print "TREAD L FUNCTION NOT LIKE A SPECIAL ONE"
|
||||||
for name, description, atom_basis in info:
|
for name, description, atom_basis in info:
|
||||||
nb_mo = 0
|
nb_mo = 0
|
||||||
|
|
||||||
for type_, _, _ in self.get_list_type(atom_basis.split("\n")):
|
line = atom_basis.split("\n")
|
||||||
|
for type_, _, _ in self.get_list_symetry(line):
|
||||||
nb_mo += string_to_nb_mo(type_)
|
nb_mo += string_to_nb_mo(type_)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -299,7 +306,9 @@ class EMSL_local:
|
|||||||
|
|
||||||
return [str(i[0]) for i in c.fetchall()]
|
return [str(i[0]) for i in c.fetchall()]
|
||||||
|
|
||||||
def get_basis(self, basis_name, elts=None, check_format=None):
|
def get_basis(self,
|
||||||
|
basis_name, elts=None,
|
||||||
|
handle_f_format="GAMESS-US", check_format=None):
|
||||||
"""
|
"""
|
||||||
Return the data from the basis set
|
Return the data from the basis set
|
||||||
"""
|
"""
|
||||||
@ -325,31 +334,46 @@ class EMSL_local:
|
|||||||
l_atom_basis = [i[0].strip() for i in c.fetchall()]
|
l_atom_basis = [i[0].strip() for i in c.fetchall()]
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
# ~#~#~#~#~#~#~#~ #
|
||||||
|
# h a n d l e _ f #
|
||||||
|
# ~#~#~#~#~#~#~#~ #
|
||||||
|
if handle_f_format:
|
||||||
|
from src.parser import handle_f_dict
|
||||||
|
try:
|
||||||
|
f = handle_f_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_f_dict.keys()
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
l_atom_basis = f(l_atom_basis,self.get_list_symetry)
|
||||||
|
|
||||||
# ~#~#~#~#~ #
|
# ~#~#~#~#~ #
|
||||||
# C h e c k #
|
# C h e c k #
|
||||||
# ~#~#~#~#~ #
|
# ~#~#~#~#~ #
|
||||||
|
|
||||||
d_check = {"gamess": check_gamess,
|
d_check = {"GAMESS-US": check_gamess,
|
||||||
"NWChem": check_NWChem}
|
"NWChem": check_NWChem}
|
||||||
|
|
||||||
if check_format:
|
if check_format:
|
||||||
try:
|
try:
|
||||||
f = d_check[check_format]
|
f = d_check[self.format]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
str_ = """This format is not handle. Chose one of : {}"""
|
str_ = """This format is not handle. Chose one of : {}"""
|
||||||
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:
|
||||||
for atom_basis in l_atom_basis:
|
for atom_basis in l_atom_basis:
|
||||||
for type_, _, _ in self.get_list_type(atom_basis.split("\n")):
|
lines = atom_basis.split("\n")
|
||||||
f(type_)
|
for type_, _, _ in self.get_list_symetry(lines):
|
||||||
|
f(type_)
|
||||||
|
|
||||||
# ~#~#~#~#~#~ #
|
# ~#~#~#~#~#~ #
|
||||||
# R e t u r n #
|
# R e t u r n #
|
||||||
# ~#~#~#~#~#~ #
|
# ~#~#~#~#~#~ #
|
||||||
|
|
||||||
return l_atom_basis
|
return l_atom_basis
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
e = EMSL_local(db_path="EMSL.db")
|
e = EMSL_local(db_path="EMSL.db")
|
||||||
|
@ -88,5 +88,72 @@ format_dict = {"Gaussian94": None,
|
|||||||
"Dalton": None,
|
"Dalton": None,
|
||||||
"deMon-KS": None,
|
"deMon-KS": None,
|
||||||
"deMon2k": None,
|
"deMon2k": None,
|
||||||
"AcesII": None,
|
"AcesII": None}
|
||||||
}
|
|
||||||
|
# _ _ _ _ _ _ _ _ _
|
||||||
|
# | | | | | | | ( | ) | ( | )
|
||||||
|
# | |_| | __ _ _ __ __| | | ___ V V| | V V
|
||||||
|
# | _ |/ _` | '_ \ / _` | |/ _ \ | |
|
||||||
|
# | | | | (_| | | | | (_| | | __/ | |____
|
||||||
|
# \_| |_/\__,_|_| |_|\__,_|_|\___| \_____/
|
||||||
|
#
|
||||||
|
#
|
||||||
|
def handle_f_gamess_us(l_atom_basis, list_symetry):
|
||||||
|
"""
|
||||||
|
Read l_atom_basis, if "L" orbital before "D" one, split them into S and P
|
||||||
|
"""
|
||||||
|
|
||||||
|
l_data = []
|
||||||
|
|
||||||
|
for atom_basis in l_atom_basis:
|
||||||
|
|
||||||
|
# Split the data in line
|
||||||
|
l_line_raw = atom_basis.split("\n")
|
||||||
|
l_line = [l_line_raw[0]]
|
||||||
|
# l_line_raw[0] containt the name of the Atom
|
||||||
|
|
||||||
|
maybe_good_l = True
|
||||||
|
|
||||||
|
for symmetry, begin, end in list_symetry(l_line_raw):
|
||||||
|
|
||||||
|
if maybe_good_l and symmetry in "L":
|
||||||
|
|
||||||
|
body_s = []
|
||||||
|
body_p = []
|
||||||
|
|
||||||
|
for i_l in l_line_raw[begin + 1:end]:
|
||||||
|
|
||||||
|
# one L => S & P
|
||||||
|
a = i_l.split()
|
||||||
|
|
||||||
|
common = "{:>3}".format(a[0])
|
||||||
|
common += "{:>15.7f}".format(float(a[1]))
|
||||||
|
|
||||||
|
tail_s = common + "{:>23.7f}".format(float(a[2]))
|
||||||
|
body_s.append(tail_s)
|
||||||
|
|
||||||
|
# Maybe only One coefficient for L function
|
||||||
|
# I guess it mean S and L are equal
|
||||||
|
try:
|
||||||
|
tail_p = common + "{:>23.7f}".format(float(a[3]))
|
||||||
|
except IndexError:
|
||||||
|
tail_p = tail_s
|
||||||
|
finally:
|
||||||
|
body_p.append(tail_p)
|
||||||
|
|
||||||
|
l_line += [l_line_raw[begin].replace("L", "S")]
|
||||||
|
l_line += body_s
|
||||||
|
|
||||||
|
l_line += [l_line_raw[begin].replace("L", "P")]
|
||||||
|
l_line += body_p
|
||||||
|
else:
|
||||||
|
l_line += l_line_raw[begin:end]
|
||||||
|
|
||||||
|
if symmetry not in ["S", "P", "L"]:
|
||||||
|
maybe_good_l = False
|
||||||
|
|
||||||
|
l_data.append("\n".join(l_line))
|
||||||
|
|
||||||
|
return l_data
|
||||||
|
|
||||||
|
handle_f_dict = {"GAMESS-US": handle_f_gamess_us}
|
||||||
|
Loading…
Reference in New Issue
Block a user