mirror of
https://github.com/LCPQ/EMSL_Basis_Set_Exchange_Local
synced 2025-01-03 01:55:54 +01:00
New design for basis set
This commit is contained in:
parent
d9fdab2469
commit
7c6812f258
92
EMSL_api.py
92
EMSL_api.py
@ -4,18 +4,18 @@
|
|||||||
"""EMSL Api.
|
"""EMSL Api.
|
||||||
|
|
||||||
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>]
|
||||||
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>
|
||||||
[--atom=atom_name...]
|
[--atom=<atom_name>...]
|
||||||
[--db_path=db_path]
|
[--db_path=<db_path>]
|
||||||
[--with_l]
|
[--with_l]
|
||||||
[(--save [--path=path])]
|
[(--save [--path=<path>])]
|
||||||
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>
|
||||||
[--no-contraction]
|
[--no-contraction]
|
||||||
EMSL_api.py (-h | --help)
|
EMSL_api.py (-h | --help)
|
||||||
EMSL_api.py --version
|
EMSL_api.py --version
|
||||||
@ -59,13 +59,13 @@ if __name__ == '__main__':
|
|||||||
except:
|
except:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# _ _ _ ______ _
|
# _ _ _ ______ _
|
||||||
#| | (_) | | | ___ \ (_)
|
# | | (_) | | | ___ \ (_)
|
||||||
#| | _ ___| |_ | |_/ / __ _ ___ _ ___
|
# | | _ ___| |_ | |_/ / __ _ ___ _ ___
|
||||||
#| | | / __| __| | ___ \/ _` / __| / __|
|
# | | | / __| __| | ___ \/ _` / __| / __|
|
||||||
#| |___| \__ \ |_ | |_/ / (_| \__ \ \__ \
|
# | |___| \__ \ |_ | |_/ / (_| \__ \ \__ \
|
||||||
#\_____/_|___/\__| \____/ \__,_|___/_|___/
|
# \_____/_|___/\__| \____/ \__,_|___/_|___/
|
||||||
#
|
|
||||||
if arguments["list_basis"]:
|
if arguments["list_basis"]:
|
||||||
e = EMSL_local(db_path=db_path)
|
e = EMSL_local(db_path=db_path)
|
||||||
|
|
||||||
@ -75,12 +75,12 @@ if __name__ == '__main__':
|
|||||||
for name, des in l:
|
for name, des in l:
|
||||||
print name, "|", des
|
print name, "|", des
|
||||||
|
|
||||||
# _ _ _ _____ _ _
|
# _ _ _ _____ _ _
|
||||||
#| | (_) | | | ___| | | |
|
# | | (_) | | | ___| | | |
|
||||||
#| | _ ___| |_ | |__ | | ___ _ __ ___ ___ _ __ | |_ ___
|
# | | _ ___| |_ | |__ | | ___ _ __ ___ ___ _ __ | |_ ___
|
||||||
#| | | / __| __| | __|| |/ _ \ '_ ` _ \ / _ \ '_ \| __/ __|
|
# | | | / __| __| | __|| |/ _ \ '_ ` _ \ / _ \ '_ \| __/ __|
|
||||||
#| |___| \__ \ |_ | |___| | __/ | | | | | __/ | | | |_\__ \
|
# | |___| \__ \ |_ | |___| | __/ | | | | | __/ | | | |_\__ \
|
||||||
#\_____/_|___/\__| \____/|_|\___|_| |_| |_|\___|_| |_|\__|___/
|
# \_____/_|___/\__| \____/|_|\___|_| |_| |_|\___|_| |_|\__|___/
|
||||||
if arguments["list_atoms"]:
|
if arguments["list_atoms"]:
|
||||||
e = EMSL_local(db_path=db_path)
|
e = EMSL_local(db_path=db_path)
|
||||||
|
|
||||||
@ -88,12 +88,12 @@ if __name__ == '__main__':
|
|||||||
l = e.get_list_element_available(basis_name)
|
l = e.get_list_element_available(basis_name)
|
||||||
print ", ".join(l)
|
print ", ".join(l)
|
||||||
|
|
||||||
#______ _ _ _
|
# ______ _ _ _
|
||||||
#| ___ \ (_) | | | |
|
# | ___ \ (_) | | | |
|
||||||
#| |_/ / __ _ ___ _ ___ __| | __ _| |_ __ _
|
# | |_/ / __ _ ___ _ ___ __| | __ _| |_ __ _
|
||||||
#| ___ \/ _` / __| / __| / _` |/ _` | __/ _` |
|
# | ___ \/ _` / __| / __| / _` |/ _` | __/ _` |
|
||||||
#| |_/ / (_| \__ \ \__ \ | (_| | (_| | || (_| |
|
# | |_/ / (_| \__ \ \__ \ | (_| | (_| | || (_| |
|
||||||
#\____/ \__,_|___/_|___/ \__,_|\__,_|\__\__,_|
|
# \____/ \__,_|___/_|___/ \__,_|\__,_|\__\__,_|
|
||||||
if arguments["get_basis_data"]:
|
if arguments["get_basis_data"]:
|
||||||
e = EMSL_local(db_path=db_path)
|
e = EMSL_local(db_path=db_path)
|
||||||
basis_name = arguments["--basis"]
|
basis_name = arguments["--basis"]
|
||||||
@ -116,23 +116,23 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
print str_
|
print str_
|
||||||
|
|
||||||
# _ _ _ __ _
|
# _ _ _ __ _
|
||||||
#| | (_) | | / _| | |
|
# | | (_) | | / _| | |
|
||||||
#| | _ ___| |_ | |_ ___ _ __ _ __ ___ __ _| |_ ___
|
# | | _ ___| |_ | |_ ___ _ __ _ __ ___ __ _| |_ ___
|
||||||
#| | | / __| __| | _/ _ \| '__| '_ ` _ \ / _` | __/ __|
|
# | | | / __| __| | _/ _ \| '__| '_ ` _ \ / _` | __/ __|
|
||||||
#| |___| \__ \ |_ | || (_) | | | | | | | | (_| | |_\__ \
|
# | |___| \__ \ |_ | || (_) | | | | | | | | (_| | |_\__ \
|
||||||
#\_____/_|___/\__| |_| \___/|_| |_| |_| |_|\__,_|\__|___/
|
# \_____/_|___/\__| |_| \___/|_| |_| |_| |_|\__,_|\__|___/
|
||||||
if arguments["list_formats"]:
|
if arguments["list_formats"]:
|
||||||
e = EMSL_dump()
|
e = EMSL_dump()
|
||||||
for i in e.get_list_format():
|
for i in e.get_list_format():
|
||||||
print i
|
print i
|
||||||
|
|
||||||
# _____ _ _ _
|
# _____ _ _ _
|
||||||
#/ __ \ | | | | |
|
# / __ \ | | | | |
|
||||||
#| / \/_ __ ___ __ _| |_ ___ __| | |__
|
# | / \/_ __ ___ __ _| |_ ___ __| | |__
|
||||||
#| | | '__/ _ \/ _` | __/ _ \ / _` | '_ \
|
# | | | '__/ _ \/ _` | __/ _ \ / _` | '_ \
|
||||||
#| \__/\ | | __/ (_| | || __/ | (_| | |_) |
|
# | \__/\ | | __/ (_| | || __/ | (_| | |_) |
|
||||||
# \____/_| \___|\__,_|\__\___| \__,_|_.__/
|
# \____/_| \___|\__,_|\__\___| \__,_|_.__/
|
||||||
if arguments["create_db"]:
|
if arguments["create_db"]:
|
||||||
db_path = arguments["--db_path"]
|
db_path = arguments["--db_path"]
|
||||||
format = arguments["--format"]
|
format = arguments["--format"]
|
||||||
@ -149,11 +149,11 @@ if __name__ == '__main__':
|
|||||||
contraction=contraction)
|
contraction=contraction)
|
||||||
e.new_db()
|
e.new_db()
|
||||||
|
|
||||||
# _
|
# _
|
||||||
# / | _ _. ._ o ._ _
|
# / | _ _. ._ o ._ _
|
||||||
# \_ | (/_ (_| | | | | | (_|
|
# \_ | (/_ (_| | | | | | (_|
|
||||||
# _|
|
# _|
|
||||||
|
|
||||||
# Clean up on exit
|
# Clean up on exit
|
||||||
if db_path_changed:
|
if not(arguments['create_db']) and db_path_changed:
|
||||||
os.system("rm -f /dev/shm/%d.db" % (os.getpid()))
|
os.system("rm -f /dev/shm/%d.db" % (os.getpid()))
|
||||||
|
BIN
db/Gamess-us.db
BIN
db/Gamess-us.db
Binary file not shown.
@ -6,7 +6,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
debug = False
|
debug = True
|
||||||
|
|
||||||
|
|
||||||
def checkSQLite3(db_path):
|
def checkSQLite3(db_path):
|
||||||
@ -189,7 +189,7 @@ class EMSL_dump:
|
|||||||
|
|
||||||
elts = re.sub('[["\ \]]', '', tup[3]).split(',')
|
elts = re.sub('[["\ \]]', '', tup[3]).split(',')
|
||||||
|
|
||||||
des = tup[-1]
|
des = re.sub('\s+', ' ', tup[-1])
|
||||||
|
|
||||||
if "-ecp" in xml_path.lower():
|
if "-ecp" in xml_path.lower():
|
||||||
continue
|
continue
|
||||||
@ -229,18 +229,20 @@ class EMSL_dump:
|
|||||||
elt_long_exp = data_elt.split()[0].lower()
|
elt_long_exp = data_elt.split()[0].lower()
|
||||||
|
|
||||||
if "$" in data_elt:
|
if "$" in data_elt:
|
||||||
print "Eror",
|
if debug:
|
||||||
|
print "Eror",
|
||||||
raise Exception("WARNING not bad split")
|
raise Exception("WARNING not bad split")
|
||||||
|
|
||||||
if elt_long_th == elt_long_exp:
|
if elt_long_th == elt_long_exp:
|
||||||
d.append((name, des, elt, data_elt.strip()))
|
d.append([elt, data_elt.strip()])
|
||||||
else:
|
else:
|
||||||
print "th", elt_long_th
|
if debug:
|
||||||
print "exp", elt_long_exp
|
print "th", elt_long_th
|
||||||
print "abv", elt
|
print "exp", elt_long_exp
|
||||||
|
print "abv", elt
|
||||||
raise Exception("WARNING not good ELEMENT")
|
raise Exception("WARNING not good ELEMENT")
|
||||||
|
|
||||||
return d
|
return [name, des, d]
|
||||||
|
|
||||||
def create_sql(self, list_basis_array):
|
def create_sql(self, list_basis_array):
|
||||||
"""Create the sql from the list of basis available data"""
|
"""Create the sql from the list of basis available data"""
|
||||||
@ -248,9 +250,32 @@ class EMSL_dump:
|
|||||||
conn = sqlite3.connect(self.db_path)
|
conn = sqlite3.connect(self.db_path)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
# Create table
|
c.execute('''CREATE TABLE basis_tab(
|
||||||
c.execute('''CREATE TABLE all_value
|
basis_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
(name text, description text, elt text, data text)''')
|
name text,
|
||||||
|
description text,
|
||||||
|
UNIQUE(name)
|
||||||
|
);''')
|
||||||
|
|
||||||
|
c.execute('''CREATE TABLE data_tab(
|
||||||
|
basis_id INTEGER,
|
||||||
|
elt TEXT,
|
||||||
|
data TEXT,
|
||||||
|
FOREIGN KEY(basis_id)
|
||||||
|
REFERENCES basis_tab(basis_id)
|
||||||
|
);''')
|
||||||
|
|
||||||
|
c.execute(''' CREATE VIEW output_tab AS
|
||||||
|
SELECT basis_id,
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
elt,
|
||||||
|
data
|
||||||
|
FROM basis_tab
|
||||||
|
NATURAL JOIN data_tab
|
||||||
|
''')
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
import Queue
|
import Queue
|
||||||
import threading
|
import threading
|
||||||
@ -264,7 +289,7 @@ class EMSL_dump:
|
|||||||
def worker():
|
def worker():
|
||||||
"""get a Job from the q_in, do stuff, when finish put it in the q_out"""
|
"""get a Job from the q_in, do stuff, when finish put it in the q_out"""
|
||||||
while True:
|
while True:
|
||||||
[name, path_xml, des, elts] = q_in.get()
|
name, path_xml, des, elts = q_in.get()
|
||||||
|
|
||||||
url = "https://bse.pnl.gov:443/bse/portal/user/anon/js_peid/11535052407933/action/portlets.BasisSetAction/template/courier_content/panel/Main/"
|
url = "https://bse.pnl.gov:443/bse/portal/user/anon/js_peid/11535052407933/action/portlets.BasisSetAction/template/courier_content/panel/Main/"
|
||||||
url += "/eventSubmit_doDownload/true"
|
url += "/eventSubmit_doDownload/true"
|
||||||
@ -286,16 +311,16 @@ class EMSL_dump:
|
|||||||
attemps += 1
|
attemps += 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
q_out.put(([name, path_xml, des, elts], basis_data))
|
q_out.put(basis_data)
|
||||||
q_in.task_done()
|
q_in.task_done()
|
||||||
except:
|
except:
|
||||||
if debug:
|
if debug:
|
||||||
print "Fail on q_out.put", name, path_xml, des
|
print "Fail on q_out.put", basis_data
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def enqueue():
|
def enqueue():
|
||||||
for [name, path_xml, des, elts] in list_basis_array:
|
for [name, path_xml, des, elts] in list_basis_array:
|
||||||
q_in.put(([name, path_xml, des, elts]))
|
q_in.put([name, path_xml, des, elts])
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@ -311,17 +336,30 @@ class EMSL_dump:
|
|||||||
nb_basis = len(list_basis_array)
|
nb_basis = len(list_basis_array)
|
||||||
|
|
||||||
for i in range(nb_basis):
|
for i in range(nb_basis):
|
||||||
[name, path_xml, des, elts], basis_data = q_out.get()
|
name, des, d = q_out.get()
|
||||||
|
q_out.task_done()
|
||||||
|
|
||||||
|
try:
|
||||||
|
c.execute(
|
||||||
|
"INSERT INTO basis_tab(name,description) VALUES (?,?)", [
|
||||||
|
name, des])
|
||||||
|
conn.commit()
|
||||||
|
except sqlite3.IntegrityError:
|
||||||
|
print '{:>3}'.format(i + 1), "/", nb_basis, name, "fail"
|
||||||
|
|
||||||
|
id_ = c.lastrowid
|
||||||
try:
|
try:
|
||||||
c.executemany(
|
c.executemany(
|
||||||
"INSERT INTO all_value VALUES (?,?,?,?)", basis_data)
|
"INSERT INTO data_tab VALUES (?,?,?)", [
|
||||||
|
[id_] + k for k in d])
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
print '{:>3}'.format(i + 1), "/", nb_basis, name
|
print '{:>3}'.format(i + 1), "/", nb_basis, name
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print '{:>3}'.format(i + 1), "/", nb_basis, name, "fail"
|
print '{:>3}'.format(i + 1), "/", nb_basis, name, "fail"
|
||||||
raise
|
raise
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
q_in.join()
|
q_in.join()
|
||||||
@ -348,12 +386,12 @@ class EMSL_local:
|
|||||||
|
|
||||||
if not elts:
|
if not elts:
|
||||||
|
|
||||||
c.execute("SELECT DISTINCT name,description from all_value")
|
c.execute("SELECT DISTINCT name,description from basis_tab")
|
||||||
data = c.fetchall()
|
data = c.fetchall()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
cmd = [
|
cmd = [
|
||||||
"SELECT name,description FROM all_value WHERE elt=?"] * len(elts)
|
"SELECT name,description FROM output_tab WHERE elt=?"] * len(elts)
|
||||||
cmd = " INTERSECT ".join(cmd) + ";"
|
cmd = " INTERSECT ".join(cmd) + ";"
|
||||||
|
|
||||||
c.execute(cmd, elts)
|
c.execute(cmd, elts)
|
||||||
@ -371,7 +409,7 @@ class EMSL_local:
|
|||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
c.execute(
|
c.execute(
|
||||||
"SELECT DISTINCT elt from all_value WHERE name=:name_us COLLATE NOCASE", {
|
"SELECT DISTINCT elt from output_tab WHERE name=:name_us COLLATE NOCASE", {
|
||||||
"name_us": basis_name})
|
"name_us": basis_name})
|
||||||
|
|
||||||
data = c.fetchall()
|
data = c.fetchall()
|
||||||
@ -383,6 +421,8 @@ class EMSL_local:
|
|||||||
|
|
||||||
def get_basis(self, basis_name, elts=None, with_l=False):
|
def get_basis(self, basis_name, elts=None, with_l=False):
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
def get_list_type(l_line):
|
def get_list_type(l_line):
|
||||||
l = []
|
l = []
|
||||||
for i, line in enumerate(l_line):
|
for i, line in enumerate(l_line):
|
||||||
@ -398,8 +438,6 @@ class EMSL_local:
|
|||||||
l[-1].append(i + 1)
|
l[-1].append(i + 1)
|
||||||
return l
|
return l
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
# __ _
|
# __ _
|
||||||
# /__ _ _|_ _|_ ._ _ ._ _ _ _. |
|
# /__ _ _|_ _|_ ._ _ ._ _ _ _. |
|
||||||
# \_| (/_ |_ | | (_) | | | _> (_| |
|
# \_| (/_ |_ | | (_) | | | _> (_| |
|
||||||
@ -412,7 +450,7 @@ class EMSL_local:
|
|||||||
else:
|
else:
|
||||||
cmd_ele = ""
|
cmd_ele = ""
|
||||||
|
|
||||||
c.execute('''SELECT DISTINCT data from all_value
|
c.execute('''SELECT DISTINCT data from output_tab
|
||||||
WHERE name="{basis_name}" COLLATE NOCASE
|
WHERE name="{basis_name}" COLLATE NOCASE
|
||||||
{cmd_ele}'''.format(basis_name=basis_name,
|
{cmd_ele}'''.format(basis_name=basis_name,
|
||||||
cmd_ele=cmd_ele))
|
cmd_ele=cmd_ele))
|
||||||
|
Loading…
Reference in New Issue
Block a user