I'm trying to call an external program (Openbabel) to each element (molecule) in a list of molecules (SMILES format). However, I keep getting the same error:
/bin/sh: 1: Syntax error: "(" unexpected (expecting ")").
What is wrong with my code?
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)
subprocess.call
requires an iterable of commands and arguments. If you need to pass command-line args to a process, they belong in an iterable. It's also not recommended to useshell=True
as it can be a security hazard. I'll omit it below.Try this: