If you want to preserve the original transform so that Blender's bones recreate the same transform, you will also need to calculate the bone roll.
Blender has a function to calculate the bone head, tail and roll from a transform matrix in C code. I haven't found a convenient way to access this functionality from the Python API, but fortunately the functions are short and can easily be translated into Python.
Below is a direct translation of the functions you need, for Blender 2.62 or later:
def vec_roll_to_mat3(vec, roll):
target = Vector((0,1,0))
nor = vec.normalized()
axis = target.cross(nor)
if axis.dot(axis) > 0.000001:
axis.normalize()
theta = target.angle(nor)
bMatrix = Matrix.Rotation(theta, 3, axis)
else:
updown = 1 if target.dot(nor) > 0 else -1
bMatrix = Matrix.Scale(updown, 3)
rMatrix = Matrix.Rotation(roll, 3, nor)
mat = rMatrix * bMatrix
return mat
def mat3_to_vec_roll(mat):
vec = mat.col[1]
vecmat = vec_roll_to_mat3(mat.col[1], 0)
vecmatinv = vecmat.inverted()
rollmat = vecmatinv * mat
roll = math.atan2(rollmat[0][2], rollmat[2][2])
return vec, roll
pos = transform.to_translation()
axis, roll = mat3_to_vec_roll(transform.to_3x3())
bone.head = pos
bone.tail = pos + axis
bone.roll = roll