A counterfactual conditional using ~なら on the negative past 必要でなかった. Note the somewhat unusual placement of the subject: the sentence makes 必要 ('necessary') a statement about chemistry, with its subject omitted. 化学を取る ('to take a class') is the standard collocation for enrolling in a subject.