Skip to content

Commit

Permalink
fix GaussianForcesDriver.from_molecule improvements qiskit-community#400
Browse files Browse the repository at this point in the history
  • Loading branch information
cometta committed Oct 19, 2022
1 parent 015c009 commit 079a802
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def from_molecule(
molecule: Molecule,
basis: str = "sto-3g",
driver_kwargs: Optional[dict[str, Any]] = None,
xcf: str = "B3LYP"
) -> "GaussianForcesDriver":
"""
Args:
Expand All @@ -95,6 +96,7 @@ def from_molecule(
basis: The basis set to be used in the resultant job control file when a
molecule is provided.
driver_kwargs: kwargs to be passed to driver
xcf: example string value `B3LYP`
Returns:
driver
Raises:
Expand All @@ -110,7 +112,7 @@ def from_molecule(
units = "Bohr"
else:
raise QiskitNatureError(f"Unknown unit '{molecule.units.value}'")
cfg1 = f"#p B3LYP/{basis} UNITS={units} Freq=(Anharm) Int=Ultrafine SCF=VeryTight\n\n"
cfg1 = f"#p {xcf}/{basis} UNITS={units} Freq=(Anharm) Int=Ultrafine SCF=VeryTight\n\n"
name = "".join([name for (name, _) in molecule.geometry])
geom = "\n".join(
[name + " " + " ".join(map(str, coord)) for (name, coord) in molecule.geometry]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def from_molecule(
*,
basis: str = "sto-3g",
driver_kwargs: Optional[dict[str, Any]] = None,
xcf: str = "B3LYP"
) -> "GaussianForcesDriver":
"""
Args:
Expand All @@ -94,6 +95,7 @@ def from_molecule(
basis: The basis set to be used in the resultant job control file when a
molecule is provided.
driver_kwargs: kwargs to be passed to driver
xcf: example string value `B3LYP`
Returns:
driver
Raises:
Expand All @@ -109,7 +111,7 @@ def from_molecule(
units = "Bohr"
else:
raise QiskitNatureError(f"Unknown unit '{molecule.units.value}'")
cfg1 = f"#p B3LYP/{basis} UNITS={units} Freq=(Anharm) Int=Ultrafine SCF=VeryTight\n\n"
cfg1 = f"#p {xcf}/{basis} UNITS={units} Freq=(Anharm) Int=Ultrafine SCF=VeryTight\n\n"
name = "".join(molecule.symbols)
geom = "\n".join(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@ def test_driver_jcf(self):
)
result = driver.run()
self._check_driver_result(self._get_expected_values(), result)

@unittest.skipIf(not _optionals.HAS_GAUSSIAN, "gaussian not available.")
def test_driver_xcf(self):
"""Test the GaussianForcesDriver.from_molecule accept xcf argument"""
molecule = Molecule(
geometry=[
("C", [-0.848629, 2.067624, 0.160992]),
("O", [0.098816, 2.655801, -0.159738]),
("O", [-1.796073, 1.479446, 0.481721]),
],
multiplicity=1,
charge=0,
)

driver = GaussianForcesDriver.from_molecule( # type: ignore
molecule, "6-31g", {}, "B3LYP"
)
result = driver.run()
# test result has the value 'B3LYP'
self.assertIn("B3LYP", result._jcf)

@unittest.skipIf(not _optionals.HAS_GAUSSIAN, "gaussian not available.")
def test_driver_molecule(self):
Expand All @@ -150,6 +170,9 @@ def test_driver_molecule(self):
)
result = driver.run()
self._check_driver_result(self._get_expected_values(), result)




@data(
("A03", _A03_REV_EXPECTED),
Expand Down

0 comments on commit 079a802

Please sign in to comment.