Free energy from constrained molecular dynamics