-
Notifications
You must be signed in to change notification settings - Fork 22
Description
Is your feature request related to a problem? Please describe.
If e.g. a method or basis set, is given as a plain string, that is available as simple keyword in ORCA, it's not trivial to get the corresponding OPI representation.
Because e.g. for methods, these are grouped in separate enums Method, Dft, Sqm, ..., which is reasonable for humans, but if we want to automatize things it gets complicated.
Describe the solution you'd like
A routine or object that takes the plain string and returns the correct enum member, e.g. for r2SCAN-3c AnyMethod("r2scAN-3c") returns Dft.R2SCAN_3C.
Describe alternatives you've considered
The AbitraryString functionality could be used, but this would add the string directly to the input. It does allow access to the OPI enum member, which might be desired.
Additional context
Currently I use my own resolution mechanism:
def norm_keyword(keyword: str, /) -> str:
"""
Normalize the string containing a Simple Keyword by capitalizing it and replacing dashes with underscores.
"""
return keyword.upper().replace("-", "_")
def get_from_namespace(
keyword: str, namespaces: object | Sequence[object], /, *, default: Any = None
) -> Any:
"""
Look for a Simple Keyword in one of OPI's enums.
"""
if not isinstance(namespaces, (list, tuple)):
namespaces = [namespaces]
for nsp in namespaces:
if (attr := getattr(nsp, keyword, None)) is not None:
return attr
namespaces_str = ", ".join(str(x) for x in namespaces)
raise ValueError(f"Object '{keyword}' not found in namespaces: {namespaces_str}")
def resolve_method(method: str, /) -> str:
"""
Convert a string containing a QM method into its OPI representation.
"""
method = norm_keyword(method)
return get_from_namespace(method, (Method, Dft, Sqm, ForceField))