Genex Corp.'s disastrous relationship with the NutraSweet Co. is finally over.

Two years after NutraSweet's cancellation of a major contract with the Gaithersburg biotechnology firm left its $17.5 million production plant in Kentucky idle and the two companies in a bitter legal dispute, Genex formally closed the book on the episode last week.

Genex has sold the Kentucky plant to the Chicago-based chemical firm H.B. Fuller Co. for about $5.8 million and has resolved its legal dispute with the maker of the sweetener.

"These resolutions will allow management to concentrate our energies on the future," said Gary E. Frashier, Genex's president and chief executive officer. "Genex is now positioned to move aggressively forward to commercialize its technologies and to pursue new and promising corporate relationships."

Although the plant was sold at a substantial loss, Genex officials said the company will recognize a gain on the transaction because of earlier writedowns on the property. The sale will also reduce overhead costs for the firm by $1 million annually. Together with a cash settlement paid by NutraSweet of between $100,000 and $500,000, Genex said it expects a gain of $3.5 million in the third quarter.

The NutraSweet Co., a subsidiary of G.D. Searle and Co., awarded Genex a contract in 1983 to supply genetically engineered raw materials for the low-calorie sweetener aspartame. At the time, the deal was thought to have a potential value of hundreds of millions of dollars for Genex, and accounted for almost 90 percent of the company's revenue in the first half of 1985.

But after NutraSweet abruptly canceled the agreement in 1985, Genex stock fell from its historic high of $22.50 to just over $1 per share, and the company was left with an unused 280,000-square-foot manufacturing facility.

Last week's settlement marks the latest step in what has been a long and painful recovery for the firm, once considered the brightest light in the burgeoning Maryland biotechnology industry.

After being widely criticized for its overreliance on the NutraSweet contract, Genex has diversified its product line in recent years and cut its dependence on contract work to 25 percent of the firm's business, with further decreases expected.

Earlier this month, the company completed a successful $8.4 million offering of convertible preferred stock, and repaid in full a $4 million loan made last March by several venture capital firms. The additional capital from the stock offering will be used in the development of several new products, including an adhesive protein derived from mussels that might be used in soft-tissue and dental surgery.

"We've restructured and refocused the company entirely with new management and a new board," says Frashier, who joined Genex April 1 after the resignation of J. Leslie Glick, who had guided the firm for more than a decade.

The settlement with NutraSweet also frees Genex of the burden of a legal battle dating back to 1985. After the termination of the contract, Genex filed a $40 million lawsuit against NutraSweet for fraud and violation of federal antitrust, racketeering and securities laws. Under a settlement reached in late July, the parties agreed to a mutual release of all claims and the payment of a nominal sum to Genex.

Last week Genex reported a net loss of $3.3 million (26 cents per share) for the first half on revenue of $693,000, compared with a loss of $1.4 million (11 cents) on revenue of $1.7 million for the year-ago period. It reported a second-quarter loss of $1.7 million (13 cents) on revenue of $423,000, compared with a loss of $1.2 million (10 cents) on revenue of $796,000 for the second quarter of 1986. Company officials admit that it will be some time before the company generates a positive cash flow.

But some analysts see a general improvement in the firm's prospects. According to Thomas Taylor, who follows the biotechnology industry for the Chesapeake Securities Research Corp. in Baltimore, "They only need one successful product to throw them back into the black. They've been traumatized, and they're unlikely to put their head in a noose again."