Energy and helicity of magnetic torus knots and braids