Exemplo n.º 1
0
    def run(self) -> QMolecule:
        psi4d_directory = os.path.dirname(os.path.realpath(__file__))
        template_file = psi4d_directory + '/_template.txt'
        qiskit_chemistry_directory = os.path.abspath(
            os.path.join(psi4d_directory, '../..'))

        molecule = QMolecule()

        input_text = self._config + '\n'
        input_text += 'import sys\n'
        syspath = '[\'' + qiskit_chemistry_directory + '\',\'' + '\',\''.join(
            sys.path) + '\']'

        input_text += 'sys.path = ' + syspath + ' + sys.path\n'
        input_text += 'from qmolecule import QMolecule\n'
        input_text += '_q_molecule = QMolecule("{0}")\n'.format(
            molecule.filename)

        with open(template_file, 'r') as file:
            input_text += file.read()

        file_fd, input_file = tempfile.mkstemp(suffix='.inp')
        os.close(file_fd)
        with open(input_file, 'w') as stream:
            stream.write(input_text)

        file_fd, output_file = tempfile.mkstemp(suffix='.out')
        os.close(file_fd)
        try:
            PSI4Driver._run_psi4(input_file, output_file)
            if logger.isEnabledFor(logging.DEBUG):
                with open(output_file, 'r') as file:
                    logger.debug('PSI4 output file:\n%s', file.read())
        finally:
            run_directory = os.getcwd()
            for local_file in os.listdir(run_directory):
                if local_file.endswith('.clean'):
                    os.remove(run_directory + '/' + local_file)
            try:
                os.remove('timer.dat')
            except Exception:  # pylint: disable=broad-except
                pass

            try:
                os.remove(input_file)
            except Exception:  # pylint: disable=broad-except
                pass

            try:
                os.remove(output_file)
            except Exception:  # pylint: disable=broad-except
                pass

        _q_molecule = QMolecule(molecule.filename)
        _q_molecule.load()
        # remove internal file
        _q_molecule.remove_file()
        _q_molecule.origin_driver_name = 'PSI4'
        _q_molecule.origin_driver_config = self._config
        return _q_molecule
Exemplo n.º 2
0
    def run(self) -> QMolecule:
        hdf5_file = self._hdf5_input
        if self.work_path is not None and not os.path.isabs(hdf5_file):
            hdf5_file = os.path.abspath(os.path.join(self.work_path, hdf5_file))

        if not os.path.isfile(hdf5_file):
            raise LookupError('HDF5 file not found: {}'.format(hdf5_file))

        molecule = QMolecule(hdf5_file)
        molecule.load()
        return molecule
Exemplo n.º 3
0
 def load_molecule(filename):
     if os.path.exists(filename):
         print(f"Found {filename}. Loading...")
         molecule = QMolecule(filename)
         molecule.load()
     else:
         # Regenerate
         print(f"Couldn't find {filename}. Regenerating...")
         molecule = self.driver.run()
         molecule.save(filename)
     return molecule
Exemplo n.º 4
0
                     max_memory=1024 * 128,
                     basis='sto3g'
                     )
#driver = PySCFDriver(atom='H .0 .0 .0; H .0 .0 0.735',
#                     unit=UnitsType.ANGSTROM,
#                     basis='sto3g')
                     
#FILENAME = "hdf5_files/femoco_sto3g_(-1,3).hdf5"
#FILENAME = "hdf5_files/femoco_nosulfer_sto3g_(-1,3).hdf5"
FILENAME = "hdf5_files/lih_sto3g_(0,0).hdf5"
#FILENAME = "hdf5_files/hydrogen.hdf5"

if os.path.exists(FILENAME):
    print(f"Found {FILENAME}. Loading...")
    molecule = QMolecule(FILENAME)
    molecule.load()
else:
    # Regenerate
    print(f"Couldn't find {FILENAME}. Regenerating...")
    molecule = driver.run()
    molecule.save(FILENAME)

#print("Loading 1 body integrals...")
#one_body_integrals = molecule.one_body_integrals
##np.save("results/old/lih_1d.npy", one_body_integrals)
#np.save("results/new/lih_1d.npy", one_body_integrals)
#
#print("Loading 2 body integrals...")
#two_body_integrals = molecule.two_body_integrals
#np.save("results/new/lih_2d.npy", two_body_integrals)