Gravar-mail: A statistical mechanical method to optimize energy functions for protein folding