There’s something odd about the many species of magic mushrooms: they’re not related to each other.

Normally, you’d expect such a complex and powerful chemical as psilocybin – the magical ingredient -- to be produced by a closely related group of organisms whose common ancestor discovered it once.

But not in this case. Scores of mushroom species – one lichenized -- from five different distantly-related families make it. A team of American scientists wondered about that, and had a hunch about why it might be.

 They tested their hunch by, for the first time, identifying the psilocybin-producing genes (there turned out to be five) and comparing the versions found in the various magic mushrooms. And sure enough: the genes shared the same origin. The psilocybin gene cluster had somehow found its way into distantly related species in a process called horizontal gene transfer, in which unrelated organisms steal genes from one another.

Although mushroom-making fungi, considered sophisticated and complex for the fungal world -- have only rarely been caught donating or stealing genes, the fact that they have made an exception for these genes implies psilocybin is a seriously hot item.

But why? A better question might be what, exactly, does a coffee bush get out of making caffeine, or a coca plant out of making cocaine? Why do magic mushrooms bother to be magic? They aren’t getting magical trips out of the deal.

The surprising reality is that the majority of naturally-produced recreational drugs – caffeine, nicotine, cocaine, morphine, and psilocybin evolved to be, if not quite insecticides, then scramblers of insect brains. The fact that our brains are enjoyably scrambled by them too is sheer coincidence, but also speaks to the uncomfortable truth that your brain is not so different from a cockroach’s as you might like to think. (Of course, you’re also not so different from a plant either)

In humans, psilocybin is converted to psilocin on ingestion, which activates one of the same receptors as feel-good neurotransmitter serotonin and produces the wild effects for which the drug is known. Serotonin, incidentally, is the same molecule on which antidepressant serotonin-reuptake inhibitors like Prozac act. However, serotonin is not the private preserve of humans. All animals with left-right symmetry – including insects -- produce serotonin, as well as some plants and fungi.

A plant has an obvious motive for stockpiling a chemical arsenal: prevent itself from becoming a salad bar. But what about mushrooms? The majority of psilocybin-producing mushrooms are either wood or dung decayers. In those environments, they are not only being eaten by insects, but also competing with them for food. Termites are major fungal competitors inside decaying logs, but a variety of other wood- and dung-eating insects fight with fungi for food.

Psilocybin may help tilt the playing field in the fungus’s favor by causing insects to, I don’t know, maybe blank on what they went in that log for again? Another serotonin receptor antagonist called 5HT-2A causes Drosophila fruit flies to somehow neglect to eat that fruit they’re sitting on.

At least one of the chemicals that makes mushrooms poisonous – muscarine – is often made in the same mushrooms that make psilocybin in the genus Inocybe, which suggests It has a similar purpose. Muscarine is a mimic of the neurotransmitting brain chemical acetylcholine, which helps translate electrical impulses into muscle action, among other roles. Although no one knows its exact effects on insects (if any), when consumed by humans in mushroom form, it causes PSL syndrome: perspiration, salivation, and lachrymation. The most famous acetylcholine mimic, however, is nicotine.

Decay mushrooms aren’t the only fungi in the insect manipulation business. Fungi that parasitize insects have also been known to use neurotransmitter-mimicking chemicals to zombify their victims. Social insects like termites might be especially vulnerable to attempts to screw with their brains because their success depends on socializing, not typically an insect strong suit and also a skill that requires nuanced brain power.

In the process of searching for the psilocybin-producing genes, the scientists made another rather fascinating discovery: there was less variation in the gene content of distantly-related wood decay fungi than between decay fungi and their close relatives in other habitats. The common thread between wood and dung decaying fungi may be the shared interest in attacking tough plant fibers like lignin and in repelling the insects that compete with them. The fact that their shared environment seems to be a stronger driver of gene content than shared ancestry is quite stunning, I think.

As a result of the chemical warfare going on between fungi and insects in dung and dead logs, these results also suggest decay mushrooms may be a good place to search for new neuro-active drugs. Fungi in such haunts may be veritable factories of neurotransmitter-targeting drugs. Though originally intended to throw insects off their game, there is no telling what unintentional, valuable – and interesting -- effects they may have on us.