Dr. David Nichols has a neatly trimmed white beard, drives a Subaru Forrester, likes to garden, play the harmonica and the flute and wears crisp Jos. A Banks shirts under his lab coat.

He also makes some of the purest MDMA, also known as ecstasy, in the world. And psilocybin (the stuff that makes mushrooms magic) and DMT, the active ingredient in ayahuasca.

When a researcher wants to study hallucinogens, Nichols is their guy.

Nichols is the legal version of Walter White in “Breaking Bad” — the Season 1 version, he’s quick to point out, not the kingpin Heisenberg version of later seasons. He makes the purest forms of these drugs, which are then studied in clinical trials for treatment of a range of conditions, including anxiety, depression, addiction and PTSD.

Now, the drugs he quietly made for years in a windowless lab on the fifth floor of Purdue University’s College of Pharmacy are finally entering the spotlight. As traditional pharmaceuticals used to treat mental conditions have not, in some cases, lived up to their promise, psychedelics are in the midst of a renaissance.

Recent research has led to key breakthroughs: On Dec. 1, the Food and Drug Administration cleared a third phase of clinical trials for MDMA to treat PTSD patients, and advocates are saying MDMA is on track to potentially become a legal, therapeutic medicine in the next five years. On the same day, a study at Johns Hopkins found that psilocybin was remarkably effective in relieving anxiety and depression in cancer patients, with the effects lasting up to six months or more. Nichols, a medicinal chemist and pharmacologist, made the MDMA for the PTSD study and the psilocybin for the Johns Hopkins cancer study.

Though Nichols’ name is a footnote in these studies, without him neither would have been possible, said Roland Griffiths, the scientist who led the Johns Hopkins study. “It’s hard to overstate his importance to this work,” said Griffiths. “It is very rare indeed that a single individual has such a profound influence on an entire area of clinical research.”

Unlike his colleague and friend, chemist Alexander “Sasha” Shulgin, the so-called “godfather of MDMA” who popularized the compound, Nichols has kept a low profile. Shulgin discovered over 150 psychoactive drugs in his sprawling lab in Northern California — many of which he tested himself — and was worshiped like a god by psychedelics devotees.

But Nichols doesn’t have a ponytail or an extensive Grateful Dead bootleg collection. The strongest drug he takes these days is naproxen for arthritis. He doesn’t drink wine because he thinks alcohol ruins the taste of fruit juice. He doesn’t even drink coffee in the morning — instead he gets going with a can of V8.

I believe in their value as molecules that heal people. I guess you could say I was a mole in the system.

“I wanted to bring legitimacy to the field,” he told The Post. “I have always just been convinced that psychedelics are important and that their importance has been overlooked for all these years. I believe in their value as molecules that heal people. I guess you could say I was a mole in the system.”

Perhaps it’s no coincidence that Nichols would end up working on a cure for PTSD, having lived with a father who he believes suffered from an undiagnosed case of it. Nichols’ father, Earl, went from high school into the Army, serving in France in World War II. Afterward, he worked in a print shop and continued to serve in the Army Reserve, retiring as a lieutenant colonel.

“He ran our house like a military barracks,” said Nichols. His father treated Nichols and his brother like soldiers, shouting “Fall in men!” at them and whistling “Taps” at bedtime. “Maybe part of my motivation is to heal people like my father,” he said. “People who were really kind of bent by life.”

Nichols was a good kid in high school, “a science geek,” but in college during the ’60s he wanted to sample hippie culture, so when a friend offered him some mescaline, the active substance in peyote, he took it. Under the influence he “left the known universe,” he said. “We were in the middle of nothingness, and the universe was humming and I knew it was a womb for life,” he said. “It makes no sense to me now, but it did then.”

He took mescaline once or twice again after that, tried LSD and took MDMA once before it became illegal. And, he says, that’s it.

Around the same time, therapists were successfully using LSD to treat some of their patients with a range of mental disorders. But after the drug was embraced by the hippie movement, the backlash was swift. LSD was outlawed in 1968 (DMT, mescaline, psilocybin all were criminalized shortly thereafter) and the nascent field of psychedelic psychotherapy was stopped in its tracks.

His first experience with mescaline “piqued his interest” enough that he went to graduate school at the University of Iowa to study the drug in 1969. After he moved to Purdue as a professor in 1974, he applied for and was given a grant, and a license, to produce psychedelics for 28 years for the National Institute on Drug Abuse. He would make and give drugs to rats and cats to better understand addiction in humans.

He was, for years, one of the only academics in the country who could legally make Schedule 1 drugs. (Today, there are only two universities with permission to do this work.)

As his colleagues worked on cancer and HIV drugs, Nichols made more than 2 kilograms of MDMA (16,000 pills), 10 grams of DMT (roughly 350 doses), an ounce of psilocybin (about 1,000 doses) and 4 grams of LSD (about 40,000 doses) — all for research purposes. He never really talked about his work in psychedelics to his colleagues, mostly because no one was that interested, he said. Plus, his lab wasn’t that secure, so he wanted to make sure no curious kids would break in and test his product.

He was never much tempted to take the drugs he made. He thought it would set the wrong example.

“I really tried to maintain respectability as a scientist,” he said.

In the late ’70s, Nichols’ pal Shulgin re-synthesized MDMA (which was first discovered by the German pharmaceutical company Merck in 1912), and a small group of therapists started giving it to their patients. Proponents of the drug said it allowed people to access emotional places they might resist in normal conscious states, without any fear or trepidation. They say it’s especially useful for treatment of trauma.

But by the mid-’80s, the drug had leaked out into the party scene under the nickname “ecstasy.”

