Skip to content

Commit

Permalink
fix get_universal_calculator AttributeError: 'SumCalculator' object h…
Browse files Browse the repository at this point in the history
…as no attribute 'lower'

from running
get_universal_calculator("mace", model="large", default_dtype="float64", dispersion=True)
  • Loading branch information
janosh committed Dec 12, 2023
1 parent f8e6edf commit 034791f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions matcalc/util.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""Some utility methods, e.g., for getting calculators from well-known sources."""

from __future__ import annotations

import functools
from typing import TYPE_CHECKING

from ase.calculators.calculator import Calculator
if TYPE_CHECKING:
from ase.calculators.calculator import Calculator

# Listing of supported universal calculators.
UNIVERSAL_CALCULATORS = (
Expand Down Expand Up @@ -34,7 +37,7 @@ def get_universal_calculator(name: str | Calculator, **kwargs) -> Calculator:
Returns:
Calculator
"""
if isinstance(name, Calculator):
if not isinstance(name, str): # e.g. already an ase Calculator instance
return name

if name.lower().startswith("m3gnet"):
Expand All @@ -44,7 +47,7 @@ def get_universal_calculator(name: str | Calculator, **kwargs) -> Calculator:
# M3GNet is shorthand for latest M3GNet based on DIRECT sampling.
name = {"m3gnet": "M3GNet-MP-2021.2.8-DIRECT-PES"}.get(name.lower(), name)
model = matgl.load_model(name)
kwargs.setdefault("stress_weight", 1.0 / 160.21766208)
kwargs.setdefault("stress_weight", 1 / 160.21766208)
return M3GNetCalculator(potential=model, **kwargs)

if name.lower() == "chgnet":
Expand Down

0 comments on commit 034791f

Please sign in to comment.