On a July day a little over a year ago, over 30 people collapsed on a street in Brooklyn. They lay on the ground, vomiting down their shirts, twitching and blank-faced. Some, half-naked, made jerking movements with their arms, eyes rolled back. Others groaned and clutched onto fire hydrants to try to stay upright. Witnesses said the scene was like The Walking Dead. Headlines claimed that people had turned into “zombies,” while police said that the 33 affected were lucky to be alive.

All had smoked an “herbal incense” product called AK-47 24 Karat Gold. Eighteen people were sent to the hospital by ambulance. The situation had all the signs of a drug overdose, and so doctors ordered the usual tests: blood count, urine analysis, heart rate monitoring.

The first patient tested was a 28-year-old man who was slow to respond, but otherwise showed few clear signs of trauma. Heart sounds: normal. Blood count: normal. His lungs were clear and there were no major neurological problems, no excessive sweating or skin lesions. He tested negative for opiates, cocaine, amphetamines. Nothing came up.

The case went to the Department of Homeland Security and the Drug Enforcement Agency. They knew who to call to get a second opinion. They packed blood and urine samples on dry ice and shipped them to a small lab 3,000 miles away in San Francisco, run by toxicologist Roy Gerona. If anyone in the country could figure out what was in 24 Karat Gold, it would be him.

Forty years ago, drugs had easy names: cocaine, meth, heroin. Today, the names can read like an ingredients list for a chemistry class: 5F-AMB, PX-2, MDMB-CHMINACA. Today’s designer drugs are made by synthesizing chemicals and hoping they give you a high that’s strong enough to be worth it, but not strong enough to send you to the hospital.

Designer drugs are volatile. If you tweak just one molecule, you can get an entirely differently substance, one you hadn’t bargained for. They’re also easy to get. There’s no shortage of “research chemicals” vendors on the dark web are willing to sell. And they’re growing more popular. These so-called “novel psychoactive substances” entered the mainstream in 2009. That year, according to the United Nations Office on Drug and Crime, there were about 100 of these substances reported; six years later, there were nearly 500. Because designer drugs don’t show up on traditional drug tests, they’re hard to track and identify. It’s a public health problem that requires a special set of skills to handle.

One of the most prominent categories of designer drugs are those intended to mimic marijuana, called synthetic cannabinoids. Marijuana, or cannabis, is widely considered one of the safest drugs, but synthetic cannabinoids are some of the most dangerous synthetic drugs. The Global Drug Survey (GDS) found that last year, for the fourth year running, the risk of seeking emergency medical treatment was higher after using synthetic weed than for any other drug.

Around 2004, labs in China started synthesizing the compounds and distributing them as “herbal incense”

When you smoke a regular joint, a chemical called tetrahydrocannabinol (THC) travels through your blood. It binds with receptors called CB1 and CB2. Because of the structure, there’s “kind of a limit on how stoned you can get,” says Adam Winstock, a London-based psychiatrist who administers the GDS. If you’re smoking a popular cannabinoid like K2 Spice, a chemical travels through your blood, but this time, it’s not THC. It’s something else that also binds with CB1 and CB2 — but unlike with regular weed, we don’t know exactly how these chemicals bind, especially when they’re illicit drugs from the black market. This mystery makes synthetic marijuana likely to lead to “much more extreme responses,” like seizures and psychosis, according to Winstock.

Synthetic cannabinoids originated in a quest to create a better pain medication. A Clemson University chemist named John W. Huffman synthesized hundreds of compounds in an attempt to find a better painkiller, but often created incredibly psychoactive substances with no medicinal properties at all. When he published the results of these compounds — called JWH compounds, after his initials — he made the information available to be copied.

There are more than 300 JWH compounds alone, and around 2004, labs in China began studying old research papers, synthesizing the compounds and distributing them as “herbal incense” products. K2 Spice itself — often partly based off the JWH-018 compound — started in China, became popular in Germany around 2008, and entered the US around 2009.

Labs can also turn to the expired patents — patents that are rich fodder, even if (or perhaps because) there was a good reason said drugs never made it to market. It’s nearly impossible to figure out how to shut down the overseas labs producing these drugs. As soon as you ban one substance, the labs move on to another.

