-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid copying code between notebooks
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Utility functions""" | ||
from typing import Optional | ||
|
||
|
||
from ase.calculators.calculator import Calculator | ||
from ase.calculators.mopac import MOPAC | ||
from ase.calculators.psi4 import Psi4 | ||
|
||
mopac_methods = ['pm7'] | ||
"""List of methods for which we will use MOPAC""" | ||
|
||
|
||
def make_calculator(method: str, basis: Optional[str], **kwargs) -> Calculator: | ||
"""Make an ASE calculator that implements a desired method. | ||
This function will select the appropriate quantum chemistry code depending | ||
on the method name using the following rules: | ||
1. Use MOPAC if the method is PM7. | ||
2. Use Psi4 otherwise | ||
Any keyword arguments are passed to the calculator | ||
Args: | ||
method: Name of the quantum chemistry method | ||
basis: Basis set name, if appropriate | ||
Returns: | ||
Calculator defined according to the user's settings | ||
""" | ||
|
||
if method in mopac_methods: | ||
if basis is not None: | ||
raise ValueError(f'Basis must be none for method: {method}') | ||
return MOPAC(method=method, command='mopac PREFIX.mop > /dev/null') | ||
else: | ||
return Psi4(method=method, basis=basis, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from pytest import raises | ||
|
||
from jitterbug.utils import make_calculator | ||
|
||
|
||
def test_make_calculator(): | ||
assert make_calculator('b3lyp', 'def2_svpd').name == 'psi4' | ||
assert make_calculator('pm7', None).name == 'mopac' | ||
|
||
with raises(ValueError): | ||
make_calculator('pm7', 'wrong') |