Skip to content

Commit

Permalink
Add force and stress calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
ElliottKasoar committed Feb 16, 2024
1 parent 4f8e418 commit a2bb272
Show file tree
Hide file tree
Showing 3 changed files with 583 additions and 4 deletions.
60 changes: 58 additions & 2 deletions janus_core/single_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pathlib

from ase.io import read
from numpy.typing import NDArray

from janus_core.mlip_calculators import choose_calculator

Expand Down Expand Up @@ -56,6 +57,61 @@ def get_calculator(self, **kwargs) -> None:
self.read_system()
self.sys.calc = calculator

def get_potential_energy(self) -> float:
"""Calculate potential energy using MLIP."""
def _get_potential_energy(self) -> float:
"""Calculate potential energy using MLIP.
Returns
-------
potential_energy : float
Potential energy of system.
"""
return self.sys.get_potential_energy()

def _get_forces(self) -> NDArray:
"""Calculate forces using MLIP.
Returns
-------
forces : float
Forces of system.
"""
return self.sys.get_forces()

def _get_stress(self) -> NDArray:
"""Calculate stress using MLIP.
Returns
-------
stress : float
Stress of system.
"""
return self.sys.get_stress()

def run_single_point(self, properties: str | list[str] | None = None) -> dict:
"""Run single point calculations.
Parameters
----------
properties : str | List[str] | None
Physical properties to calculate. If not specified, "energy",
"forces", and "stress" will be returned.
Returns
-------
results : dict
Dictionary of calculated results.
"""
results = {}
if properties is None:
properties = []
if isinstance(properties, str):
properties = [properties]

if "energy" in properties or len(properties) == 0:
results["energy"] = self._get_potential_energy()
if "forces" in properties or len(properties) == 0:
results["forces"] = self._get_forces()
if "stress" in properties or len(properties) == 0:
results["stress"] = self._get_stress()

return results
Loading

0 comments on commit a2bb272

Please sign in to comment.