Source code for metafalcon.cvs.angle

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

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

import numpy as np

from . import cvfunctions as cvf
from .cv import cv

[docs]class cv_angle(cv): """ Angle between three 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 three atom indices for the calculation of the angle """ def __init__(self, idx, symbols, **kwargs): """Construct angle CV object.""" cv.__init__(self, idx, symbols, **kwargs) self.atoms = self.get_kwargs("atoms") self.x = np.linspace(0., 180., 200) self.ticks = 30.
[docs] def set_s_and_ds(self, coords): """ Calculate 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] angle = cvf.angle(coord) dangle = np.zeros(coords.shape) dangle[self.atoms] = cvf.dangle(coord) self.s = angle self.ds_dr = dangle