Skip to content

Commit

Permalink
Add charge and multiplicity as options to ASE calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
awvwgk committed Feb 8, 2024
1 parent a32309a commit 75f0948
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions xtb/ase/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
Keyword Default Description
======================== ============ ============================================
method "GFN2-xTB" Underlying method for energy and forces
charge None Total charge of the system
multiplicity None Total multiplicity of the system
accuracy 1.0 Numerical accuracy of the calculation
electronic_temperature 300.0 Electronic temperatur for TB methods
max_iterations 250 Iterations for self-consistent evaluation
Expand Down Expand Up @@ -132,6 +134,22 @@ def set(self, **kwargs) -> dict:

return changed_parameters

@property
def _charge(self) -> int:
return (
self.atoms.get_initial_charges().sum()
if self.parameters.charge is None
else self.parameters.charge
)

@property
def _uhf(self) -> int:
return (
int(self.atoms.get_initial_magnetic_moments().sum().round())
if self.parameters.multiplicity is None
else self.parameters.multiplicity - 1
)

def _check_parameters(self, parameters: dict) -> None:
"""Verifiy provided parameters are valid"""

Expand Down Expand Up @@ -187,8 +205,8 @@ def _create_api_calculator(self) -> Calculator:
try:
_cell = self.atoms.cell
_periodic = self.atoms.pbc
_charge = self.atoms.get_initial_charges().sum()
_uhf = int(self.atoms.get_initial_magnetic_moments().sum().round())
_charge = self._charge
_uhf = self._uhf

calc = Calculator(
_method,
Expand Down

0 comments on commit 75f0948

Please sign in to comment.