EMSL_Basis_Set_Exchange_Local/EMSL_api.py

181 lines
6.4 KiB
Python
Raw Permalink Normal View History

2018-07-27 15:14:58 +02:00
#!/usr/bin/env python2
2014-11-12 14:30:26 +01:00
# -*- coding: utf-8 -*-
"""EMSL Api.
Usage:
2015-03-18 13:32:13 +01:00
EMSL_api.py list_basis [--basis=<basis_name>...]
[--atom=<atom_name>...]
2016-01-15 10:09:24 +01:00
[--db_path=<db_path> |--db_dump_path=<db_dump_path>]
2015-03-18 13:32:13 +01:00
[--average_mo_number]
EMSL_api.py list_atoms --basis=<basis_name>
2016-01-15 10:09:24 +01:00
[--db_path=<db_path> |--db_dump_path=<db_dump_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>...]
2016-01-15 10:09:24 +01:00
[--db_path=<db_path> |--db_dump_path=<db_dump_path>]
2015-03-12 10:50:42 +01:00
[(--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-18 13:32:13 +01:00
EMSL_api.py create_db --format=<format>
2016-01-15 10:09:24 +01:00
[--db_path=<db_path> |--db_dump_path=<db_dump_path>]
2015-03-17 16:11:01 +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
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
2015-03-23 15:05:24 +01:00
from src.EMSL_local import EMSL_local
2014-11-12 14:30:26 +01:00
if __name__ == '__main__':
arguments = docopt(__doc__, version='EMSL Api ' + version)
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"]
2016-01-15 10:09:24 +01:00
db_dump_path = None
elif arguments["--db_dump_path"]:
2018-07-27 15:08:50 +02:00
db_path = None
db_dump_path = arguments["--db_dump_path"]
2015-01-08 16:12:15 +01:00
else:
2018-07-27 15:08:50 +02:00
db_dump_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
2016-01-15 10:09:24 +01:00
"db/GAMESS-US.dump")
db_path = None
# db_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
# "db/GAMESS-US.db")
2015-01-08 16:12:15 +01:00
2015-01-16 09:38:12 +01:00
# Check the db
2016-01-15 10:09:24 +01:00
# try:
# if not(arguments['create_db']):
# from src.EMSL_local import checkSQLite3
# db_path, db_path_changed = checkSQLite3(db_path)
# except:
# 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"]:
2016-01-15 10:09:24 +01:00
e = EMSL_local(db_path=db_path, db_dump_path=db_dump_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-26 19:36:52 +01:00
des_str = "{0:<50}".format(des)
2015-03-24 13:56:46 +01:00
print "- '{0}' ({1}) || {2}".format(name, avg, des_str)
2015-03-10 19:30:11 +01:00
else:
for name, des in l:
2015-03-26 19:36:52 +01:00
des_str = "{0:<50}".format(des)
2015-03-24 13:56:46 +01:00
print "- '{0}' || {1}".format(name, des_str)
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"]:
2016-01-15 10:09:24 +01:00
e = EMSL_local(db_path=db_path, db_dump_path=db_dump_path)
2014-11-12 14:30:26 +01:00
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"]:
2016-01-15 10:09:24 +01:00
e = EMSL_local(db_path=db_path, db_dump_path=db_dump_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-03-23 15:12:23 +01:00
for i in EMSL_dump.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
2016-01-15 10:09:24 +01:00
# if not(arguments['create_db']) and db_path_changed:
# os.system("rm -f /dev/shm/%d.db" % (os.getpid()))