I suggest a (BIG) back emf diode, provided it's installed at the DC section. During normal operation, the diode is reverse biased and does nothing. When you open the magnet, the back emf will...