Teaching a neural network to attach and detach electrons from molecules