mirror of
https://github.com/LCPQ/EMSL_Basis_Set_Exchange_Local
synced 2024-12-22 20:34:23 +01:00
Suport of --average_number_mo
This commit is contained in:
parent
57c4ac024d
commit
70553f1779
16
EMSL_api.py
16
EMSL_api.py
@ -6,6 +6,7 @@
|
|||||||
Usage:
|
Usage:
|
||||||
EMSL_api.py list_basis [--atom=<atom_name>...]
|
EMSL_api.py list_basis [--atom=<atom_name>...]
|
||||||
[--db_path=<db_path>]
|
[--db_path=<db_path>]
|
||||||
|
[--average_mo_number]
|
||||||
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>
|
||||||
@ -62,7 +63,7 @@ if __name__ == '__main__':
|
|||||||
if not(arguments['create_db']):
|
if not(arguments['create_db']):
|
||||||
db_path, db_path_changed = checkSQLite3(db_path)
|
db_path, db_path_changed = checkSQLite3(db_path)
|
||||||
except:
|
except:
|
||||||
sys.exit(1)
|
raise
|
||||||
|
|
||||||
# _ _ _ ______ _
|
# _ _ _ ______ _
|
||||||
# | | (_) | | | ___ \ (_)
|
# | | (_) | | | ___ \ (_)
|
||||||
@ -75,10 +76,17 @@ if __name__ == '__main__':
|
|||||||
e = EMSL_local(db_path=db_path)
|
e = EMSL_local(db_path=db_path)
|
||||||
|
|
||||||
elts = arguments["--atom"]
|
elts = arguments["--atom"]
|
||||||
l = e.get_list_basis_available(elts)
|
|
||||||
|
|
||||||
for name, des, n in l:
|
amn = arguments["--average_mo_number"]
|
||||||
print name, "(", n, ")", "|", des
|
|
||||||
|
l = e.get_list_basis_available(elts, average_mo_number=amn)
|
||||||
|
|
||||||
|
if amn:
|
||||||
|
for name, des, avg in l:
|
||||||
|
print "{0} ({2}) | {1}".format(name, des, avg)
|
||||||
|
else:
|
||||||
|
for name, des in l:
|
||||||
|
print "{0} | {1}".format(name, des)
|
||||||
|
|
||||||
# _ _ _ _____ _ _
|
# _ _ _ _____ _ _
|
||||||
# | | (_) | | | ___| | | |
|
# | | (_) | | | ___| | | |
|
||||||
|
@ -377,44 +377,120 @@ class EMSL_dump:
|
|||||||
self.create_sql(array_basis)
|
self.create_sql(array_basis)
|
||||||
|
|
||||||
|
|
||||||
class EMSL_local:
|
def string_to_nb_mo(str_l):
|
||||||
|
|
||||||
|
assert len(str_l) == 1
|
||||||
|
|
||||||
|
d = {"S": 3,
|
||||||
|
"P": 5,
|
||||||
|
"D": 7,
|
||||||
|
"F": 9,
|
||||||
|
"L": 8}
|
||||||
|
|
||||||
|
if str_l in d:
|
||||||
|
return d[str_l]
|
||||||
|
# ord("G") = 72 and ord("Z") = 87
|
||||||
|
elif 72 <= ord(str_l) <= 87:
|
||||||
|
# orf("G") = 72 and l = 4 so ofset if 68
|
||||||
|
return 2 * (ord(str_l) - 68) + 1
|
||||||
|
else:
|
||||||
|
raise BaseException
|
||||||
|
|
||||||
|
|
||||||
|
class EMSL_local:
|
||||||
|
"""
|
||||||
|
All the method for using the EMSL db localy
|
||||||
|
"""
|
||||||
def __init__(self, db_path=None):
|
def __init__(self, db_path=None):
|
||||||
self.db_path = db_path
|
self.db_path = db_path
|
||||||
|
|
||||||
def get_list_basis_available(self, elts=[]):
|
def get_list_basis_available(self, elts=[], average_mo_number=False):
|
||||||
|
"""
|
||||||
|
return all the basis name who contant all the elts
|
||||||
|
"""
|
||||||
conn = sqlite3.connect(self.db_path)
|
conn = sqlite3.connect(self.db_path)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
# If not elts just get the disctinct name
|
||||||
|
# Else: 1) fetch for geting the run_id available
|
||||||
|
# 2) If average_mo_number:
|
||||||
|
# * Get name,descripption,data
|
||||||
|
# * Then parse it
|
||||||
|
# Else Get name,description
|
||||||
|
# 3) Parse it
|
||||||
|
|
||||||
|
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||||
|
# G e t i n g B a s i s _ i d #
|
||||||
|
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||||
if not elts:
|
if not elts:
|
||||||
|
cmd = """SELECT DISTINCT name, description FROM basis_tab"""
|
||||||
|
c.execute(cmd)
|
||||||
|
info = c.fetchall()
|
||||||
|
else:
|
||||||
|
cmd_ele = ["SELECT DISTINCT basis_id FROM data_tab WHERE elt=?"] * len(elts)
|
||||||
|
cmd = " INTERSECT ".join(cmd_ele) + ";"
|
||||||
|
c.execute(cmd, elts)
|
||||||
|
|
||||||
c.execute("""SELECT DISTINCT name,description, LENGTH(data)- LENGTH(REPLACE(data, X'0A', ''))
|
dump = [i[0] for i in c.fetchall()]
|
||||||
FROM output_tab""")
|
cmd_basis = " ".join(cond_sql_or("basis_id", dump))
|
||||||
data = c.fetchall()
|
cmd_ele = " ".join(cond_sql_or("elt", elts))
|
||||||
|
|
||||||
|
if average_mo_number:
|
||||||
|
cmd = """SELECT DISTINCT name,description,data
|
||||||
|
FROM output_tab"""
|
||||||
|
|
||||||
else:
|
else:
|
||||||
cmd = ["""SELECT name,description, LENGTH(data)- LENGTH(REPLACE(data, X'0A', ''))
|
cmd = """SELECT DISTINCT name,description
|
||||||
FROM output_tab WHERE elt=?"""] * len(elts)
|
FROM output_tab"""
|
||||||
cmd = " INTERSECT ".join(cmd) + ";"
|
|
||||||
|
|
||||||
c.execute(cmd, elts)
|
cmd += " WHERE" + cmd_ele + " AND " + cmd_basis
|
||||||
data = c.fetchall()
|
|
||||||
|
|
||||||
data = [i[:] for i in data]
|
c.execute(cmd)
|
||||||
|
info = c.fetchall()
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
return data
|
# ~#~#~#~#~#~#~ #
|
||||||
|
# P a r s i n g #
|
||||||
|
# ~#~#~#~#~#~#~ #
|
||||||
|
|
||||||
|
dict_info = {}
|
||||||
|
# dict_info[name] = [description, nb_mo, nb_ele]
|
||||||
|
|
||||||
|
if average_mo_number:
|
||||||
|
|
||||||
|
for name, description, data in info:
|
||||||
|
nb_mo = 0
|
||||||
|
nb_ele = 0
|
||||||
|
for line in data.split("\n")[1:]:
|
||||||
|
str_l = line.split()[0]
|
||||||
|
try:
|
||||||
|
nb_mo += string_to_nb_mo(str_l)
|
||||||
|
nb_ele += 1
|
||||||
|
except BaseException:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
dict_info[name][1] += nb_mo
|
||||||
|
dict_info[name][2] += 1
|
||||||
|
except:
|
||||||
|
dict_info[name] = [description, nb_mo, nb_ele]
|
||||||
|
|
||||||
|
# ~#~#~#~#~#~ #
|
||||||
|
# R e t u r n #
|
||||||
|
# ~#~#~#~#~#~ #
|
||||||
|
|
||||||
|
if average_mo_number:
|
||||||
|
return[[k, v[0], v[1] / v[2]] for k, v in dict_info.iteritems()]
|
||||||
|
else:
|
||||||
|
return [i[:] for i in info]
|
||||||
|
|
||||||
def get_list_element_available(self, basis_name):
|
def get_list_element_available(self, basis_name):
|
||||||
|
|
||||||
conn = sqlite3.connect(self.db_path)
|
conn = sqlite3.connect(self.db_path)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
c.execute(
|
str_ = "SELECT DISTINCT elt from output_tab WHERE name=:name_us COLLATE NOCASE"
|
||||||
"SELECT DISTINCT elt from output_tab WHERE name=:name_us COLLATE NOCASE", {
|
c.execute(str_, {"name_us": basis_name})
|
||||||
"name_us": basis_name})
|
|
||||||
|
|
||||||
data = c.fetchall()
|
data = c.fetchall()
|
||||||
|
|
||||||
@ -424,10 +500,20 @@ class EMSL_local:
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def get_basis(self, basis_name, elts=None, with_l=False):
|
def get_basis(self, basis_name, elts=None, with_l=False):
|
||||||
|
"""
|
||||||
|
Return the data from the basis set
|
||||||
|
"""
|
||||||
import re
|
import re
|
||||||
|
|
||||||
def get_list_type(l_line):
|
def get_list_type(l_line):
|
||||||
|
"""
|
||||||
|
Return the begin and the end of all the type of orbital
|
||||||
|
Usefull for tranforming the L in S, P
|
||||||
|
output : [ [type, begin, end], ...]
|
||||||
|
"""
|
||||||
|
# Example
|
||||||
|
# [[u'S', 1, 5], [u'L', 5, 9], [u'L', 9, 12], [u'D', 16, 18]]"
|
||||||
|
|
||||||
l = []
|
l = []
|
||||||
for i, line in enumerate(l_line):
|
for i, line in enumerate(l_line):
|
||||||
|
|
||||||
@ -440,6 +526,7 @@ class EMSL_local:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
l[-1].append(i + 1)
|
l[-1].append(i + 1)
|
||||||
|
print l
|
||||||
return l
|
return l
|
||||||
|
|
||||||
# __ _
|
# __ _
|
||||||
@ -476,6 +563,7 @@ class EMSL_local:
|
|||||||
|
|
||||||
l_line_raw = basis.split("\n")
|
l_line_raw = basis.split("\n")
|
||||||
|
|
||||||
|
# l_line_raw[0] containt the name of the Atom
|
||||||
l_line = [l_line_raw[0]]
|
l_line = [l_line_raw[0]]
|
||||||
|
|
||||||
for symmetry, begin, end in get_list_type(l_line_raw):
|
for symmetry, begin, end in get_list_type(l_line_raw):
|
||||||
|
Loading…
Reference in New Issue
Block a user