Skip to content

Commit

Permalink
Make the code an optional argument
Browse files Browse the repository at this point in the history
WardLT committed Dec 24, 2023
1 parent 35a23ac commit d897b4a
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions jitterbug/utils.py
Original file line number Diff line number Diff line change
@@ -11,38 +11,53 @@
"""List of methods for which we will use MOPAC"""


def make_calculator(method: str, basis: Optional[str], multiplicity: int = 1, **kwargs) -> Calculator:
def make_calculator(method: str, basis: Optional[str], multiplicity: int = 1,
code: Optional[str] = None, **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 xTB if the method is xTB.
2. Use Psi4 otherwise
1. Use the code named in the ``code`` argument
2. Use MOPAC if the method is PM7.
3. Use xTB if the method is xTB.
4. 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
multiplicity: Default multiplicity for the computation
code: Which code to use
Returns:
Calculator defined according to the user's settings
"""

if method in mopac_methods:
if not (basis is None or basis.lower() == "none"):
raise ValueError(f'Basis must be none for method: {method}')
# Determine which code to use
if code is None:
if method in mopac_methods:
if not (basis is None or basis.lower() == "none"):
raise ValueError(f'Basis must be none for method: {method}')
code = 'mopac'
elif method == 'xtb':
code = 'xtb'
else:
code = 'psi4'

# Make the appropriate calculator
if code == 'mopac':
return MOPAC(method=method, command='mopac PREFIX.mop > /dev/null')
elif method == 'xtb':
elif code == 'xtb':
from xtb.ase.calculator import XTB
return XTB()
else:
elif code == 'psi4':
return Psi4(method=method, basis=basis,
multiplicity=multiplicity,
reference='rhf' if multiplicity == 1 else 'uhf',
**kwargs)
else:
raise ValueError(f'Code not supported: {code}')


# Taken from ExaMol

0 comments on commit d897b4a

Please sign in to comment.