Recently, I encountered a similar problem. After going through the source code of "reroot_at_midpoint" in Dendropy 3.12.0, it will induce infinite looping
when the midpoint should be one of the existing internal node. The following is the code fragment:
while cur_node is not mrca_node:
if cur_node.edge.length > plen:
target_edge = cur_node.edge
head_node_edge_len = plen #cur_node.edge.length - plen
plen = 0
break
elif cur_node.edge.length < plen:
plen -= cur_node.edge.length
cur_node = cur_node.parent_node
else:
break_on_node = cur_node
#solution
break #when find the midpoint, it should break the loop
My solution is to override the original function just adding "break" after finding the midpoint is on one node. Waiting for other wiser solutions :)