It is not too difficult to do this with a python script:
You basically start the engine as a subprocess and communicate via "uci".
I'll post some not very pretty code snippets and try to explain what you have to do:
engine=subprocess.Popen('./stockfish-5- 64',universal_newlines=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE,)
def put(command):
print command
engine.stdin.write(command+'\n')
if command!='quit':
engine.stdin.write('isready\n')
while(True):
text=engine.stdout.readline().strip()
print
print text
print
if text == 'readyok':
return
def get():
engine.stdin.write('isready\n')
while(True):
text=engine.stdout.readline().strip()
print text
if text == 'readyok':
break
if text !='':
print text
def getResult(depth):
Result=[]
while(True):
text=engine.stdout.readline().strip()
liste=text.split()
if text[:22]=="info depth "+str(depth)+" seldepth" and liste[15]=='1':
Result=[]
if text[:22]=="info depth "+str(depth)+" seldepth":
Result.append(text)
if text[:8] == 'bestmove':
break
Scores=[]
for line in Result:
liste=line.split()
Scores.append(liste[7])
return Scores
def Game_Analysis(game):
scorestring=''
moves=''
for x in range(len(game)-1):
moves+=game[x]+' '
command='position startpos moves '+moves
put(command)
get()
put('go depth 15')
Scores=getResult(15)
for score in Scores:
scorestring+=score+' '
scorestring+='\n'
return scorestring
get()
put('uci')
get()
put('setoption name MultiPV value 20')
get()
print Game_Analysis(game)
put('stop')
put('quit')
So, get() and put() are for communicating with the engine.
put('uci') starts the dialog.
put('setoption name MultiPV value 20') tells the engine to return the best twenty moves. (In your case you really only need 2)
command='position startpos moves '+moves
put(command) This sets up the position, unfortunately the moves aren't pgn but in uci-format. So you'll probably have to transcribe or use FEN.
In GetResult() I extract the 20 best scores of the position. Then you only need to look for a big difference between move one and move two.
Game_Analysis(game) extracts the 20 best scores for every position in a game, here given as a list of uci-formated moves.
To deal with the uci-format and really understand these commands you should have a look at the uci=Universal Chess Interface.