As someone who has been a pain patient for a decade and a half, and as someone who has been supplementing with magnesium off and on for even longer... If you're a pain patient you should definitely investigate this, and probably just supplement and see how it goes. I certainly feel better about my relationship with opioids when I'm consistent about my magnesium.
Magnesium will increase ATP. And ATP is the energy that is needed to sensitize G protein coupled receptors. One of those G protein coupled receptors is the opioid receptor.
So what magnesium is doing is making your opioid receptors more sensitive to your natural opioids.
I think severe withdrawals are associated with Magnesium deficiency. This research has been going on for decades as there isn't a dose response curve for how severe a narcotic withdrawal will be based on dosing alone.
I am sure magnesium is in no way universal cure. But interestingly cysteine is used to reduce ATP so you might have the same condition I have, which is instead of low ATP, high ATP.
High ATP could end up, creating a lot of oxidative stress in the mitochondria and end up inhibiting ATP as well. And the cystine can reduce oxidative stress inside the mitochondria to repair it.
Some people use magnesium citrate for GI motility and reduce calcium oxalate kidney stone formation. In higher doses, it's used as a pre-surgical laxative.