This letter proposes a structure-aware automatic differentiation method to accelerate the solution of alternating current optimal power flow (ACOPF) with nonlinear programming (NLP) solvers. By exploiting the isomorphic structure of nonlinear power flow constraints in ACOPF, specialized binary code is generated to efficiently compute the Jacobian and Hessian matrix. Numerical tests show that our implementation achieves over 18% speedup in the total solution process and 40% speedup in automatic differentiation for large-scale ACOPF problems compared to state-of-the-art algebraic modeling languages of NLP.