An algorithm to construct lattice models of polymers with side chains is presented. A search for the global minimum of the error function for a given lattice-to-chain orientation is done by dynamic programming, making the search both fast and complete. Application of the algorithm is illustrated by constructing lattice models for 12 proteins of different sizes and structural types.