CDTK.Dynamics.Constraints module

class CDTK.Dynamics.Constraints.Constraints(f_constraint)[source]

Bases: object

check_constraints(x1)[source]
enforceConstraints(x1, m, tol=1e-06, nsteps=100)[source]
Enforces constraints by making Newton steps for the coordinates

Keeps the center of mass of the molecule the same TODO: address the velocities TODO: prevent Rotation

Parameters:
  • x1 (numpy array shape (natoms,3)) – coordinates

  • m (numpy array shape (natoms)) – atom masses

  • tol (float, optional) – tolerance. Defaults to 1e-6.

  • nsteps (int, optional) – maximum number of steps. Defaults to 100.

Returns:

(numpy array shape (natoms,3)): new coordinates

Return type:

x1

get_correction_r(r0, r1, dt, m, tolerance=1e-05)[source]

Calculates the correction to the position according to the RATTLE algorithm to a geometry with constraints.

todo: Put reference to Andersen todo: Molecular simulations of fluids: Theory, Algorithms, Object-orientation

Parameters:
  • r0 ((natoms, 3) ndarray of float) – Positions of atoms at t, r(t).

  • r1 ((natoms, 3) ndarray of float) – Positions of atoms at t+dt, r(t+dt).

  • dt (float) – Timestep

  • m ((natoms)) – Array with atomic masses

  • tolerance (float, optional) – Tolearance of the constrain function for the iterative procedure, by default 1e-5

Returns:

correction

Return type:

(natom, 3) ndarray of float

get_correction_v(r1, v1, dt, m)[source]

Calculates the correction to the velocity according to the RATTLE algorithm to a geometry with constraints. This variant takes advantage of r”

rac{dsigma(X(t))}{dt} = 0” and r” rac{dsigma}{dX} cdot rac{dX}{dt} = 0”.

Some information can be found in [Ref] Andersen JOURNAL OF COMPUTATIONAL PHYSICS 52, 24-34

Arguments:

r1 ((natoms, 3) ndarray of float): Positions of atoms at t+dt with constraints applied, r(t+dt). v1 ((natoms, 3) ndarray of float): Velocity of atoms at t+dt without constraints, r(t+dt). dt (float): Timestep m ((natoms) ndarray of float): Array with atomic masses

Returns:

((natom, 3) - ndarray of float): correction

get_dg0dg1_matrix(r1, dgdt0overM, lambda_r)[source]

Calculates the matrix resulting from multipying the constraints Jacobian calculated at r(t) times the Jacobian calculated at r_c(t+dt)

r1(natoms, 3) ndarray of float

Positions of atoms at t+dt, r(t+dt).

dgdt0overM(nconstraints, natoms, 3) ndarray of float

Derivative of the constraints at r(t) times dt over the mass of each atom.

lambda_r(nconstraints) nndarray of float

Lagrange multiplier for the constrins of the position (lambda_R) for each constraint.

g: (nconstraints) ndarray of float

Constraints calculated at the new positions r_c(t+dt) after applying constraints.

dg0dg1_mat: (nconstraints, nconstraints) ndarray of float.

Derivative of the constrains at r(t) [

abla g(r(t))] times the derivative of the constraints at r_c(t+dt).