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 anderson_velocity_scale(atoms, temperature, n_degree_of_freedom): """ Scales the velocity of atoms such that average energy is consistent with the temperature. """ # This is the classic Anderson approach to temperature # regulation. Whilst deterministic, can be easily trapped in # local minima. target_energy = mean_energy(temperature, n_degree_of_freedom) kin = kinetic_energy(atoms) if v3.is_similar_mag(kin, 0): gas_randomize(atoms, temperature) else: scaling_factor = math.sqrt(target_energy / kin) for atom in atoms: v3.set_vector(atom.vel, v3.scale(atom.vel, scaling_factor))
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