Load gaussian binary dependencies first if not using discovery
@@ -24,7 +24,7 @@ import numpy as np
from qiskit_chemistry import QMolecule
from qiskit_chemistry import QiskitChemistryError
-from qiskit_chemistry.drivers import BaseDriver
+from qiskit_chemistry.drivers import BaseDriver, get_driver_class
logger = logging.getLogger(__name__)
@@ -33,14 +33,6 @@ GAUSSIAN_16_DESC = 'Gaussian 16'
g16prog = which(GAUSSIAN_16)
-try:
- from .gauopen.QCMatEl import MatEl
-except ImportError as mnfe:
- if mnfe.name == 'qcmatrixio':
- logger.info('qcmatrixio extension not found. See Gaussian driver readme to build qcmatrixio.F using f2py')
- else:
- logger.info(str(mnfe))
-
class GaussianDriver(BaseDriver):
"""Python implementation of a Gaussian 16 driver.
@@ -177,6 +169,18 @@ class GaussianDriver(BaseDriver):
return cfgaug
def _parse_matrix_file(self, fname, useAO2E=False):
+ # get_driver_class is used here because the discovery routine will load all the gaussian
+ # binary dependencies, if not loaded already. It won't work without it.
+ try:
+ get_driver_class('GAUSSIAN')
+ from .gauopen.QCMatEl import MatEl
+ except ImportError as mnfe:
+ msg = 'qcmatrixio extension not found. See Gaussian driver readme to build qcmatrixio.F using f2py' \
+ if mnfe.name == 'qcmatrixio' else str(mnfe)
+
+ logger.info(msg)
+ raise QiskitChemistryError(msg)
+
mel = MatEl(file=fname)
logger.debug('MatrixElement file:\n{}'.format(mel))