Rick Doblin, then a college student who had always hoped to become a therapist, knew it was only a matter of time before MDMA became illegal, much like LSD, so he began to push to prove the drug was safe and had medicinal value. To do this, he turned to the wizard in the white lab coat.

Nichols had never made MDMA before, but he was more than familiar with the compound having co-published, with Shulgin, a paper on the drug in 1978. By this point, Nichols himself had grown frustrated with rats and cats and the lack of clinical trials with psychedelics on humans. He told Doblin that for the price of the materials, he’d make the MDMA for him.

For a month he worked with a team of grad students to make batches of it in their spare time — they made about 2 kilograms of MDMA, which, by the way, is still pure and stable to this day — and about 940 grams of that original batch remains. Today Nichols’ total original batch would have a street value of about $400,000. He sold it to Doblin for $4,000.

Doblin used that MDMA to run clinical trials on combat veterans, firefighters, police officers and survivors of sexual assault, all suffering from PTSD. The trials have been successful — many of the subjects have seen their symptoms drastically reduced after talk therapy and three doses of the drug — and MDMA could be approved as a legal therapeutic medicine by 2021, Doblin said.

Brad Burge, communications director of the Multidisciplinary Association for Psychedelic Studies, or MAPS, which is the nonprofit that Doblin now runs, said “a pure MDMA compound used a limited number of times in a therapeutic setting is safe.” He won’t vouch for the safety of recreational use, pointing out that more than half of ecstasy pills sold on the street, when tested, are found to have no MDMA in them at all.

Doblin is hopeful it will soon be legalized, meaning a physician would prescribe it and a licensed therapist would administer it. Already MAPS has trained 125 therapists for that purpose.

Jonathan Lubecky was the subject of one of Doblin’s trials. Lubecky was a Marine from 1995 to 1999 and after watching the Twin Towers collapse, he knew he had to re-enlist. In March 2003, he went back into the Army and in August 2005 was deployed to Iraq. He was stationed out of Balad Air Base in the Sunni Triangle, where he worked what’s called “overwatch,” sitting on the front gate of the base with a Barrett .50 caliber sniper rifle held to his eye while watching everyone coming and going through the scope. He protected the base and saved lives, but he had to kill people to do so.

One night in March 2006, he went to the port-o-john and a mortar exploded just outside. The blast wave hit him, causing a traumatic brain injury. A few months later, he was back home in Raleigh, NC, only to discover his wife had left him. Soon he found himself alone in a bar on Christmas Eve. He listened to the bells ringing at a church nearby and tried to get into midnight Mass but was turned away because there wasn’t room, he says. He left and sat outside at the Veterans Monument in downtown Raleigh for the next two hours trying to figure out the best way to kill himself. He finally went to Womack Army Medical Center at Fort Bragg and told them he was suicidal. He says they gave him six Xanax, told him to go home and give all his ammunition to his neighbor and come back after the holiday. Instead he went home, drank a bottle of vodka, loaded a Beretta 9mm, put it to his temple and pulled the trigger. The gun malfunctioned, but the nanosecond when the hammer was falling was the most peace he had known in a long time, he said.

(Col. Kenneth Shaw, Acting Commander of the medical center, said while he can’t comment on the care of an individual, “Suicide prevention is something we take very seriously. We have a team of dedicated mental-health professionals who work with the emergency department and military personnel across Fort Bragg to provide immediate care to anyone expressing suicidal ideation.”)

The thing about PTSD, Lubecky says, is that you don’t know you have it until you return to civilian life. The constant vigilance and fight-or-flight mode had kept him alive in Iraq. But when he was back in the States, it was making him crazy. During one Fourth of July, his girlfriend found him in the closet, dressed in combat gear with his service dog, terrified. The constant fireworks were “worse than Baghdad” and giving him flashbacks, he said. She had to take him to the local VFW, where he felt safe, surrounded by concrete walls, other veterans and lots of booze. He would go on to attempt suicide four more times in the next five years. At one point he was taking 42 pills a day for injuries and mental-health issues.

For the first time in his life, he was able to talk about the shot he’d fired in Iraq that had haunted him for years.

In 2014, an intern at the medical center told Lubecky about Doblin’s MDMA clinical study, and he immediately enrolled. During his second session with MDMA, he started talking about his time in Iraq. At first he just told the same stories he’d told 100 times — about the heat and the constant mortar fire, but then he started to delve into more disturbing stories. At one point, he had a moment where he saw himself outside his body, floating above himself and the two therapists in the room.

For the first time in his life, he was able to talk about the shot he’d fired in Iraq that had haunted him for years. He was able to see that he had done something that was both morally abhorrent yet necessary to save American lives, and he was able to make peace with it.

When the trial ended, his PTSD symptoms had lessened by half. He’s now remarried and during a recent Fourth of July he was “jumpy” but didn’t have any flashbacks, he said. He now looks forward to his future and he no longer wants to die. “I want to say ‘Thank you’ to Dr. Nichols,” he told The Post. “You saved my life.”

Nichols, who is now 72, retired from Purdue in 2012. He and his wife live in a sunny house on the side of a hill in Chapel Hill, NC, where he’s an adjunct professor of chemistry at the university.

In 1993, he founded the Heffter Research Institute to fund clinical studies of psilocybin with private money, and earlier this month he was hailed by peers at Psychedelic Science 2017, the largest-ever gathering on psychedelic studies, held in Oakland, Calif.

The legal Walter White said he’s encouraged by stories like Lubecky’s and the progress his field has made — especially because he didn’t think he’d live to see it.

“I would always tell people that some day, after I’m dead, you’ll be having a midlife crisis and you’ll be able to go to . . . a psychiatrist who will give you psychedelic therapy to give you perspective on what’s happening on your life,” he said. “It looks like that may happen sooner than I thought.”