2017-08-03 104 views
0

我試圖調用外部程序(Openbabel)給分子列表(SMILES格式)中的每個元素(分子)。然而,我一直得到相同的錯誤:對列表中的每個元素運行外部程序

/bin/sh: 1: Syntax error: "(" unexpected (expecting ")"). 

我的代碼有什麼問題?

from subprocess import call 

with open('test_zinc.smi') as f: 
    smiles = [(line.split())[0] for line in f] 

def call_obabel(smi): 
    for mol in smi: 
     call('(obabel %s -otxt -s %s -at %s -aa)' % ('fda_approved.fs', mol, '5'), shell=True) 

call_obabel(smiles) 

回答

0

subprocess.call需要可迭代的命令和參數。如果您需要將命令行參數傳遞給進程,則它們屬於可迭代的。也不建議使用shell=True,因爲這可能會造成安全隱患。我會在下面省略它。

試試這個:

def call_obabel(smi): 
    for mol in smi: 
     cmd = ('obabel', 'fda_approved.fs', '-otxt', '-s', mol, '-at', '5', '-aa') 
     call(cmd) 
相關問題