def moment_of_inertia(atom, axis, anchor): """ Returns the moment (DaAng^^2) of atom around axis at anchor. """ r = atom.pos - anchor r_perp = v3.perpendicular(r, axis) r_len = v3.mag(r_perp) return atom.mass * r_len * r_len
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
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