Predicting the structure of a protein--the three dimensional pattern that a particular sequence of amino acids folds into to become biologically active--is a perennial challenge of biology.
Researchers have long recognized major drivers of the final shape, such as exposing hydrophilic amino acids to the aqueous environment, while keeping hydrophobic amino-acids tucked away safely inside or in regions that will lie inside of membranes. Chemists back to Linus Pauling have also recognized recurring structural motifs such as alpha helices and beta sheets that allow somewhat regular packing. But even with these constraints, a chain of hundreds of amino acids can arrange in an astronomical number of ways. Exploring these configurations one by one would take virtually forever, so how do real proteins find the few configurations that will let them do their biological job?
One answer is that they don't always succeed. Generally tens of percent of the molecules get mangled along the way and have to be disposed of. But this just reduces the astronomical challenge by a small factor.
Another important fact is that proteins don't fold in a vacuum--or even in a water environment. Even as it is being translated from messenger RNA by the ribosome, a growing polypeptide is joined by proteins called chaperones. These key proteins help to ensure that the new chain folds properly, and also keeps it from aggregating with others (which is another way to tuck away hydrophobic amino acids).
These molecular chaperones are the best-known members of the family of heat-shock proteins (denoted hsp), which are produced in large quantities by cells that have been stressed. Heat, for example, tends to disrupt protein folding, and the chaperones can help put them back together again. In addition to the small hsp70 chaperone that binds to the growing protein, another protein called hsp60 forms a kind of dressing room where the still-folding protein can assemble itself in privacy.
This activity of these chaperones is driven by ATP, the cell's energy currency. Here is a movie of both processes. I'm afraid it didn't help me much, though.
The important point is that protein folding in a cell, like the processing of DNA and RNA, involves the close coordination of other biological macromolecules. This may be part of the reason that, although researches have made a lot of progress in structure prediction from sequence, in part by draw analogies with similar sequences in proteins with known structure, they still struggle with completely novel sequences.
Folding is only one step in the processing of proteins. They also may be acetylated or phosphorylated, crosslinked with sulfur, and combined with metals like iron, zinc, or manganese. They will be decorated with sugars that can, for example, serve as address labels for their final destinations. Those proteins headed for membranes will not be sent out into the cell to fend for themselves, but will bound with membrane and directly handed off. Much of this activity happens in the endoplasmic reticulum, where proteins that have been mangled are identified and recycled.
Even after processing, many proteins will be further modified chemically, for example by adding or removing phosphate groups to modify their activity. Moreover, many proteins do their work as part of complexes with other proteins, either in pairs or other small groups or in larger complexes that may include RNA.
Biology (the reality, as well as the science) is a team sport.