The code I’ve been working on has some cool features. If you give it a list of atoms and bonds, it automatically figures out bend and dihedral interactions using simple graph concepts. That is, if the molecule has a bond between atoms i and j and another bond between atoms j and k, you can easily deduce that there’s a bend interaction between i, j, and k. Similar three-bond ideas can be used to automatically determine dihedral interactions: Find bonds i-j, j-k, and k-l, then you can deduce the torsion for i-j-k-l.
For out-of-plane bends or improper torsions at the sp2 sites, there’s no simple graph theory way to determine an out-of-plane interaction. You actually need to know something about the chemical identity of the central atom. At least, I think this is the case. I’d love to be proven wrong, because keeping track of valences and bond counts is beyond the level of coding I wanted to include.