One (albeit not the only) factor that influences BBB-passage are the exact pKa/pKb-values of the amino- resp. carboxyl-group involved. An example from the class of GABAergic ligands:
Muscimol: pKa1 = 4.8 | pka2 = 8.4
Piperidine-4-sulfonic acid (P4S): pKa1 = <1 | pKa2 = 10.3
GABA: pka1 = 4.0 | pKa2 = 10.7
All three compounds are very potent GABA-A-receptor agonists, but only the first one is active upon oral application. This can be explained easily by the ratio between ionized vs. unionized form, which depend on the shown pKa-values:
ca. 600 for muscimol (for the closely related thiomuscimol even as low as 13!)
800,000 for GABA
> 1,000,000 for P4S.
The lower the value, the more effective occurs BBB-passage.
With regard to loperamide *sigh!*: Neither are carboxylic ligands preferred by the opioid-receptors, nor is the idea of getting loperamide or a close relative into the brain very clever. Rather idiotic, I'd say.