A method for constrained energy minimization of macromolecules