Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions PyVOTCA/schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

"""Module with the schemas to validate the user input."""

from multiprocessing import cpu_count
from numbers import Integral
from typing import Any, Dict

import yaml
from schema import Optional, Or, Schema, SchemaError

__all__ = ["validate_input"]


input_schema = Schema({
# Path to the molecule in xyz format
"molecule": str,

# Number of Threads to run the application
Optional("threads", default=cpu_count()): Integral,

# Functional
Optional("functional", default="PBE"): str,

# Basisset
Optional("basis", default=None): Or(str, None),

# AuxBasisset
Optional("auxbasis", default=None): Or(str, None),

# GW
Optional("gw", default=None): Or(str, None),

# BSE
Optional("bse", default=None): Or(str, None),
})


def validate_input(file_input: str) -> Dict[str, Any]:
"""Check the input validation against an schema."""
with open(file_input, 'r') as handler:
dict_input = yaml.load(handler.read(), Loader=yaml.FullLoader)
try:
inp = input_schema.validate(dict_input)
return inp
except SchemaError as err:
msg = f"There was an error in the input yaml provided:\n{err}"
print(msg)
raise
15 changes: 9 additions & 6 deletions PyVOTCA/xtp_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys

from .numerical_gradient import NumericalGradient
from .schemas import validate_input


def exists(input_file: str) -> Path:
Expand Down Expand Up @@ -35,22 +36,24 @@ def xtp_gradient(args: argparse.Namespace):
def parse_user_arguments() -> argparse.Namespace:
"""Read the user arguments."""
parser = argparse.ArgumentParser("xtp_gradient")
parser.add_argument("-n", "--name", help="Molecule name")
parser.add_argument("-t", "--threads", help="Number of threads")
parser.add_argument(
"-i", "--input", help="Input file in YAML format", type=exists)

# Read the arguments
args = parser.parse_args()

if args.name is None:
if args.input is None:
parser.print_help()
sys.exit()

return args
return args.input


def main():
args = parse_user_arguments()
xtp_gradient(args)
inp = parse_user_arguments()
args = validate_input(inp)
print(args)
# xtp_gradient(args)


if __name__ == "__main__":
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
'xtp_gradient=PyVOTCA.xtp_gradient:main',
]
},

install_requires=["h5py", "matplotlib", "numpy", "scipy"],
install_requires=["h5py", "matplotlib", "numpy", "pyyaml", "schema", "scipy"],
extras_require={
'test': ['coverage', 'mypy', 'pycodestyle', 'pytest>=3.9',
'pytest-asyncio', 'pytest-cov', 'pytest-mock'],
Expand Down
2 changes: 2 additions & 0 deletions tests/files/example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
molecule: test/files/ethylene.xyz