Skip to content
Merged
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
10 changes: 6 additions & 4 deletions openfermionpyscf/_run_pyscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def run_pyscf(molecule,
run_cisd=False,
run_ccsd=False,
run_fci=False,
verbose=False):
"""
This function runs a pyscf calculation.
verbose=False,
save=True):
"""This function runs a pyscf calculation.

Args:
molecule: An instance of the MolecularData or PyscfMolecularData class.
Expand All @@ -115,6 +115,7 @@ def run_pyscf(molecule,
run_ccsd: Optional boolean to run CCSD calculation.
run_fci: Optional boolean to FCI calculation.
verbose: Boolean whether to print calculation results to screen.
save: Boolean whether to save the calculated molecular data to disk.

Returns:
molecule: The updated PyscfMolecularData object. Note the attributes
Expand Down Expand Up @@ -202,7 +203,8 @@ def run_pyscf(molecule,
# Return updated molecule instance.
pyscf_molecular_data = PyscfMolecularData.__new__(PyscfMolecularData)
pyscf_molecular_data.__dict__.update(molecule.__dict__)
pyscf_molecular_data.save()
if save:
pyscf_molecular_data.save()
return pyscf_molecular_data


Expand Down
21 changes: 21 additions & 0 deletions openfermionpyscf/tests/_run_pyscf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"""Tests many modules to call pyscf functions."""
from __future__ import absolute_import

import os

from openfermion.chem import MolecularData
from openfermionpyscf import run_pyscf
from openfermionpyscf import PyscfMolecularData
Expand All @@ -37,3 +39,22 @@ def test_run_pyscf():
run_fci=True,
verbose=1)
assert isinstance(new_mole, PyscfMolecularData)

Comment thread
mhucka marked this conversation as resolved.

def test_run_pyscf_without_save(tmp_path):
test_molecule = MolecularData(geometry,
basis,
multiplicity,
charge,
data_directory=str(tmp_path))

new_mole = run_pyscf(test_molecule,
run_scf=True,
save=False)
assert isinstance(new_mole, PyscfMolecularData)
assert not os.path.exists(f'{new_mole.filename}.hdf5')

new_mole_saved = run_pyscf(test_molecule,
run_scf=True)
assert isinstance(new_mole_saved, PyscfMolecularData)
assert os.path.exists(f'{new_mole_saved.filename}.hdf5')
Loading