A theory for semiconductor nanostructure reactivity to gas environment