The gunman who shot and killed his former professor before turning the gun on himself at UCLA has been identified as Mainak Sarkar, a PhD student who had once called slain academic William Klug his mentor.

According to the LAPD, Sarkar had accused Klug of stealing his computer code and giving it to someone else. The Los Angeles Times reported that Sakar killed himself after shooting Klug in one of the college's engineering facilities.

Klug, an associate professor of Mechanical and Aerospace Engineering, had been aware of Sarkar's accusations against him. The former student had taken to social media on March 10 to call the professor a "very sick person".

"William Klug, UCLA professor is not the kind of person when you think of a professor. He is a very sick person. I urge every new student coming to UCLA to stay away from this guy," the student wrote. "He made me really sick. Your enemy is my enemy. But your friend can do a lot more harm. Be careful about whom you trust."

A source at the university told the Los Angeles paper the accusations were ludicrous. They added that Klug had worked hard to help Sarkar despite shortcomings in his work.

In his doctoral thesis Sarkar thanked Klug and wrote: "Thank you for being my mentor". Before enrolling at UCLA, Sarkar earned a master's degree at Stanford University.

39-year-old Klug, a father of two, was described as "brilliant and kind" by his colleagues and an "exceptional mentor" by a former student.

"I am absolutely devastated," said Klug's colleague, Alan Garfinkel, a professor of integrative biology and physiology who worked with the victim to develop a computer generated virtual heart. "You cannot ask for a nicer, gentler, sweeter and more supportive guy than William Klug."

The El Segundo resident earned his undergraduate degree in engineering physics in 1997 from Westmont College, his master's degree in civil engineering in 1999 at UCLA, and a PhD in mechanical engineering in 2003 from Caltech.