1 """ @package forcebalance.abinitio_internal Internal implementation of energy matching (for TIP3P water only) 6 from __future__
import division
8 from builtins
import range
10 from forcebalance
import BaseReader
21 """Subclass of Target for force and energy matching 22 using an internal implementation. Implements the prepare and 23 energy_force_driver methods. The get method is in the superclass. 25 The purpose of this class is to provide an extremely simple test 26 case that does not require the user to install any external 27 software. It only runs with one of the included sample test 28 calculations (internal_tip3p), and the objective function is 31 @warning This class is only intended to work with a very specific 32 test case (internal_tip3p). This is because the topology and 33 ordering of the atoms is hard-coded (12 water molecules with 3 36 @warning This class does energy matching only (no forces) 40 def __init__(self,options,tgt_opts,forcefield):
47 super(AbInitio_Internal,self).
__init__(options,tgt_opts,forcefield)
50 """ Here we actually compute the interactions and return the 51 energies and forces. I verified this to give the same answer 56 ThisFF = FF({
'forcefield':[
'tip3p.xml'],
'ffdir':
'',
'priors':{}},verbose=
False)
57 r_0 = ThisFF.pvals0[ThisFF.map[
'HarmonicBondForce.Bond/length/OW.HW']] * 10
58 k_ij = ThisFF.pvals0[ThisFF.map[
'HarmonicBondForce.Bond/k/OW.HW']]
59 t_0 = ThisFF.pvals0[ThisFF.map[
'HarmonicAngleForce.Angle/angle/HW.OW.HW']] * 180 / np.pi
60 k_ijk = ThisFF.pvals0[ThisFF.map[
'HarmonicAngleForce.Angle/k/HW.OW.HW']]
61 q_o = ThisFF.pvals0[ThisFF.map[
'NonbondedForce.Atom/charge/tip3p-O']]
62 q_h = ThisFF.pvals0[ThisFF.map[
'NonbondedForce.Atom/charge/tip3p-H']]
63 sig = ThisFF.pvals0[ThisFF.map[
'NonbondedForce.Atom/sigma/tip3p-O']]
64 eps = ThisFF.pvals0[ThisFF.map[
'NonbondedForce.Atom/epsilon/tip3p-O']]
67 for I
in range(self.ns):
68 xyz = self.mol.xyzs[I]
73 for i
in range(0,len(xyz),3):
78 r_1 = xyz[h1] - xyz[o]
79 r_1n = np.linalg.norm(r_1)
80 Bond_Energy += 0.5 * k_ij * ((r_1n - r_0) / 10)**2
82 r_2 = xyz[h2] - xyz[o]
83 r_2n = np.linalg.norm(r_2)
84 Bond_Energy += 0.5 * k_ij * ((r_2n - r_0) / 10)**2
86 theta = np.arccos(np.dot(r_1, r_2) / (r_1n * r_2n)) * 180 / np.pi
87 Angle_Energy += 0.5 * k_ijk * ((theta - t_0) * np.pi / 180)**2
88 for j
in range(0, i, 3):
93 r_o_oo = np.linalg.norm(xyz[oo] - xyz[o]) / 10
95 VdW_Energy += 4*eps*(sroo**12 - sroo**6)
97 for k, l
in itertools.product(*[[i,i+1,i+2],[j,j+1,j+2]]):
98 q1 = q_o
if (k % 3 == 0)
else q_h
99 q2 = q_o
if (l % 3 == 0)
else q_h
100 Coulomb_Energy += q1*q2 / np.linalg.norm(xyz[k]-xyz[l])
101 Coulomb_Energy *= facel
102 Energy = Bond_Energy + Angle_Energy + VdW_Energy + Coulomb_Energy
103 Force = list(np.zeros(3*len(xyz)))
104 M.append(np.array([Energy] + Force))
def __init__(self, options, tgt_opts, forcefield)
coords
Name of the trajectory, we need this BEFORE initializing the SuperClass.
def energy_force_driver_all(self)
Here we actually compute the interactions and return the energies and forces.
Ab-initio fitting module (energies, forces, resp).
loop_over_snapshots
LPW 2018-02-11: This is set to True if the target calculates a single-point property over several exi...
Subclass of Target for force and energy matching using an internal implementation.