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

172 lines
5.7 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-03-11 10:36:05 +01:00
EMSL_api.py list_basis [--basis=<basis_name>...]
[--atom=<atom_name>...]
[--db_path=<db_path>]
[--average_mo_number]
2015-01-20 14:20:06 +01:00
EMSL_api.py list_atoms --basis=<basis_name>
2015-03-11 10:36:05 +01:00
[--db_path=<db_path>]
2015-01-20 14:20:06 +01:00
EMSL_api.py get_basis_data --basis=<basis_name>
2015-03-12 10:50:42 +01:00
[--atom=<atom_name>...]
[--db_path=<db_path>]
[(--save [--path=<path>])]
2015-03-17 14:30:19 +01:00
[--check=<program_name>]
[--treat_l]
2015-01-09 15:44:03 +01:00
EMSL_api.py list_formats
2015-03-17 16:11:01 +01:00
EMSL_api.py create_db --format=<format>
[--db_path=<db_path>]
[--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
2015-01-20 14:24:44 +01:00
Example of use:
./EMSL_api.py list_basis --atom Al --atom U
2015-03-11 10:36:05 +01:00
./EMSL_api.py list_basis --atom S --basis 'cc-pV*' --average_mo_number
2015-01-20 14:24:44 +01:00
./EMSL_api.py list_atoms --basis ANO-RCC
./EMSL_api.py get_basis_data --basis 3-21++G*
2014-11-12 14:30:26 +01:00
"""
2015-03-17 15:39:51 +01:00
version = "0.8.1"
2014-11-12 15:35:31 +01:00
2015-01-15 23:19:40 +01:00
import os
2014-11-12 14:30:26 +01:00
2015-03-17 15:39:51 +01:00
from src.misc.docopt import docopt
2015-03-11 10:32:44 +01:00
from src.EMSL_dump import EMSL_dump
from src.EMSL_local 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-03-10 19:30:11 +01:00
raise
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"]:
2015-03-16 19:10:55 +01:00
e = EMSL_local(db_path=db_path)
2014-11-12 14:30:26 +01:00
2015-03-16 19:24:39 +01:00
l = e.list_basis_available(arguments["--atom"],
arguments["--basis"],
arguments["--average_mo_number"])
2015-03-10 19:30:11 +01:00
2015-03-16 19:24:39 +01:00
if arguments["--average_mo_number"]:
2015-03-10 19:30:11 +01:00
for name, des, avg in l:
2015-03-11 10:32:44 +01:00
print "- '{}' ({}) || {:<50}".format(name, avg, des)
2015-03-10 19:30:11 +01:00
else:
for name, des in l:
print "- '{}' || {:<50}".format(name, des)
2014-11-12 14:30:26 +01:00
2015-01-20 14:20:06 +01:00
# _ _ _ _____ _ _
# | | (_) | | | ___| | | |
# | | _ ___| |_ | |__ | | ___ _ __ ___ ___ _ __ | |_ ___
# | | | / __| __| | __|| |/ _ \ '_ ` _ \ / _ \ '_ \| __/ __|
# | |___| \__ \ |_ | |___| | __/ | | | | | __/ | | | |_\__ \
# \_____/_|___/\__| \____/|_|\___|_| |_| |_|\___|_| |_|\__|___/
2015-03-16 19:10:55 +01:00
elif 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-03-16 19:10:55 +01:00
elif arguments["get_basis_data"]:
e = EMSL_local(db_path=db_path)
2015-03-12 09:49:06 +01:00
basis_name = arguments["--basis"][0]
2015-01-08 17:07:53 +01:00
elts = arguments["--atom"]
2014-11-12 14:30:26 +01:00
l_atom_basis = e.get_basis(basis_name, elts,
arguments["--treat_l"],
arguments["--check"])
2015-03-12 14:04:42 +01:00
# Add separation between atoms, and a empty last line
str_ = "\n\n".join(l_atom_basis) + "\n"
2015-01-08 16:12:15 +01:00
if arguments["--save"]:
if arguments["--path"]:
path = arguments["--path"]
else:
2015-03-16 19:24:39 +01:00
# The defaut path is bais
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-03-16 19:10:55 +01:00
elif 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-03-16 19:10:55 +01:00
elif arguments["create_db"]:
2015-01-08 16:12:15 +01:00
db_path = arguments["--db_path"]
format = arguments["--format"]
2015-01-16 16:51:56 +01:00
2014-11-12 15:35:31 +01:00
contraction = not arguments["--no-contraction"]
2014-11-12 14:30:26 +01:00
2015-03-12 14:30:43 +01:00
e = EMSL_dump(db_path=db_path,
format=format,
2015-03-12 14:30:43 +01:00
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()))