Patterning through controlled submolecular motion: Rotaxane-based switches and logic gates that function in solution and polymer films