Source code for metafalcon.cvs.torsion

# -*- coding: utf-8 -*-

"""Contains a class for using the torsion angle between four atoms as a CV."""

import numpy as np

from . import cvfunctions as cvf
from .cv import cv

[docs]class cv_torsion(cv): """ Torsion angle between four atoms as collective variable, inherits from `metafalcon.cvs.cv.cv`. Parameters ---------- idx : int index of collective variable in the input file symbols : list of str atomic symbols of the molecule **kwargs : See below Keyword Arguments ----------------- atoms : list of int list of four atom indices for the calculation of the torsion angle """ def __init__(self, idx, symbols, **kwargs): """Construct torsion angle CV object.""" cv.__init__(self, idx, symbols, **kwargs) self.atoms = self.get_kwargs("atoms") self.x = np.linspace(-180., 180., 200) self.ticks = 45. self.shift = [-360., 0., 360] self.periodic = True self.periodictype = "continue" self.periodicstart = -180. self.periodicend = 180.
[docs] def set_s_and_ds(self, coords): """ Calculate torsion angle and its gradient for the current set of coordinates. Parameters ---------- coords : np.2darray cartesian coordinates of the molecule (shape: (N, 3)) """ coord = [coords[i] for i in self.atoms] torsion = cvf.torsion(coord) dtorsion = np.zeros(coords.shape) dtorsion[self.atoms] = cvf.dtorsion(coord) self.s = torsion self.ds_dr = dtorsion