def get_gdir_angle(coords1, coords2, coords3, r_21=None, r_23=None): """Calculate direction of energy gradients between bond angle atoms. Args: coords1 (float*): 3 cartesian coordinates [Angstrom] of atom1. coords2 (float*): 3 cartesian coordinates [Angstrom] of atom2. coords3 (float*): 3 cartesian coordinates [Angstrom] of atom3. r_21 (float): Distance between atom2 and atom1 (default None). r_23 (float): Distance between atom2 and atom3 (default None). Returns: gdir1 (float*), gdir2 (float*), gdir3 (float*): vectors in the direction of max increasing bond angle. """ if (not r_21): r_21 = geomcalc.get_r_ij(coords2, coords1) if (not r_23): r_23 = geomcalc.get_r_ij(coords2, coords3) u_21 = geomcalc.get_u_ij(coords2, coords1, r_21) u_23 = geomcalc.get_u_ij(coords2, coords3, r_23) cp = geomcalc.get_ucp(u_21, u_23) gdir1 = geomcalc.get_ucp(u_21, cp) / r_21 gdir3 = geomcalc.get_ucp(cp, u_23) / r_23 gdir2 = -1.0 * (gdir1 + gdir3) return gdir1, gdir2, gdir3
def get_gdir_outofplane(coords1, coords2, coords3, coords4, oop, r_31=None, r_32=None, r_34=None): """Calculate direction of energy gradients between outofplane atoms. Args: coords1 (float*): 3 cartesian coordinates [Angstrom] of atom1. coords2 (float*): 3 cartesian coordinates [Angstrom] of atom2. coords3 (float*): 3 cartesian coordinates [Angstrom] of atom3. coords4 (float*): 3 cartesian coordinates [Angstrom] of atom4. oop (float): Out-of-plane angles bewteen atoms 1, 2, 3, and 4. r_31 (float): Distance between atom3 and atom1 (default None). r_32 (float): Distance between atom3 and atom2 (default None). r_34 (float): Distance between atom3 and atom4 (default None). Returns: gdir1 (float*), gdir2 (float*), gdir3 (float*), gdir4 (float*): vectors in the direction of max increasing outofplane angle. """ if (not r_31): r_31 = geomcalc.get_r_ij(coords3, coords1) if (not r_32): r_32 = geomcalc.get_r_ij(coords3, coords2) if (not r_34): r_34 = geomcalc.get_r_ij(coords3, coords4) u_31 = geomcalc.get_u_ij(coords3, coords1, r_31) u_32 = geomcalc.get_u_ij(coords3, coords2, r_32) u_34 = geomcalc.get_u_ij(coords3, coords4, r_34) cp_3234 = geomcalc.get_cp(u_32, u_34) cp_3431 = geomcalc.get_cp(u_34, u_31) cp_3132 = geomcalc.get_cp(u_31, u_32) a_132 = geomcalc.get_a_ijk(coords1, coords3, coords2) s_132 = math.sin(geomcalc.deg2rad() * a_132) c_132 = math.cos(geomcalc.deg2rad() * a_132) c_oop = math.cos(geomcalc.deg2rad() * oop) t_oop = math.tan(geomcalc.deg2rad() * oop) gdir1 = ((1.0 / r_31) * (cp_3234 / (c_oop * s_132) - (t_oop / s_132**2) * (u_31 - c_132 * u_32))) gdir2 = ((1.0 / r_32) * (cp_3431 / (c_oop * s_132) - (t_oop / s_132**2) * (u_32 - c_132 * u_31))) gdir4 = ((1.0 / r_34) * (cp_3132 / (c_oop * s_132) - (t_oop * u_34))) gdir3 = -1.0 * (gdir1 + gdir2 + gdir4) return gdir1, gdir2, gdir3, gdir4
def get_g_nonbonded(mol): """Calculate vdw and elst energy gradients for all nonbonded atom pairs. Args: mol (mmlib.molecule.Molecule): Molecule object with associated Atom objects with geometry and parameter data. """ mol.g_nonbonded.fill(0.0) mol.g_vdw.fill(0.0) mol.g_elst.fill(0.0) for i in range(mol.n_atoms): at1 = mol.atoms[i] for j in range(i + 1, mol.n_atoms): if (not j in mol.nonints[i]): at2 = mol.atoms[j] r_ij = geomcalc.get_r_ij(at1.coords, at2.coords) dir1, dir2 = get_gdir_inter(at1.coords, at2.coords, r_ij) eps_ij = at1.sreps * at2.sreps ro_ij = at1.ro + at2.ro g_elst = get_g_elst_ij(r_ij, at1.charge, at2.charge, mol.dielectric) g_vdw = get_g_vdw_ij(r_ij, eps_ij, ro_ij) mol.g_vdw[i] += g_vdw * dir1 mol.g_vdw[j] += g_vdw * dir2 mol.g_elst[i] += g_elst * dir1 mol.g_elst[j] += g_elst * dir2
def get_g_bound_i(k_box, bound, coord, origin, boundtype): """Calculate energy gradient magnitude of boundary energy. Args: k_box (float): Spring constant [kcal/(mol*A^2)] of boundary. bound (float): Distance from origin [Angstrom] of boundary. coords (float*): Array of cartesian coordinates [Angstrom] of atom. origin (float*): Array of cartesian coordiantes [Angstrom] of origin of simulation. boundtype (str): `cube` or `sphere`, type of boundary condition. Returns: g_bound_i (float): Magnitude of energy gradient [kcal/(mol*A)]. """ g_bound_i = numpy.zeros(3) if (boundtype == 'cube'): for j in range(3): sign = 1.0 if ((coord[j] - origin[j]) <= 0.0) else -1.0 scale = 1.0 if (abs(coord[j] - origin[j]) >= bound) else 0.0 g_bound_i[j] = (-2.0 * sign * scale * k_box * (abs(coord[j]) - bound)) elif (boundtype == 'sphere'): r_io = geomcalc.get_r_ij(origin, coord) u_io = geomcalc.get_u_ij(origin, coord) scale = 1.0 if (r_io >= bound) else 0.0 g_bound_i = 2.0 * scale * k_box * (r_io - bound) * u_io return g_bound_i
def get_gdir_torsion(coords1, coords2, coords3, coords4, r_12=None, r_23=None, r_34=None): """Calculate direction of energy gradients between torsion atoms. Args: coords1 (float*): 3 cartesian coordinates [Angstrom] of atom1. coords2 (float*): 3 cartesian coordinates [Angstrom] of atom2. coords3 (float*): 3 cartesian coordinates [Angstrom] of atom3. coords4 (float*): 3 cartesian coordinates [Angstrom] of atom4. r_12 (float): Distance between atom1 and atom2 (default None). r_23 (float): Distance between atom2 and atom3 (default None). r_34 (float): Distance between atom3 and atom4 (default None). Returns: gdir1 (float*), gdir2 (float*), gdir3 (float*), gdir4 (float*): vectors in the direction of max increasing torsion angle. """ if (not r_12): r_12 = geomcalc.get_r_ij(coords1, coords2) if (not r_23): r_23 = geomcalc.get_r_ij(coords2, coords3) if (not r_34): r_34 = geomcalc.get_r_ij(coords3, coords4) u_21 = geomcalc.get_u_ij(coords2, coords1, r_12) u_34 = geomcalc.get_u_ij(coords3, coords4, r_34) u_23 = geomcalc.get_u_ij(coords2, coords3, r_23) u_32 = -1.0 * u_23 a_123 = geomcalc.get_a_ijk(coords1, coords2, coords3, r_12, r_23) a_432 = geomcalc.get_a_ijk(coords4, coords3, coords2, r_34, r_23) s_123 = math.sin(geomcalc.deg2rad() * a_123) s_432 = math.sin(geomcalc.deg2rad() * a_432) c_123 = math.cos(geomcalc.deg2rad() * a_123) c_432 = math.cos(geomcalc.deg2rad() * a_432) gdir1 = geomcalc.get_ucp(u_21, u_23) / (r_12 * s_123) gdir4 = geomcalc.get_ucp(u_34, u_32) / (r_34 * s_432) gdir2 = (r_12 / r_23 * c_123 - 1.0) * gdir1 - (r_34 / r_23 * c_432) * gdir4 gdir3 = (r_34 / r_23 * c_432 - 1.0) * gdir4 - (r_12 / r_23 * c_123) * gdir1 return gdir1, gdir2, gdir3, gdir4
def update_bonds(mol): """Update all bond lengths [Angstrom] within a molecule object. Args: mol (mmlib.molecule.Molecule): Molecule object with bond data. """ for p in range(mol.n_bonds): b = mol.bonds[p] c1 = mol.atoms[b.at1].coords c2 = mol.atoms[b.at2].coords b.r_ij = geomcalc.get_r_ij(c1, c2) mol.bond_graph[b.at1][b.at2] = b.r_ij mol.bond_graph[b.at2][b.at1] = b.r_ij
def get_bond(mol, record): """Parse bond record into a bond object and append to molecule. Appends mmlib.molecule.Bond object to mmlib.molecule.Molecule object. Contents of bond object include (int) 2 atomic indices, (float) spring constant [kcal/(mol*A^2)], (float) equilibrium bond length [Angstrom], (float) bond length [Angstrom]. Args: mol (mmlib.molecule.Molecule): Molecule to append bond. record (str*): Array of strings from line of prm file. """ at1, at2 = int(record[1])-1, int(record[2])-1 k_b, r_eq = float(record[3]), float(record[4]) c1, c2 = mol.atoms[at1].coords, mol.atoms[at2].coords r_ij = geomcalc.get_r_ij(c1, c2) bond = molecule.Bond(at1, at2, r_ij, r_eq, k_b) mol.bonds.append(bond) mol.bond_graph[at1][at2] = r_ij mol.bond_graph[at2][at1] = r_ij