Unified formulation for control and inversion of molecular dynamics