Beispiel #1
0
def set_bonds(bonds, atoms, bond_graph):
    for bond in bonds:
        coords_1 = atoms[bond.at_1].coords
        coords_2 = atoms[bond.at_2].coords
        bond.set_rij(geometry.get_r_ij(coords_1, coords_2))
        bond_graph[bond.at_1][bond.at_2] = bond_graph[bond.at_2][
            bond.at_1] = bond.r_ij
Beispiel #2
0
def get_all_g_nonbonded(g_vdw, g_elst, atoms, nonints, dielectric, atom_tree,
                        cutoff):
    g_vdw.fill(0.0)
    g_elst.fill(0.0)
    vdw_cutoff = cutoff[0]
    elst_cutoff = cutoff[1]

    search_rad = max(6.8 * vdw_cutoff, elst_cutoff)
    dont_truncate = cutoff == (0.0, 0.0)
    pivot = -1

    for i, j in itertools.combinations(range(len(atoms)), 2):
        if (i, j) in nonints:
            continue

        at_1, at_2 = atoms[i], atoms[j]
        eps = at_1.at_sreps * at_2.at_sreps
        ro = at_1.at_ro + at_2.at_ro

        if dont_truncate:
            r_ij = geometry.get_r_ij(at_1.coords, at_2.coords)
            gdir_1, gdir_2 = get_g_dir_bond(at_1.coords, at_2.coords, r_ij)
            grad_elst_mag = get_g_mag_elst(r_ij, at_1.at_charge,
                                           at_2.at_charge, dielectric)
            g_elst[i] += grad_elst_mag * gdir_1
            g_elst[j] += grad_elst_mag * gdir_2
            grad_vdw_mag = get_g_mag_vdw(r_ij, eps, ro)
            g_vdw[i] += grad_vdw_mag * gdir_1
            g_vdw[j] += grad_vdw_mag * gdir_2
        else:
            if not i == pivot:
                pivot = i
                nn_pivot = atom_tree.query_radius(at_1.coords.reshape(1, -1),
                                                  r=search_rad,
                                                  return_distance=True)
                nn_idx = nn_pivot[0][0].tolist()
                nn_dist = nn_pivot[1][0]

            if j in nn_idx:
                r_ij = nn_dist[nn_idx.index(j)]
                gdir_1, gdir_2 = get_g_dir_bond(at_1.coords, at_2.coords, r_ij)

                if r_ij <= elst_cutoff:
                    grad_elst_mag = get_g_mag_elst(r_ij,
                                                   at_1.at_charge,
                                                   at_2.at_charge,
                                                   dielectric,
                                                   cutoff=elst_cutoff)
                    g_elst[i] += grad_elst_mag * gdir_1
                    g_elst[j] += grad_elst_mag * gdir_2

                if r_ij <= vdw_cutoff * ro:
                    grad_vdw_mag = get_g_mag_vdw(r_ij,
                                                 eps,
                                                 ro,
                                                 cutoff=vdw_cutoff)
                    g_vdw[i] += grad_vdw_mag * gdir_1
                    g_vdw[j] += grad_vdw_mag * gdir_2
Beispiel #3
0
def get_g_dir_angle(coords_1, coords_2, coords_3, r_21=None, r_23=None):
    if r_21 is None:
        r_21 = geometry.get_r_ij(coords_2, coords_1)
    if r_23 is None:
        r_23 = geometry.get_r_ij(coords_2, coords_3)

    u_21 = geometry.get_u_ij(coords_2, coords_1, r_21)
    u_23 = geometry.get_u_ij(coords_2, coords_3, r_23)
    ucp_2123 = np.cross(u_21, u_23)
    ucp_2123 /= np.linalg.norm(ucp_2123)

    gdir_1 = np.cross(u_21, ucp_2123)
    gdir_1 /= np.linalg.norm(gdir_1) * r_21
    gdir_3 = np.cross(ucp_2123, u_23)
    gdir_3 /= np.linalg.norm(gdir_3) * r_23
    gdir_2 = -1.0 * (gdir_1 + gdir_3)

    return gdir_1, gdir_2, gdir_3
Beispiel #4
0
def get_total_e_nonbonded(atoms, nonints, dielectric, atom_tree, cutoff):
    e_vdw, e_elst, e_neut = 0.0, 0.0, [0.0, 0.0]
    vdw_cutoff = cutoff[0]
    elst_cutoff = cutoff[1]

    search_rad = max(6.8 * vdw_cutoff, elst_cutoff)
    dont_truncate = cutoff == (0.0, 0.0)
    pivot = -1

    for i, j in itertools.combinations(range(len(atoms)), 2):
        if (i, j) in nonints:
            continue

        at_1, at_2 = atoms[i], atoms[j]
        eps = at_1.at_sreps * at_2.at_sreps
        ro = at_1.at_ro + at_2.at_ro

        if dont_truncate:
            r_ij = geometry.get_r_ij(at_1.coords, at_2.coords)
            e_elst += get_e_elst(r_ij, at_1.at_charge, at_2.at_charge,
                                 dielectric)
            e_vdw += get_e_vdw(r_ij, eps, ro)
        else:
            if not i == pivot:
                pivot = i
                nn_pivot = atom_tree.query_radius(at_1.coords.reshape(1, -1),
                                                  r=search_rad,
                                                  return_distance=True)
                nn_idx = nn_pivot[0][0].tolist()
                nn_dist = nn_pivot[1][0]

            if j in nn_idx:
                r_ij = nn_dist[nn_idx.index(j)]
                if r_ij <= elst_cutoff:
                    d_e_elst = get_e_elst(r_ij,
                                          at_1.at_charge,
                                          at_2.at_charge,
                                          dielectric,
                                          cutoff=elst_cutoff,
                                          return_neut=False)
                    e_elst += d_e_elst

                if r_ij <= vdw_cutoff * ro:
                    d_e_vdw = get_e_vdw(r_ij,
                                        eps,
                                        ro,
                                        cutoff=vdw_cutoff,
                                        return_neut=False)
                    e_vdw += d_e_vdw

    return e_vdw, e_elst, e_neut