Gerona, a toxicologist with gray hair styled in an undercut, was the one who received the biological samples from the DEA. From a small lab in the Medical Sciences Building at the University of California, San Francisco, Gerona says he and his team are playing a “cat and mouse game” with illicit international drug manufacturers. When an overdose happens, Gerona’s team tries to identify the drug in question — often synthetic substances no one has seen before. But the lab goes one further: Gerona’s lab attempts to identify and classify these substances before the mass overdoses even happen.

Inside, the lab is meticulously neat: rows of spotless tables are covered in bottles with orange rubber caps, all labeled with orange duct tape, and small gray centrifuges. A window overlooking a courtyard has molecular structures scribbled over it in pink and green marker. Near the door sits an enormous freezer, filled with thousands of brightly colored, frost-covered boxes of drug samples kept at -112 degrees Fahrenheit.

2010 was the year that a designer drug called “bath salts” began flooding the market

Gerona launched his toxicology lab in 2010, in partnership with the San Francisco Poison Control Center. The date wasn’t a coincidence; he says that 2010 was the year that a designer drug called “bath salts” began flooding the market. “Bath salts” is a blanket term for a group of designer drugs made from stimulants; they create a euphoric high like MDMA, sometimes with hallucinations thrown in. The drugs usually come in powdered and capsule form, and can cause freak-outs that were well-documented on YouTube at the time. The most famous of these was a viral story of a 31-year-old Miami resident attacking and then eating a homeless man. (Scientists dispute the drugs’ role.)

For users and the DEA, the spike in bath salts use was a nightmare. For Gerona, the increased interest in designer drugs led to more work and more samples from around the country. Eventually, the lab caught the notice of both Michael Schwartz, a toxicologist at the Centers for Disease Control and Prevention, and DEA pharmacologist Jordan Trecki. A collaboration between Gerona’s lab and the DEA was formed. (Neither the DEA nor the CDC responded to repeated requests for comment.)

The first step in doing an analysis at Gerona’s lab is getting the sample — urine, blood or, rarely, a tiny bit of drug itself — shipped over on dry ice. In traditional drug testing, you check to see if the sample matches any of the known substances: marijuana, heroin, cocaine, and so on. They match, or they don’t. Designer drugs, almost by definition, are made of chemical combinations we haven’t seen before. They almost never match traditional databases, and the chemists often don’t know what they’re looking for. So Gerona’s lab gathers as much information about the substance as possible.

A tiny vial of the biological sample — usually plasma, the colorless part of blood — goes into a bulky, printer-like machine. That machine is called a liquid chromatography mass spectrometer, and very crudely put, it separates out all the different parts of the plasma by mass. (Think of it like an extremely sensitive centrifuge.) That process makes it easier to identify chemicals, and the mass spectrometer then spits out the different measurements in a computer chart with peaks and valleys called a chromatogram.

Then, says Axel Adams, a graduate student in Gerona’s lab, you turn to the so-called “prophetic library.”

Researches look for posts about drugs on subreddits like r/researchchemicals

Gerona’s “prophetic library,” about three years in the making, is a detailed catalog of already synthesized variants that his team believes is going to be the next big street drug. The library was made possible with the help of Samuel Banister, a synthetic chemist at Stanford University. Banister synthesizes variants of popular street drugs and takes down their chemical information to create “reference standards.” Synthesizing can take anywhere from a few days to a couple of weeks; the lab now has almost 150 variants on file. It’s a side job for Banister, but at one point, he says, “I was pumping out five to 10 a week.” The final products look like white crystalline solids and are kept in drawers in the lab, ready for when a case like AK-47 24 Karat Gold comes along.

In addition, lab members spend hours each week on drug forums, researching trends. It’s more of an art than a science. Researches look for posts about drugs on subreddits like r/researchchemicals. They reference surveys like the Global Drug Survey and survey “trip reports” from experiential documentation sites like Erowid and PsychonautWiki.

They look for terms like synthetic pot, K2, Spice, and sometimes, scientific terms like “cannabinoids,” or a specific popular class of cannabinoids, like “FUBINACA” or “JWH compounds.” Often, the posts themselves will include the name of the chemical. Gerona has ordered drugs off the dark web. In one case, the invoice billed him for “cosmetics,” and the package included lipstick, fake eyelashes, and tabs labeled “powder.” The “powder,” unsurprisingly, turned out to be drugs. But most of the time, the drugs in the powder were not the drug that was ordered.

