def __init__(self, system, term, other_terms, cart_penalty=1e-3 * angstrom): ''' A class deriving from the Yaff ForceField class to implement the strain of a molecular geometry associated with the term defined by term_index. **Arguments** system A Yaff System instance containing all system information. term a Term instance representing the term of the perturbation trajectory of the current strain other_terms a list of Term instances representing all other terms for ICs for which a strain contribution should be added **Keyword Arguments** cart_penalty Magnitude of an extra term added to the strain that penalises a deviation of the cartesian coordinates of each atom with respect to the equilibrium coordinates. This penalty is equal to norm(R-R_eq)**2/(2.0*3*Natoms*cart_penalty**2) and prevents global translations, global rotations as well as rotations of molecular fragments far from the IC under consideration. ''' self.coords0 = system.pos.copy() self.ndof = np.prod(self.coords0.shape) self.cart_penalty = cart_penalty self.cons_ic_atindexes = term.get_atoms() #construct main strain strain = ForcePartValence(system) for other in other_terms: if other.kind == 3: continue #no cross terms strain.add_term(Harmonic(1.0, None, other.ics[0])) #set the rest values to the equilibrium values strain.dlist.forward() strain.iclist.forward() for iterm in range(strain.vlist.nv): vterm = strain.vlist.vtab[iterm] ic = strain.iclist.ictab[vterm['ic0']] vterm['par1'] = ic['value'] ForceField.__init__(self, system, [strain]) #Abuse the Chebychev1 polynomial to simply get the value of q-1 and #implement the contraint constraint = ForcePartValence(system) constraint.add_term(Chebychev1(-2.0, term.ics[0])) self.constraint = ForceField(system, [constraint]) self.constrain_target = None self.constrain_value = None self.value = None
def satisfy(self, vterm, pars, part, system): if self.pars == pars: part_valence = ForcePartValence(system) part_valence.add_term(vterm) energy = part_valence.compute() ic_index = part_valence.vlist.vtab[0]['ic0'] ic = part_valence.vlist.iclist.ictab[ic_index]['value'] return np.abs(ic - self.rv) < self.eps else: return True
def get_hessian_contrib(self, index, fc=None): ''' Get the contribution to the covalent hessian of term with given index (and its slaves). If fc is given, set the fc of the master and its slave to the given fc. ''' val = ForcePartValence(self.system) kind = self.vlist.vtab[index]['kind'] masterslaves = [index] + self.terms[index].slaves if kind == 4: #Cosine m, k, rv = self.get_params(index) if fc is not None: k = fc for jterm in masterslaves: ics = self.terms[jterm].ics args = (m, k, rv) + tuple(ics) val.add_term(Cosine(*args)) elif kind == 3: #cross k, rv0, rv1 = self.get_params(index) if fc is not None: k = fc for jterm in masterslaves: ics = self.terms[jterm].ics args = (k, rv0, rv1) + tuple(ics) val.add_term(Cross(*args)) elif kind == 1: #Polyfour a0, a1, a2, a3 = list(self.get_params(index)) if fc is not None: a3 = 2.0 * fc a1 = -4.0 * fc * np.cos(a0)**2 for jterm in masterslaves: ics = self.terms[jterm].ics args = ([0.0, a1, 0.0, a3], ) + tuple(ics) val.add_term(PolyFour(*args)) elif kind == 0: #Harmonic: k, rv = self.get_params(index) if fc is not None: k = fc for jterm in masterslaves: ics = self.terms[jterm].ics args = (k, rv) + tuple(ics) val.add_term(Harmonic(*args)) else: raise ValueError('Term kind %i not supported' % kind) ff = ForceField(self.system, [val]) hcov = estimate_cart_hessian(ff) return hcov
def __init__(self, system, cons_ic, cons_ic_atindexes, ics, cart_penalty=1e-3 * angstrom): ''' A class deriving from the Yaff ForceField class to implement the strain of a molecular geometry associated with the term defined by term_index. **Arguments** system A Yaff System instance containing all system information. cons_ic An instance of Yaff Internal Coordinate representing the constrained term in the strain. cons_ic_atindexes A list of the atoms involved in the constrained IC. This is required for the implementation of the cartesian penalty. In principle this could be extracted from the information stored in cons_ic, but this is the lazy solution. ics A list of Yaff Internal Coordinate instances for which the strain needs to be minimized. cart_penalty Magnitude of an extra term added to the strain that penalises a deviation of the cartesian coordinates of each atom with respect to the equilibrium coordinates. This penalty is equal to norm(R-R_eq)**2/(2.0*3*Natoms*cart_penalty**2) and prevents global translations, global rotations as well as rotations of molecular fragments far from the IC under consideration. ''' self.coords0 = system.pos.copy() self.ndof = np.prod(self.coords0.shape) self.cart_penalty = cart_penalty self.cons_ic_atindexes = cons_ic_atindexes part = ForcePartValence(system) for ic in ics: part.add_term(Harmonic(1.0, None, ic)) #set the rest values to the equilibrium values part.dlist.forward() part.iclist.forward() for iterm in xrange(part.vlist.nv): term = part.vlist.vtab[iterm] ic = part.iclist.ictab[term['ic0']] term['par1'] = ic['value'] ForceField.__init__(self, system, [part]) #Abuse the Chebychev1 polynomial to simply get the value of q-1 and #implement the contraint part = ForcePartValence(system) part.add_term(Chebychev1(-2.0, cons_ic)) self.constraint = ForceField(system, [part]) self.constrain_target = None self.constrain_value = None self.value = None