Numerous compounds are reported to interact with dopamine receptors, but the molecular mechanisms mediating dopamine receptor selectivity and activity are poorly understood. Here, Wang et al. determine crystal structures of the D4 dopamine receptor (D4R) in its inactive state bound to the antipsychotic drug nemonapride, with resolutions of up to 1.95 Å. The use of computational modelling to dock a library of more than 600,000 molecules from the ZINC database of commercially available compounds against the 1.95 Å D4R structure identified an extremely potent and specific D4R agonist.