Thomas Folks spent years in his U.S. Centers for Disease Control and Prevention lab developing a treatment to block deadly HIV in monkeys. Then San Francisco AIDS researcher Robert Grant, using $50 million in federal grants, proved the treatment worked in people who engaged in risky sex.

Their work — almost fully funded by U.S. taxpayers — created a new use for an older prescription drug called Truvada: preventing HIV infection. But the U.S. government, which patented the treatment in 2015, is not receiving a penny for that use of the drug from Gilead Sciences, ­Truvada’s maker, which earned $3 billion in Truvada sales last year.

Gilead argues that the government’s patents for Truvada for PrEP, as the prevention treatment is called, are invalid. And the government has failed to reach a deal for royalties or other concessions from the company — benefits that could be used to distribute the drug more widely.

“With the amount of effort and time and taxpayer money that went into it, for CDC and Gilead not to come to an agreement, so the taxpayer could get some of that money, is really unconscionable,’’ said Folks, who is retired.

The extraordinary standoff between the CDC and a drug company over patent rights raises a big question for the Trump administration: How aggressively should the government attempt to enforce its patents against an industry partner?

The Department of Health and Human Services, which includes the CDC and the National Institutes of Health, has patented more than 2,500 inventions created with taxpayer dollars since 1976, according to the U.S. Patent and Trademark Office.

It routinely licenses new pharmaceutical compounds to private companies that take those publicly financed discoveries into the marketplace.

Intellectual-property disputes between private companies are common, and they often wind up in court. But it is rare for the government to bring lawsuits over pharmaceutical patents.

Gilead, which enjoys a U.S. monopoly on Truvada, charges between $1,600 and $2,000 for a month’s supply of a pill that can be manufactured for a fraction of that amount. The number of new HIV infections in the United States has barely budged, meanwhile, and is stuck around 40,000 a year, according to CDC estimates.

Activists want the government to take a more aggressive stance against Gilead. Their complaints are part of a broader wave of anger over drug companies reaping hefty financial rewards by capitalizing on taxpayer-funded research.

“The CDC has all these patents and is allowing Gilead to rip off the American people at the expense of public health,’’ said James Krellenstein, an HIV/AIDS activist and co-founder of the PrEP4All Collaboration, who has spent months digging into the government patents. Instead of enforcing the patent, Krellenstein said, CDC officials are “twiddling their thumbs.’’

The fight over PrEP presents a novel challenge to the interdependence of drug companies and government developed over years of collaboration.

The government is not locked in a battle for profits, like a private company, said Neel U. Sukhatme, a professor and patent expert at Georgetown Law. Rather, NIH and CDC officials see their role as encouraging the commercialization of government-financed discoveries, not placing curbs on them, Sukhatme said. That tends to take patent infringement lawsuits off the table.

“They may not want to be in the position of suing these companies that arguably are producing valuable stuff,’’ he said.

But that stance increasingly is challenged by political anger over high drug prices. Consumer advocates and members of Congress have stepped up demands that the government exercise its rights under existing law to license generic competition or imports during shortages or unwarranted price spikes; several bills would enhance such “compulsory licensing’’ provisions.

The case of Gilead and Truvada for PrEP adds a new twist to these debates, with demands that the government be more aggressive in exercising its own patent to ease the cost effects of a monopoly.

Government officials would not discuss any aspect of steps they have taken to enforce the CDC patent.

“When it comes to conversations with companies, those are subjects we’re not at liberty to talk about,’’ said Michael R. Mowatt, director of the office within the National Institute of Allergy and Infectious Diseases that represents the CDC in patent licensing matters.

The CDC itself did not respond to multiple requests for comment.

Gilead said it was contacted by the CDC about licensing Truvada for PrEP in 2016.

“Since that time there have been several phone discussions and the exchange of about half a dozen letters addressing the parties’ concerns and positions,’’ Gilead said in a written statement in response to questions from The Washington Post. It would not discuss contents of the calls and letters, citing a confidentiality agreement with the CDC.

President Trump set a goal in his State of the Union speech last month of eradicating HIV/AIDS by 2030; to get close to that goal, specialists say, Truvada for PrEP needs to be far more widespread. Trump’s budget plan unveiled this month would add $291 million to combat the disease.

