Peptides in lipid bilayers: structural and thermodynamic basis for partitioning and folding