2017-08-03 16 views
0

分子のリスト(SMILES形式)の各要素(分子)に外部プログラム(Openbabel)を呼び出そうとしています。リストの各要素に外部プログラムを実行する

/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には、反復可能なコマンドと引数が必要です。コマンドライン引数をプロセスに渡す必要がある場合は、それらは反復可能(iterable)に属します。 shell=Trueを使用することは、セキュリティ上の危険があるため、推奨されません。私はそれを省略します。

これを試してみてください:

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