We have investigated the structural and electronic properties of p-coumaric acid, the chromophore of the photoactive yellow protein (PYP), by means of first-principles molecular dynamics based on density functional theory (DFT). We have studied the chromophore both in the vacuum and in an extended model which includes the nearest residues in the binding pocket of PYP, as derived from crystallographic data. We have characterized the ground state of the isolated chromophore in its protonated and deprotonated forms and computed the energy barrier involved in the trans to cis isomerization process around the carbon-carbon double bond. A comparison of the optimized structures of the chromophore in the vacuum and in the extended protein model, both in the trans (ground state of PYP in the dark) and cis (first light-activated intermediate) configuration, shows how the protein environment affects the chromophore in the first step of the photocycle. Our model gives an energy storage of 25 kcal/mol associated with the trans-to-cia photoisomerization. Finally, we have elucidated the nature of the electronic excitation relevant for the photochemistry of PYP by means of time-dependent DFT calculations.