forked from qiskit-community/qiskit-aqua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgaussian_log_driver.py
88 lines (68 loc) · 3.03 KB
/
gaussian_log_driver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
""" Gaussian Log Driver """
from typing import Union, List
import logging
from ..base_driver import BaseDriver
from ...qiskit_chemistry_error import QiskitChemistryError
from .gaussian_utils import check_valid, run_g16
from .gaussian_log_result import GaussianLogResult
logger = logging.getLogger(__name__)
class GaussianLogDriver(BaseDriver):
""" Gaussian™ 16 log driver.
Qiskit chemistry driver using the Gaussian™ 16 program that provides the log
back, via :class:`GaussianLogResult`, for access to the log and data recorded there.
See http://gaussian.com/gaussian16/
This driver does not use Gaussian 16 interfacing code, as certain data such as forces
properties are not present in the MatrixElement file. The log is returned as a
:class:`GaussianLogResult` allowing it to be parsed for whatever data may be of interest.
This result class also contains ready access to certain data within the log.
"""
def __init__(self, jcf: Union[str, List[str]]) -> None:
r"""
Args:
jcf: A job control file conforming to Gaussian™ 16 format. This can
be provided as a single string with '\\n' line separators or as a list of
strings.
Raises:
QiskitChemistryError: Invalid Input
"""
GaussianLogDriver._check_valid()
if not isinstance(jcf, list) and not isinstance(jcf, str):
raise QiskitChemistryError("Invalid input for Gaussian Log Driver '{}'"
.format(jcf))
if isinstance(jcf, list):
jcf = '\n'.join(jcf)
self._jcf = jcf
super().__init__()
@staticmethod
def _check_valid():
check_valid()
def run(self) -> GaussianLogResult:
""" Runs the driver to produce a result given the supplied job control file.
Returns:
A log file result.
Raises:
QiskitChemistryError: Missing output log
"""
# The job control file, needs to end with a blank line to be valid for
# Gaussian to process it. We simply add the blank line here if not.
cfg = self._jcf
while not cfg.endswith('\n\n'):
cfg += '\n'
logger.debug("User supplied job control file raw: '%s'",
cfg.replace('\r', '\\r').replace('\n', '\\n'))
logger.debug('User supplied job control file\n%s', cfg)
all_text = run_g16(cfg)
if not all_text:
raise QiskitChemistryError("Failed to capture log from stdout")
return GaussianLogResult(all_text)