Nonlinear machine learning of macromolecular folding and self-assembly