there's no formula
you gotta use your ears
all variables will make difference (string height from fretboard, gauge and brand, body resonance and timbre, bridge type)
I like some pickups in some guitars very close, others with some distance
the alnico nailbomb and the miracle man I had sounded best in a "medium" height, no too close, unlike the black dog or holy diver, for example, but not too far from strings neither
but "best" is also subjective
I usually try adjusting pickup height by palm muting under higher gain and setting it as close as I can to get maximum chunk without getting compressed (which happens when it's too close)
when the bass start farting out, I lower it back a bit
open chords through gain and cleaning up by picking softly are good tests too
higher output pickups like the c-bomb might mush the mids a bit on chords if you set them too close and they are harder to clean up