10
0
mirror of https://github.com/LCPQ/EMSL_Basis_Set_Exchange_Local synced 2024-07-27 21:27:33 +02:00
EMSL_Basis_Set_Exchange_Local/EMSL_api.py

160 lines
5.1 KiB
Python
Raw Normal View History

2014-11-12 14:30:26 +01:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""EMSL Api.
Usage:
2015-01-20 14:20:06 +01:00
EMSL_api.py list_basis [--atom=<atom_name>...]
[--db_path=<db_path>]
EMSL_api.py list_atoms --basis=<basis_name>
[--db_path=<db_path>]
EMSL_api.py get_basis_data --basis=<basis_name>
[--atom=<atom_name>...]
[--db_path=<db_path>]
2015-01-09 13:17:37 +01:00
[--with_l]
2015-01-20 14:20:06 +01:00
[(--save [--path=<path>])]
2015-01-09 15:44:03 +01:00
EMSL_api.py list_formats
2015-01-20 14:20:06 +01:00
EMSL_api.py create_db --db_path=<db_path>
--format=<format>
2015-01-08 16:12:15 +01:00
[--no-contraction]
2014-11-12 14:30:26 +01:00
EMSL_api.py (-h | --help)
EMSL_api.py --version
Options:
2014-11-12 15:35:31 +01:00
-h --help Show this screen.
--version Show version.
--no-contraction Basis functions are not contracted
<db_path> is the path to the SQLite3 file containing the Basis sets.
2015-01-08 16:12:15 +01:00
By default is $EMSL_API_ROOT/db/Gausian_uk.db
2014-11-12 14:30:26 +01:00
"""
2015-01-08 16:12:15 +01:00
version = "0.2.0"
2014-11-12 15:35:31 +01:00
2014-11-12 14:30:26 +01:00
import sys
2015-01-15 23:19:40 +01:00
import os
2014-11-12 14:30:26 +01:00
2015-01-12 12:22:18 +01:00
from src.docopt import docopt
from src.EMSL_utility import EMSL_dump
2015-01-16 09:38:12 +01:00
from src.EMSL_utility import EMSL_local, checkSQLite3
2014-11-12 14:30:26 +01:00
if __name__ == '__main__':
arguments = docopt(__doc__, version='EMSL Api ' + version)
2014-11-12 15:35:31 +01:00
2015-01-16 09:38:12 +01:00
# ___
# | ._ o _|_
# _|_ | | | |_
#
2015-01-08 16:12:15 +01:00
if arguments["--db_path"]:
db_path = arguments["--db_path"]
else:
2015-01-12 12:22:18 +01:00
db_path = os.path.dirname(__file__) + "/db/Gamess-us.db"
2015-01-08 16:12:15 +01:00
2015-01-16 09:38:12 +01:00
# Check the db
2015-01-15 23:19:40 +01:00
try:
2015-01-16 16:51:56 +01:00
if not(arguments['create_db']):
db_path, db_path_changed = checkSQLite3(db_path)
2015-01-15 23:19:40 +01:00
except:
2015-01-16 09:38:12 +01:00
sys.exit(1)
2015-01-15 23:19:40 +01:00
2015-01-20 14:20:06 +01:00
# _ _ _ ______ _
# | | (_) | | | ___ \ (_)
# | | _ ___| |_ | |_/ / __ _ ___ _ ___
# | | | / __| __| | ___ \/ _` / __| / __|
# | |___| \__ \ |_ | |_/ / (_| \__ \ \__ \
# \_____/_|___/\__| \____/ \__,_|___/_|___/
2015-01-08 16:12:15 +01:00
if arguments["list_basis"]:
2014-11-12 14:30:26 +01:00
e = EMSL_local(db_path=db_path)
2015-01-08 17:07:53 +01:00
elts = arguments["--atom"]
2015-01-08 16:12:15 +01:00
l = e.get_list_basis_available(elts)
2014-11-12 14:30:26 +01:00
2015-01-08 16:12:15 +01:00
for name, des in l:
print name, "|", des
2014-11-12 14:30:26 +01:00
2015-01-20 14:20:06 +01:00
# _ _ _ _____ _ _
# | | (_) | | | ___| | | |
# | | _ ___| |_ | |__ | | ___ _ __ ___ ___ _ __ | |_ ___
# | | | / __| __| | __|| |/ _ \ '_ ` _ \ / _ \ '_ \| __/ __|
# | |___| \__ \ |_ | |___| | __/ | | | | | __/ | | | |_\__ \
# \_____/_|___/\__| \____/|_|\___|_| |_| |_|\___|_| |_|\__|___/
2015-01-08 17:07:53 +01:00
if arguments["list_atoms"]:
2014-11-12 14:30:26 +01:00
e = EMSL_local(db_path=db_path)
2015-01-08 16:12:15 +01:00
basis_name = arguments["--basis"]
l = e.get_list_element_available(basis_name)
print ", ".join(l)
2015-01-20 14:20:06 +01:00
# ______ _ _ _
# | ___ \ (_) | | | |
# | |_/ / __ _ ___ _ ___ __| | __ _| |_ __ _
# | ___ \/ _` / __| / __| / _` |/ _` | __/ _` |
# | |_/ / (_| \__ \ \__ \ | (_| | (_| | || (_| |
# \____/ \__,_|___/_|___/ \__,_|\__,_|\__\__,_|
2015-01-08 16:12:15 +01:00
if arguments["get_basis_data"]:
2014-11-12 14:30:26 +01:00
e = EMSL_local(db_path=db_path)
2015-01-08 16:58:57 +01:00
basis_name = arguments["--basis"]
2015-01-08 17:07:53 +01:00
elts = arguments["--atom"]
2014-11-12 14:30:26 +01:00
2015-01-16 09:38:12 +01:00
l = e.get_basis(basis_name, elts, arguments["--with_l"])
2015-01-08 16:12:15 +01:00
str_ = "\n\n".join(l) + "\n"
if arguments["--save"]:
if arguments["--path"]:
path = arguments["--path"]
else:
2015-01-08 17:07:53 +01:00
path = "_".join([basis_name, ".".join(elts)])
path = "/tmp/" + path + ".bs"
2015-01-08 16:12:15 +01:00
with open(path, 'w') as f:
f.write(str_ + "\n")
print path
else:
print str_
2015-01-20 14:20:06 +01:00
# _ _ _ __ _
# | | (_) | | / _| | |
# | | _ ___| |_ | |_ ___ _ __ _ __ ___ __ _| |_ ___
# | | | / __| __| | _/ _ \| '__| '_ ` _ \ / _` | __/ __|
# | |___| \__ \ |_ | || (_) | | | | | | | | (_| | |_\__ \
# \_____/_|___/\__| |_| \___/|_| |_| |_| |_|\__,_|\__|___/
2015-01-09 15:44:03 +01:00
if arguments["list_formats"]:
2015-01-16 09:38:12 +01:00
e = EMSL_dump()
for i in e.get_list_format():
2014-11-12 14:30:26 +01:00
print i
2015-01-20 14:20:06 +01:00
# _____ _ _ _
# / __ \ | | | | |
# | / \/_ __ ___ __ _| |_ ___ __| | |__
# | | | '__/ _ \/ _` | __/ _ \ / _` | '_ \
# | \__/\ | | __/ (_| | || __/ | (_| | |_) |
# \____/_| \___|\__,_|\__\___| \__,_|_.__/
2015-01-08 16:12:15 +01:00
if arguments["create_db"]:
db_path = arguments["--db_path"]
format = arguments["--format"]
2015-01-16 16:51:56 +01:00
format_dict = EMSL_dump().get_list_format()
2014-11-12 15:35:31 +01:00
if format not in format_dict:
2015-01-09 15:44:03 +01:00
print "Format %s doesn't exist. Run list_formats to get the list of formats." % (format)
sys.exit(1)
2014-11-12 15:35:31 +01:00
contraction = not arguments["--no-contraction"]
2014-11-12 14:30:26 +01:00
e = EMSL_dump(
2015-01-08 16:12:15 +01:00
db_path=db_path,
format=format_dict[format],
contraction=contraction)
2014-11-12 14:30:26 +01:00
e.new_db()
2015-01-15 23:19:40 +01:00
2015-01-20 14:20:06 +01:00
# _
# / | _ _. ._ o ._ _
# \_ | (/_ (_| | | | | | (_|
# _|
2015-01-15 23:19:40 +01:00
# Clean up on exit
2015-01-20 14:20:06 +01:00
if not(arguments['create_db']) and db_path_changed:
2015-01-16 09:38:12 +01:00
os.system("rm -f /dev/shm/%d.db" % (os.getpid()))