10
0
mirror of https://github.com/LCPQ/EMSL_Basis_Set_Exchange_Local synced 2024-12-22 20:34:23 +01:00
EMSL_Basis_Set_Exchange_Local/EMSL_api.py

137 lines
4.6 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-08 17:07:53 +01:00
EMSL_api.py list_basis [--atom=atom_name...]
2015-01-08 16:12:15 +01:00
[--db_path=db_path]
2015-01-08 17:07:53 +01:00
EMSL_api.py list_atoms --basis=basis_name
2015-01-08 16:12:15 +01:00
[--db_path=db_path]
EMSL_api.py get_basis_data --basis=basis_name
2015-01-08 17:07:53 +01:00
[--atom=atom_name...]
2015-01-08 16:12:15 +01:00
[--db_path=db_path]
2015-01-09 13:17:37 +01:00
[--with_l]
2015-01-08 16:12:15 +01:00
[(--save [--path=path])]
2015-01-09 15:44:03 +01:00
EMSL_api.py list_formats
2015-01-08 16:12:15 +01:00
EMSL_api.py create_db --db_path=db_path
2015-01-09 15:44:03 +01:00
--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-12 12:22:18 +01:00
from src.docopt import docopt
from src.EMSL_utility import EMSL_dump
from src.EMSL_utility import format_dict
from src.EMSL_utility import EMSL_local
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-08 16:12:15 +01:00
if arguments["--db_path"]:
db_path = arguments["--db_path"]
else:
import os
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
# _ _ _ ______ _
#| | (_) | | | ___ \ (_)
#| | _ ___| |_ | |_/ / __ _ ___ _ ___
#| | | / __| __| | ___ \/ _` / __| / __|
#| |___| \__ \ |_ | |_/ / (_| \__ \ \__ \
#\_____/_|___/\__| \____/ \__,_|___/_|___/
#
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-08 16:12:15 +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)
#______ _ _ _
#| ___ \ (_) | | | |
#| |_/ / __ _ ___ _ ___ __| | __ _| |_ __ _
#| ___ \/ _` / __| / __| / _` |/ _` | __/ _` |
#| |_/ / (_| \__ \ \__ \ | (_| | (_| | || (_| |
#\____/ \__,_|___/_|___/ \__,_|\__,_|\__\__,_|
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-09 13:17:37 +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-09 15:44:03 +01:00
if arguments["list_formats"]:
2014-11-12 15:35:31 +01:00
for i in format_dict:
2014-11-12 14:30:26 +01:00
print i
2015-01-08 16:12:15 +01:00
# _____ _ _ _
#/ __ \ | | | | |
#| / \/_ __ ___ __ _| |_ ___ __| | |__
#| | | '__/ _ \/ _` | __/ _ \ / _` | '_ \
#| \__/\ | | __/ (_| | || __/ | (_| | |_) |
# \____/_| \___|\__,_|\__\___| \__,_|_.__/
if arguments["create_db"]:
db_path = arguments["--db_path"]
format = arguments["--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()