An O(n) Framework for Internal Coordinate Molecular Dynamics Applicable to Molecules with Arbitrary Constraints and Geometries