Little bmesh helper script.
The process to move the origin involves making the new point the origin by subtracting it from all other verts, effectively making the point origin (0, 0, 0),
Finally translate the matrix world of the object, in the opposite direction, such that the global location of vertices stays the same, ie move the object by the difference in global coordinate of the point to the former origin.
mw.translation += mw @ pt - mw @ Vector()
or since mw @ Vector() == mw.translation
can set the translation to
mw.translation = mw @ pt
Run in edit mode. Moves origin to selected geo.
import bpy
import bmesh
from mathutils import Vector
context = bpy.context
ob = context.edit_object
mw = ob.matrix_world
me = ob.data
bm = bmesh.from_edit_mesh(me)
selverts = [v.co for v in bm.verts if v.select]
if len(selverts):
pt = sum(selverts, Vector()) / len(selverts)
#T = Matrix.Translation(-pt)
bmesh.ops.translate(bm, vec=-pt, verts=bm.verts)
mw.translation = mw @ pt # replace @ with * for 2.7x
bmesh.update_edit_mesh(me)
As an addon for 2.80