The invoice billed him for “cosmetics,” and the package included lipstick, fake eyelashes, and tabs labeled “powder”

If there is a match because the compound is already in the library, finding the right variant is “only going to take 15 minutes,” says Gerona. “Otherwise, it could take a week, or it could not be solved.”

Adams checked the results of a blood sample tied to AK-47 24 Karat Gold against the prophetic library. The computer pulled up a chart that indicated a line — jagged, up and down — that shows the mass of the components of AK-47 24 Karat Gold, versus the same information for AMB-FUBINACA.

Drugs don’t pass through the body untouched. Once they’re ingested, the body processes the compounds. So by the time they’re in the blood or urine, it’s not exactly the same compound as the drug that was ingested. It’s hard enough to find a reference standard for the original compound; it’s even more difficult to find a reference standard for the possible variants. In the case of AMB-FUBINACA, the chemical in the biological sample from Brooklyn wasn’t the parent compound. It was a derivative. Luckily, Banister had already synthesized that variant, too.

The peaks and valleys of the two lines of AK-47 24 Karat Gold and AMB-FUBINACA matched up precisely. It took the team only seven days to identify the substance in the Brooklyn case — and most of that time was spent waiting for the sample to get there.

Gerona’s lab has worked on cases across the country, from New York City to Sacramento to Colorado. The number of cases varies. Sometimes, they’ll get 15 to 25 samples a month. One Mississippi case involving synthetic cannabinoids resulted in over 400 samples. The average turnaround on results is about six months, says Adams. That’s not good enough for Gerona.

And it’s not likely that the problem will go away. Marijuana legalization advocates claim that people will stop with the synthetic stuff once the real thing is okay. But that’s not true in the experience of Andrew Monte, a clinical toxicologist at the University of Colorado School of Medicine who collaborates with Gerona’s lab. Recreational marijuana is legal in Colorado, but he sees patients who are on these synthetic compounds anyway. Monte’s team has surveyed people who come into the ER and even set up at music festivals to ask attendees questions. Synthetic drug users are “taking it for a different reason, to get a different high,” Monte says. “They’re really looking for something different than what pot gives, the same way you might choose cocaine over pot or meth over pot.”

One Mississippi case involving synthetic cannabinoids resulted in over 400 samples

To help address this problem, in 2016 Gerona started a new research consortium called P SCAN, or the Psychoactive Surveillance Consortium and Analysis Network. (Yes, the double entendre is intended.) They’re working with about 10 poison control centers in places like Kansas and Colorado. They’ve had more than 100 cases referred to them and are writing up case reports and manuscripts. (The 24 Karat Gold case was published by the New England Journal of Medicine.)

P SCAN will continue to do the surveillance work Gerona has been doing for years, but also create a database of clinical data connected to the specific synthetic drugs they track and discover. Think of it like a medical version of Erowid. This way, the next time there’s an outbreak like the one in Brooklyn, investigators and researchers can look at specific physical indicators (heart rate, respiratory information, neurological information, and more) and say, “Ah, this matches the symptoms of AMB-FUBINACA” — all without shipping samples across the country.

But even with P SCAN and the prophetic library, the task is huge. “The identity of a lab needs to constantly expand and rework in order for it to stay relevant,” says Gerona.

Gerona is a biochemist by training. Before launching his lab, he didn’t know anything about Spice, or AK-47 Gold, or the dark net. But now, Gerona says, “I have no other choice but to really learn about it, so that I am relevant and retain my relevance in the field.” He’s hoping to work with people in technology to automate this “market research” to glean new insights and make the prediction process even faster. “It would be so great if we could predict the drugs coming in with more accuracy, instead of after people are hurt,” he says.

Weeding out designer drugs is a Sisyphean task, Gerona admits. It may be impossible to shut down the overseas labs, but he wants to have even better methods for predicting what’s going to get big and then, instantly identifying the substances. He compares the endless drug variations to nature: the cold virus is still around because it changes all the time. HIV has never been cured because it continues mutating. “In a sense, they’re reinventing themselves all the time, so reinvention is key to persistence. As long as you’re reinventing yourself, you can persist.”