Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add charge and multiplicity as options to ASE calculator #107

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading