Switchable nanoparticle assemblies for photonic sensing