Source code for metafalcon.cvs.bond

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

"""Contains a class for using the bond length between two atoms as a CV."""

import numpy as np

from .. import constants as c
from . import cvfunctions as cvf
from .cv import cv

[docs]class cv_bond(cv): """ Bond length between two 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 two atom indices for the calculation of the bond length """ def __init__(self, idx, symbols, **kwargs): """Construct bond length CV object.""" cv.__init__(self, idx, symbols, **kwargs) self.atoms = self.get_kwargs("atoms") self.x = np.linspace(0.5, 2.5, 200) self.ticks = None self.au2unit = c.a0 self.reset_width()
[docs] def set_s_and_ds(self, coords): """ Calculate bond length 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] bond = cvf.bond(coord) dbond = np.zeros(coords.shape) dbond[self.atoms] = cvf.dbond(coord) self.s = bond self.ds_dr = dbond