Derivation and implementation of equations of motion for isothermal and isobaric Molecular Dynamics simulations