First-principles calculations of the linear and nonlinear optical properties of KH2PO4 (KDP) and CO(NH2) 2 are presented. The calculations are an extension of methods we developed earlier and applied to borate crystals. Electronic band structure obtained from a pseudopotential method is input to the calculation. For two crystals considered, the resulting indices of refraction, birefringence, and nonlinear optical coefficients are in good agreement with experiments. The origin of nonlinear effects has been explained through real-space atom-cutting analysis. For KDP, the contributions of PO4 groups to second-harmonic generation effect are dominant, and the hydrogen bonds contribute much more to birefringence. For both KDP and urea, the contributions from the virtual electron process to nonlinear optical responses are dominant.