Gilead began marketing Truvada in 2004 after the Food and Drug Administration approved it to treat people who were already infected by HIV.

Around the same time, government researchers at the CDC were looking for medicine that would do something to curb or even end the epidemic: block HIV from infecting healthy people, even if they engaged in unprotected sex. Gilead worked with the government, providing Truvada doses free of charge to test in the monkeys at CDC labs in Atlanta.

After Truvada was shown to work as a prophylactic in primates, the CDC applied for its patents. That began a nine-year effort, using two outside law firms retained by the CDC, which made its case to U.S. Patent and Trademark Office examiners.

The National Institutes of Health awarded grants to conduct more studies, this time in clinical trials in humans. Grant’s study, led from his lab in San Francisco and published in 2010 in the New England Journal of Medicine, proved that the drug lowered the risk of contracting HIV by more than 92 percent.

In addition to $50 million in government money, $17 million for the study came from the Bill & Melinda Gates Foundation, Grant said.

Based on those clinical trials in humans, Gilead won approval to market Truvada for PrEP, the new indication, in 2012.

Gilead often works in cooperation with federal research agencies because it seeks to develop drugs to fight infectious diseases like HIV/AIDS, hepatitis B and hepatitis C, epidemics that have attracted intense government attention. But it also has been criticized for excessive pricing; in 2013 it sparked an uproar when it priced a 12-week course of the hepatitis C medication Sovaldi at $84,000.

HIV/AIDS activists have been upset about the price of Truvada for PrEP for years. Even though it is covered by most private and government insurance, the drug’s high cost is factored into state Medicaid programs; when those programs pay for the drug, that leaves less money for education and distribution efforts on the ground, they contend.

Federal officials estimated in 2016 that less than 10 percent of the 1.1 million people who should be on PrEP treatment were receiving the drug. Gilead says that has now improved to about 20 percent. The problem is particularly acute in Southern states, where cultural barriers and lack of education programs are holding back its use.

Krellenstein and other activists began unearthing facts about the CDC’s patents last year and then commissioned a report on their validity, which they shared with The Post. The outside review was conducted by Christopher J. Morten, a patent expert and fellow at the Global Health Justice Partnership, a program of Yale Law School and the Yale School of Public Health.

The CDC waged a successful defense of its patent in Europe, adding strength to its case that its patents are legitimate, Morten said.

“I have no reason to believe that these patents are not valid and enforceable, and moreover, they seem to be infringed [by Gilead] by the use of Truvada for PrEP,’’ Morten said in an interview. “These are public assets that were generated with public money that effectively are going to waste here.’’

Gilead maintains that the government improperly claimed to have invented the use of Truvada for HIV prevention.

The drug was already being used by doctors and patients for that purpose “off-label,’’ meaning in a way not approved by the FDA, before the CDC patent application in 2006, Gilead said.

“Further, the patents do not reflect the contributions of Gilead scientists, who collaborated with the CDC to design the monkey studies that underlie the patents. In addition, Gilead provided Truvada free of charge for the primate study,’’ the company said.

Gilead’s Truvada patent expires in 2021; it could be at least two more years before Gilead faces lower-cost competition in the United States.

In response to complaints about its pricing, Gilead said it offers discount coupons that reduce the cost to less than $5 for a monthly supply for patients who lack insurance. It says it has spent $138 million since 2012 on community grant programs to raise awareness and educate at-risk people. Gilead has earned $36.2 billion on Truvada since 2004, according to its annual reports.

“Limited awareness and societal and structural barriers, rather than cost, have hindered broader Truvada usage,’’ the company said, citing studies.

HIV/AIDS activists and researchers say assertions about the benefits of coupons are misleading.

Obtaining Gilead’s coupons for Truvada for PrEP is a cumbersome process, they said. If the CDC leveraged its patents to get money for Truvada, it could help cash-strapped state Medicaid programs undertake aggressive education and distribution programs. Virginia Medicaid said it pays $54.04 per pill, or $1,621.20 for a monthly course of treatment.

“What we’re seeing is that because city and local governments are spending so much on getting PrEP,’’ said HIV/AIDS activist Christian Urrutia, “they don’t have a lot of money left over to do these kinds of programs.’’