There was an interesting video by ChubbyEmu where energy drinks fixed his B12 deficiency by accident that caused the insomnia: https://www.youtube.com/watch?v=d_qKA6KTvs8
Insomnia can of course manifest itself through many causes, but taking energy drinks would definitely help very few. B12 is something the body stores so your lifestyle and diet must be quite shit to have a deficiency.
Magnesium and B6 on the other hand you can become deficient very quickly.
In fact, ATP exists typically as MG-ATP in the body.
Severe Deficiency is rare (or rarely diagnosed i should say) because the body maintains serum magnesium levels at the expense of skeletal mg.