closest quaternion with a given axis

For each face of the mesh I’m calculating the quaternion representing the tangent space derived from UV coordinates.

Then I’m calculating mean quaternion of the faces that share a vertex. This is another big problem, but not major to this topic. For now it’s just an arithmetic mean (sum divided by number).

Now I have a normal specified by graphics artist that must represent the axis for the resulting tangent space of the vertex.

The problem is: how to calculate the angle for this quaternion to have it as close to the target quaternion (calculated from faces) as possible?