Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 2 additions & 5 deletions MDMC/MD/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from pkgutil import iter_modules

from . import ase, engine_facades, force_fields, solvents
from .constraints import Rattle, Shake
from .interaction_functions import (
Buckingham,
Coulomb,
Expand All @@ -55,14 +56,10 @@
Interaction,
NonBondedInteraction,
)
from .kspace_solvers import PPPM, Ewald, KSpaceSolver
from .parameters import Parameter, Parameters
from .simulation import (
PPPM,
ConstraintAlgorithm,
Ewald,
KSpaceSolver,
Rattle,
Shake,
Simulation,
Universe,
)
Expand Down
108 changes: 108 additions & 0 deletions MDMC/MD/constraints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# MDMC is a package for the optimisation of classical potentials with experimental data
# Copyright (C) 2026 MDMC Developers
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Constraint solvers."""


class ConstraintAlgorithm:
"""
Class describing the algorithm and parameters which are applied to
constrain ``BondedInteraction`` objects

Parameters
----------
accuracy : float
The accuracy (tolerance) of the applied constraints
max_iterations : int
The maximum number of iterations that can be used when calculating the
additional force that is required to constrain the atoms to satisfy the
constraints on the bonded interactions

Attributes
----------
accuracy : float
The accuracy (tolerance) of the applied constraints
"""

def __init__(self, accuracy: float, max_iterations: int):

self.accuracy = accuracy
self.max_iterations = max_iterations

@property
def name(self) -> str:
"""
Get the name of the class

Returns
-------
str
The name of the class
"""

return self.__class__.__name__

@property
def max_iterations(self) -> int:
"""
Get or set the maximum number of iterations that can be used when
calculating the additional force that is required to constrain the atoms
to satisfy the constraints on the bonded interactions

Returns
-------
int
The maximum number of iterations
"""

return self._max_iterations

@max_iterations.setter
def max_iterations(self, value: int) -> None:

self._max_iterations = int(value)


class Shake(ConstraintAlgorithm):
"""
Holds the parameters which are required for the SHAKE algorithm to be
applied to the constrained interactions

Parameters
----------
accuracy : float
The accuracy (tolerance) of the applied constraints
max_iterations : int
The maximum number of iterations that can be used when calculating the
additional force that is required to constrain the atoms to satisfy the
constraints on the bonded interactions
"""


class Rattle(ConstraintAlgorithm):
"""
Holds the parameters which are required for the RATTLE algorithm to be
applied to the constrained interactions

Parameters
----------
accuracy : float
The accuracy (tolerance) of the applied constraints
max_iterations : int
The maximum number of iterations that can be used when calculating the
additional force that is required to constrain the atoms to satisfy the
constraints on the bonded interactions
"""
3 changes: 2 additions & 1 deletion MDMC/MD/engine_facades/lammps_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
Interaction,
NonBondedInteraction,
)
from MDMC.MD.simulation import ConstraintAlgorithm, KSpaceSolver, Universe
from MDMC.MD.kspace_solvers import KSpaceSolver
from MDMC.MD.simulation import ConstraintAlgorithm, Universe
from MDMC.MD.structures import Atom
from MDMC.trajectory_analysis.compact_trajectory import CompactTrajectory
from MDMC.utilities.partitioning import partition, partition_interactions
Expand Down
94 changes: 94 additions & 0 deletions MDMC/MD/kspace_solvers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# MDMC is a package for the optimisation of classical potentials with experimental data
# Copyright (C) 2026 MDMC Developers
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""k-Space models for long range forces."""


class KSpaceSolver:
"""
Class describing the k-space solver that is applied to electrostatic and/or
dispersion interactions

Different ``MDEngine`` require different parameters to be specified for a
k-space solver to be used. These parameters are specified in settings.

Parameters
----------
**settings
``accuracy`` (`float`)
The relative RMS error in per-atom forces

Attributes
----------
accuracy : float
The relative RMS error in per-atom forces
"""

def __init__(self, *, accuracy: float | None = None):

self.accuracy = accuracy

@property
def name(self):
"""
Get the name of the class

Returns
-------
str
The name of the class
"""

return self.__class__.__name__


class Ewald(KSpaceSolver):
"""
Holds the parameters that are required for the Ewald solver to be applied to
both/either the electrostatic and/or dispersion interactions

Parameters
----------
**settings
``accuracy`` (`float`)
The relative RMS error in per-atom forces
"""


class PPPM(KSpaceSolver):
"""
Holds the parameters that are required for the PPPM solver to be applied to
both/either the electrostatic and/or dispersion interactions

Parameters
----------
**settings
``accuracy`` (`float`)
The relative RMS error in per-atom forces
"""

def __eq__(self, other) -> bool:
"""
Two KSpaceSolvers are equal if their __dict__ are equal
"""

if not isinstance(other, self.__class__):
return False
return all(v == getattr(other, k) for k, v in self.__dict__.items())

def __ne__(self, other) -> bool:

return not self.__eq__(other)
Loading
Loading