I should stop feeling guilty.
Only a few of the lines of code in that script were untested.
I got a chance to test the remaining untested lines in this script.
This script works.
You can use this "gen_all_angles_topo.sh" script to automatically
generate angles and dihedrals in a data file, and you can invoke it
periodically in your lammps scripts in conjunction with fix
bond/create and/or fix bond/break.
Running an external script will slow, but it should work. You just
have to be willing to tolerate a delay between when the bond is
created or breaks, and when the angular forces are switched on/off.
And there is currently no other way of doing this.
I hope this helps