Beispiel #5
0
def get_g_dir_outofplane(coords_1,
                         coords_2,
                         coords_3,
                         coords_4,
                         o_ijkl,
                         r_31=None,
                         r_32=None,
                         r_34=None):
    if r_31 is None:
        r_31 = geometry.get_r_ij(coords_3, coords_1)
    if r_32 is None:
        r_32 = geometry.get_r_ij(coords_3, coords_2)
    if r_34 is None:
        r_34 = geometry.get_r_ij(coords_3, coords_4)

    u_31 = geometry.get_u_ij(coords_3, coords_1, r_31)
    u_32 = geometry.get_u_ij(coords_3, coords_2, r_32)
    u_34 = geometry.get_u_ij(coords_3, coords_4, r_34)

    cp_3234 = np.cross(u_32, u_34)
    cp_3431 = np.cross(u_34, u_31)
    cp_3132 = np.cross(u_31, u_32)

    a_132 = geometry.get_a_ijk(coords_1, coords_3, coords_2, r_31, r_34)
    s_132 = np.sin(const.DEG2RAD * a_132)
    c_132 = np.cos(const.DEG2RAD * a_132)
    c_o_ijkl = np.cos(const.DEG2RAD * o_ijkl)
    t_o_ijkl = np.tan(const.DEG2RAD * o_ijkl)

    gdir_1 = ((1.0 / r_31) * (cp_3234 / (c_o_ijkl * s_132) -
                              (t_o_ijkl / s_132**2) * (u_31 - c_132 * u_32)))
    gdir_2 = ((1.0 / r_32) * (cp_3431 / (c_o_ijkl * s_132) -
                              (t_o_ijkl / s_132**2) * (u_32 - c_132 * u_31)))
    gdir_4 = ((1.0 / r_34) * (cp_3132 / (c_o_ijkl * s_132) -
                              (t_o_ijkl * u_34)))
    gdir_3 = -1.0 * (gdir_1 + gdir_2 + gdir_4)

    return gdir_1, gdir_2, gdir_3, gdir_4
Beispiel #6
0
def get_g_dir_torsion(coords_1,
                      coords_2,
                      coords_3,
                      coords_4,
                      r_12=None,
                      r_23=None,
                      r_34=None):
    if r_12 is None:
        r_12 = geometry.get_r_ij(coords_1, coords_2)
    if r_23 is None:
        r_23 = geometry.get_r_ij(coords_2, coords_3)
    if r_34 is None:
        r_34 = geometry.get_r_ij(coords_3, coords_4)

    u_21 = geometry.get_u_ij(coords_2, coords_1, r_12)
    u_34 = geometry.get_u_ij(coords_3, coords_4, r_34)
    u_23 = geometry.get_u_ij(coords_2, coords_3, r_23)
    u_32 = -1.0 * u_23

    a_123 = geometry.get_a_ijk(coords_1, coords_2, coords_3, r_12, r_23)
    a_432 = geometry.get_a_ijk(coords_4, coords_3, coords_2, r_34, r_23)

    s_123 = np.sin(const.DEG2RAD * a_123)
    s_432 = np.sin(const.DEG2RAD * a_432)
    c_123 = np.cos(const.DEG2RAD * a_123)
    c_432 = np.cos(const.DEG2RAD * a_432)

    gdir_1 = np.cross(u_21, u_23)
    gdir_1 /= np.linalg.norm(gdir_1) * r_12 * s_123
    gdir_4 = np.cross(u_34, u_32)
    gdir_4 /= np.linalg.norm(gdir_4) * r_34 * s_432
    gdir_2 = (r_12 * c_123 / r_23 - 1.0) * gdir_1 - (r_34 * c_432 /
                                                     r_23) * gdir_4
    gdir_3 = (r_34 * c_432 / r_23 - 1.0) * gdir_4 - (r_12 * c_123 /
                                                     r_23) * gdir_1

    return gdir_1, gdir_2, gdir_3, gdir_4
Beispiel #7
0
def get_bond_from_prm(record, atoms):
    at_1, at_2 = (i - 1 for i in map(int, record[1:3]))
    k_b, r_eq = tuple(map(float, record[3:5]))
    coords_1, coords_2 = (atoms[i].coords for i in (at_1, at_2))
    r_ij = geometry.get_r_ij(coords_1, coords_2)
    return molecule.Bond(at_1, at_2, r_ij, r_eq, k_b)