The critical first step in CRISPR-Cas mediated gene editing is recognizing a preferred protospacer adjacent motif (PAM) on target DNAs by the protein's PAM-interacting amino acids (PIAAs). Thus, accurate computational modeling of PAM recognition is useful in assisting CRISPR-Cas engineering to relax or tighten PAM requirement for subsequence applications. Here we describe a universal computational protein design framework (UniDesign) for designing protein-nucleic acid interactions. As a proof of concept, we applied UniDesign to decode the PAM-PIAA interactions for eight Cas9 proteins. We show that, given native PIAAs, the UniDesign-predicted PAMs are largely identical to the natural PAMs of all Cas9s. In turn, given natural PAMs, the computationally redesigned PIAA residues largely recapitulated the native PIAAs (>70% and >80% in terms of identity and similarity, respectively). These results demonstrate that UniDesign faithfully captures the mutual preference between natural PAMs and native PIAAs, suggesting it as a useful tool for engineering CRISPR-Cas and other nucleic acid-interacting proteins. UniDesign is open-sourced at https://github.com/tommyhuangthu/UniDesign.