Source code for metafalcon.cvs.custom

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

"""Contains a class for embedding own CV implementations."""

import numpy as np
import os
import sys

from .cv import cv

[docs]class cv_custom(cv): """ User-defined 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 ----------------- filename : str name of the python module for the evaluation of the CV and its gradient (default: cvcustom) parameters : dict configuration parameters handed over to the functions in `filename` """ def __init__(self, idx, symbols, **kwargs): """Construct user-defined CV object.""" cv.__init__(self, idx, symbols, **kwargs) self.prm = self.get_kwargs("parameters") self.x = np.linspace(0., 1.0, 200) self.ticks = None # import cvcustom.py or file with differently defined name self.filename = self.get_kwargs("filename", default="cvcustom") sys.path.insert(0, os.getcwd()) self.cvc = __import__(self.filename) self.au2unit = self.cvc.au2unit self.reset_width() if self.periodic and self.periodictype == "continue": self.shift = [self.periodicstart-self.periodicend, 0., self.periodicend-self.periodicstart]
[docs] def set_s_and_ds(self, coords): """ Calculate custom CV and its gradient for the current set of coordinates. Parameters ---------- coords : np.2darray cartesian coordinates of the molecule (shape: (N, 3)) """ custom = self.cvc.customcv(self.symbols, coords, self.prm) dcustom = self.cvc.dcustomcv(self.symbols, coords, self.prm) self.s = custom self.ds_dr = dcustom