Thanks! I'd "traced" add_H to that function before but my knowledge of C is rudimentary so I was quite overwhelmed.
Yet, I think I managed to understand a bit better what's going on, but correct me if I'm wrong. It seems PyMol looks for neighbours first, derives a "bonding network" from that, and then calculates valences.
Thanks a lot for the help! And good luck with the new city!