Understanding the mechanism of peptide self-assembly