A method is presented for obtaining the Hamiltonian and the proper canonical variables that is both very general and simple. A tree of capacitors is used to write the state equations for an LC circuit with independent sources, and transformations to canonical variables are generated from the circuit topology by considering an alternate tree (cotree) containing as many inductors (capacitors) as possible. A method is given to obtain these transformations by inspection, based on fundamental loops and cutsets of both the capacitor and alternate trees. When the nonlinearities in the capacitors and inductors are small, a change of coordinates is given to achieve complete separation of the canonical variables of the unperturbed (linear) system. These results should allow the application of techniques from Hamiltonian dynamics, such as canonical perturbation theory, to circuits.< <ETX xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">></ETX>