Something within Loudoun County horse trainer Theodore Gregory "snapped like a rubber band" and he started firing his gun when he found his wife in bed with his best friend, a defense psychiatrist testified today at Gregory's first-degree murder trial.

Gregory's friend and fellow Middleburg horseman, Howard LaBove, was killed as the two grappled for the gun in the incident 2 1/2 years ago.

Gregory "snapped" when he "heard the unmistakable sounds of love-making" as he stood outside LaBove's cottage window, the psychiatrist, Dr. David Lanham, testified. Lanham said Gregory had told him that when he then entered and saw the couple, he reacted "like an exploding light bulb."

Lanham's account on the third day of testimony here gave the jury its only glimpse of Gregory's version of events on the fatal night. Both sides completed their evidence in the case late today without the 31-year-old Gregory taking the witness stand.

Psychiatric testimony by prosecution experts generally coincided with the defense account of events on the night of Aug. 20, 1980, but directly contradicted Lanham's contention that Gregory was gripped by an irresistible impulse in the shooting.

Dr. James Dimitris, a psychiatrist at Central State Hospital in Petersburg, Va., who interviewed Gregory on four occasions, testified for the prosecution that the shooting was "an act unresisted and not irresistible."

A second prosecution expert, psychologist Henry O. Gwaltney Jr., acknowledged under cross examination that Gregory felt "totally betrayed" by his wife and LaBove and was "in a condition of panic" at the cottage. Gwaltney said, however, that Gregory's depression and anxiety stopped well short of mental disease. "It was the end of his world as he saw it at that time," said Gwaltney.

Under Virginia law, a defendant may be aware of the nature and consequences of his actions and still win acquittal if the jury finds he lacked the capacity to control his sudden impulse to act. If convicted, Gregory could be sentenced to 20 years to life in prison.

Lanham, former chief of forensic medicine for the District of Columbia, testified for the defense that Gregory suffered from two mental disorders -- a schizoid personality and clinical depression -- that worsened after Gregory and his wife, Monique Dana, separated three months before the shooting.

"He was having all sorts of fantasies -- torturing fantasies of Monique's having sex with other men," Lanham said. "He was listening to country songs about cheating women. The sadder the song, the better he liked it."

When Gregory once found LaBove talking to Dana after their estrangement in May 1980, Lanham said, LaBove assured Gregory the relationship was innocent. " 'I'm your best friend in Middleburg,' " LaBove told him, according to Lanham.

On the fatal night, Lanham testified, Gregory had dinner with his parents at a Fauquier County restaurant, then stopped in Middleburg on the way home. Across the street, he saw LaBove and Dana leave a restaurant and Dana put her arm on LaBove's shoulder and whisper to him. When LaBove and Dana left in separate cars for LaBove's cottage, Lanham said, Gregory "felt compelled to follow."

"It was like a living part of him getting up and walking away," said Lanham. "He knew he was fishing in the wrong waters, but he couldn't help it."

At the farm north of Middleburg where LaBove was a tenant, Gregory parked near the entrance, placed a .45 automatic in his belt, removed his shoes and walked up the gravel driveway, Lanham testified.

After hearing the couple from outside, the psychiatrist said, Gregory entered the cottage, switched on the living room light and flung open the bedroom door.

"The visual imagery. . . was like cold water on a hot light bulb," Lanham said Gregory told him later.

Lanham said Gregory "remembers very little" of the shooting.

Gregory understood, Lanham said, that he had participated in a shooting and went to the Middleburg police station to surrender, only to find it unmanned because the town's officers were out searching for the shooting suspect. Gregory was arrested the next day.

Closing arguments in the trial are scheduled to start Friday morning.