Skip to content

Commit 493c75b

Browse files
committed
Add charge and multiplicity as options to ASE calculator
1 parent a32309a commit 493c75b

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

xtb/ase/calculator.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
Keyword Default Description
4848
======================== ============ ============================================
4949
method "GFN2-xTB" Underlying method for energy and forces
50+
charge None Total charge of the system
51+
multiplicity None Total multiplicity of the system
5052
accuracy 1.0 Numerical accuracy of the calculation
5153
electronic_temperature 300.0 Electronic temperatur for TB methods
5254
max_iterations 250 Iterations for self-consistent evaluation
@@ -132,6 +134,22 @@ def set(self, **kwargs) -> dict:
132134

133135
return changed_parameters
134136

137+
@property.getter
138+
def _charge(self) -> int:
139+
return (
140+
self.atoms.get_initial_charges().sum()
141+
if self.parameters.charge is None
142+
else self.parameters.charge
143+
)
144+
145+
@property.getter
146+
def _uhf(self) -> int:
147+
return (
148+
int(self.atoms.get_initial_magnetic_moments().sum().round())
149+
if self.parameters.multiplicity is None
150+
else self.parameters.multiplicity - 1
151+
)
152+
135153
def _check_parameters(self, parameters: dict) -> None:
136154
"""Verifiy provided parameters are valid"""
137155

@@ -187,8 +205,8 @@ def _create_api_calculator(self) -> Calculator:
187205
try:
188206
_cell = self.atoms.cell
189207
_periodic = self.atoms.pbc
190-
_charge = self.atoms.get_initial_charges().sum()
191-
_uhf = int(self.atoms.get_initial_magnetic_moments().sum().round())
208+
_charge = self._charge
209+
_uhf = self._uhf
192210

193211
calc = Calculator(
194212
_method,

0 commit comments

Comments
 (0)