Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip test and import if pyscf.semiempirical is not installed #170

Merged
merged 19 commits into from
Jun 28, 2022
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
7 changes: 5 additions & 2 deletions tangelo/algorithms/classical/semi_empirical_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
- MINDO3
"""

from pyscf.semiempirical import mindo3

from tangelo.helpers.utils import is_package_installed
from tangelo.algorithms.electronic_structure_solver import ElectronicStructureSolver


Expand All @@ -50,6 +49,9 @@ class MINDO3Solver(ElectronicStructureSolver):
"""

def __init__(self, molecule):
if not is_package_installed("pyscf.semiempirical"):
raise ModuleNotFoundError(f"The pyscf.semiempirical module is not available and is required by {self.__class__.__name__}.")

self.molecule = molecule

def simulate(self):
Expand All @@ -58,6 +60,7 @@ def simulate(self):
Returns:
float: RMINDO3 energy.
"""
from pyscf.semiempirical import mindo3

solver = mindo3.RMINDO3(self.molecule.to_pyscf()).run(verbose=0)
total_energy = solver.e_tot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@

import unittest

from tangelo.helpers.utils import is_package_installed
from tangelo.molecule_library import mol_pyridine
from tangelo.algorithms.classical.semi_empirical_solver import MINDO3Solver


class MINDO3SolverTest(unittest.TestCase):
class SemiEmpiricalSolverTest(unittest.TestCase):

def test_energy(self):
@unittest.skipIf(not is_package_installed("pyscf.semiempirical"), "Test Skipped: pyscf.semiempirical module not available \n")
def test_mindo3_energy(self):
"""Test MINDO3Solver with pyridine. Validated with:
- MINDO/3-derived geometries and energies of alkylpyridines and the
related N-methylpyridinium cations. Jeffrey I. Seeman,
John C. Schug, and Jimmy W. Viers
The Journal of Organic Chemistry 1983 48 (14), 2399-2407
DOI: 10.1021/jo00162a021.
"""
from tangelo.algorithms.classical import MINDO3Solver

solver = MINDO3Solver(mol_pyridine)
energy = solver.simulate()
Expand Down