def get_pdb_transform(pdb, center_res, top_res): """ Returns a transformation matrix that centers pdb to center_res on the z-axis and moves top_res above center_res on the y-axis """ soup = pdbatoms.Soup(pdb) atoms = soup.atoms() soup_center = pdbatoms.get_center(atoms) translation = v3.translation(-soup_center) soup.transform(translation) result = translation center_atom = find_ca_of_resname(soup.atoms(), center_res) view = v3.vector(0, 0, 1) axis = v3.cross(view, center_atom.pos) angle = v3.vec_dihedral(view, axis, center_atom.pos) rotation = v3.rotation(axis, angle) soup.transform(rotation) result = v3.combine(rotation, result) top_atom = find_ca_of_resname(soup.atoms(), top_res) top_dir = v3.vector(0, 1, 0) axis = view.copy() angle = v3.vec_dihedral(top_dir, axis, top_atom.pos) rotation2 = v3.rotation(axis, angle) result = v3.combine(rotation2, result) del soup return result
def add_rotational_velocity(atoms, rot_vel, axis, anchor): """ Adds the rot_vel to the vel vector of atoms with respect to the rotation around axis and attached to anchor. """ for atom in atoms: r_perp = v3.perpendicular(atom.pos - anchor, axis) v_tang_dir = v3.cross(axis, r_perp) v_tang_dir_len = v3.mag(v_tang_dir) if v3.is_similar_mag(v_tang_dir_len, 0): v_tang = v3.vector() else: v_new_len = rot_vel * v3.mag(r_perp) v_tang = v3.scale(v_tang_dir, v_new_len / v_tang_dir_len) atom.vel += v_tang
def add_rotational_velocity(atoms, rot_vel, axis, anchor): """ Adds the rot_vel to the vel vector of atoms with respect to the rotation around axis and attached to anchor. """ for atom in atoms: r_perp = v3.perpendicular(atom.pos - anchor, axis) v_tang_dir = v3.cross(axis, r_perp) v_tang_dir_len = v3.mag(v_tang_dir) if v3.is_similar_mag(v_tang_dir_len, 0): v_tang = v3.vector() else: v_new_len = rot_vel * v3.mag(r_perp) v_tang = v3.scale(v_tang_dir, v_new_len/v_tang_dir_len) atom.vel += v_tang
def rotational_velocity(atom, axis, anchor): """ Returns the rotational velocity (rad/ps) of the atom connected to anchor around axis. """ r = atom.pos - anchor r_perp = v3.perpendicular(r, axis) vel_perp = v3.perpendicular(atom.vel, axis) vel_tang = v3.perpendicular(vel_perp, r_perp) pos_ref = v3.cross(axis, r_perp) if v3.dot(vel_tang, pos_ref) < 0.0: sign = -1.0 else: sign = 1.0 if v3.is_similar_mag(v3.mag(r_perp), 0): result = 0.0 else: result = sign * v3.mag(vel_tang) / v3.mag(r_perp) return result