For nearly 60 years scientists have known the chemical responsible for magic mushrooms' psychedelic reputation is a compound called psilocybin. What we haven't known is the biochemical pathway behind this famous hallucinogen. 

Feel free to now tick that one off your chemistry bucket-list. German researchers have identified four key enzymes involved in making the chemical, potentially setting the stage for mass production of a promising pharmaceutical.

Psilocybin was first identified by the Swiss scientist Albert Hofmann way back in 1959, but has only recently re-entered the spotlight as a safe way to treat conditions related to anxiety, depression, and addiction.

As the evidence mounts, there could be a need for an efficient way to synthesise the compound for experimentation and mass production.

So a small team of researchers from Friedrich Schiller University Jena in Germany sequenced the genomes of the magic mushroom species Psilocybe cubensis and Psilocybe cyanescens to hunt for the biochemical components responsible for constructing this mind-bending molecule.

They had their suspicions, as early work on the molecule's biosynthesis using radioactive tags had already revealed the order of the steps required to turn a molecule of tryptophan - an essential amino acid - into a series of chemicals, ending up with psilocybin.

While the order is a little different than it first appeared, it turns out four enzymes are responsible for the entire process.

Knowing what these enzymes are as well as the genes that encode them is a boon for any future pharmacologist who might want to churn out buckets of the stuff, or tweak the secret recipe to suit their needs.

"Our findings set the stage for heterologous production of [psilocybin] in a controlled place for pharmaceutical purposes, using engineered microbial hosts, should the re-discovered pharmaceutical value lead to increased demands," the researchers write in their report.

Unfortunately since the mid 1960s, the production of psilocybin from mushrooms has been heavily regulated, with a reputation as a mind-altering drug for party-goers rather than a potential therapeutic for mental illnesses.

That not only made it harder to study, its baggage as an illicit substance has dissuaded researchers from looking deeper into any potential benefits.

After four decades of virtually ignoring the science of psychedelics, researchers tentatively returned to investigating how substances such as lysergic acid diethylamide ( LSD) and psilocybin behaved in the brain.

Since then researchers have found evidence that psychedelics can reduce the clinical symptoms of mood and affective disorders, addiction, and even help painful conditions such as cluster headaches.

More recently, it's been found that small doses of psilocybin can be used in conjunction with therapy to help 'reset' brains as they're going through counselling.

As far as risks go, the biggest problems consumers of magic mushrooms currently face stem from mistaking their mycology and picking a toxic dead ringer in the wild, finding specimens that have too little (or too much) active compounds for their liking, or behaving in dangerous ways under the drug's influence.

"Magic mushrooms are one of the safest drugs in the world," consultant addiction psychiatrist Adam Winstock recently told Olivia Solon at The Guardian.

Compared with other illicit substances such as LSD, cocaine, and MDMA, risk of harm from taking psilocybin is at least five times lower.

For all of its promise, even the most advanced clinical trials won't bear fruit for a number of years.

If, or when, psilocybin gets the big tick of approval as a safe and effective form of medication, it's nice to know the groundwork has been set for a cheap and effective production process.

This research was published in Angewandte Chemie.