A warlock, who led a double-life as a pillar of the Edinburgh community, was a Dr Jekyll and Mr Hyde "prototype", a new BBC Scotland documentary reveals.
David Hemmings played 'Dr Jekyll And Mr Hyde" in 1980
The documentary, presented by Ian Rankin, reveals the author Robert Louis Stevenson was "horrified" as a child by tales of wizard Major Thomas Weir.
An upstanding preacher, Major Weir shocked his flock by revealing he practised incest and bestiality.
"Ian Rankin Investigates: Dr Jekyll and Mr Hyde" is on BBC Four on Saturday.
Weir and his sister, Jean, were sentenced to be strangled and burned at the stake in 1670.
Local legend has it that his ghost haunts the West Bow area, of Edinburgh, where he lived.
The programme reveals Robert Louis Stevenson had nightmares in the wake of tales about the major told by his nanny, whom he called Cummy.
Mr Rankin said: "Stevenson had always suffered from nightmares. They began as a child growing up in Heriot Row, Edinburgh.
"What made Cummy's bedtime stories for young Louis so terrifying was that they really happened - just outside his bedroom window on the haunted streets of Edinburgh.
"One of Cummy's favourite bedtime stories was about Edinburgh's most famous witch Thomas Weir."
Robert Louis Stevenson was born in 1850 and died in 1894
As Covenanters, Major Weir and his sister "made a great show of piety and godliness and excelled at prayer".
In time, they even became the unofficial leaders of one group who called themselves "The Saints". But they harboured a secret.
Mr Rankin added: "When both Thomas and his sister Jean confessed to a string of sexual offences, the outraged congregation reported the pair to the authorities."
Major Weir, who was born near Carluke, in Lanarkshire, was reputed to have said on the day of his execution, when he was burned at the stake: "Let me alone. I have lived as a beast and I must die as a beast."
The documentary goes out on BBC Four on Saturday at 2155 BST, after the first episode of BBC One's new drama Jekyll, starring James Nesbitt.
The city lost out as the location for the tale because Stevenson thought the home of a famous anatomist, who lived in London, was a great setting.