Code that computes the origin that centers the volume is available here.
However, volume centering should never be used for anything else than troubleshooting! Need for centering is typically a sign of an error in the data processing workflow.
Can you explain why you need to center the volume?