Light-directed trapping of metastable intermediates in a self-assembly process