From dd9101e6ed50ba27d5bc83ae9a2b4807ec240042 Mon Sep 17 00:00:00 2001 From: tjkessler Date: Sat, 8 Jun 2019 11:20:40 -0400 Subject: [PATCH] Reduced timeout, processes try 3 times before throwing exception --- padelpy/functions.py | 76 ++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/padelpy/functions.py b/padelpy/functions.py index 16fdbf8..0932b16 100644 --- a/padelpy/functions.py +++ b/padelpy/functions.py @@ -20,7 +20,7 @@ def from_smiles(smiles: str, output_csv: str=None, descriptors: bool=True, - fingerprints: bool=False, timeout: int=8) -> OrderedDict: + fingerprints: bool=False, timeout: int=4) -> OrderedDict: ''' from_smiles: converts SMILES string to QSPR descriptors/fingerprints Args: @@ -45,22 +45,26 @@ def from_smiles(smiles: str, output_csv: str=None, descriptors: bool=True, save_csv = False output_csv = '{}.csv'.format(timestamp) - try: - padeldescriptor( - mol_dir='{}.smi'.format(timestamp), - d_file=output_csv, - convert3d=True, - retain3d=True, - d_2d=descriptors, - d_3d=descriptors, - fingerprints=fingerprints, - maxruntime=1000*timeout - ) - except RuntimeError as exception: - remove('{}.smi'.format(timestamp)) - if not save_csv: - remove(output_csv) - raise RuntimeError(exception) + for attempt in range(3): + try: + padeldescriptor( + mol_dir='{}.smi'.format(timestamp), + d_file=output_csv, + convert3d=True, + retain3d=True, + d_2d=descriptors, + d_3d=descriptors, + fingerprints=fingerprints, + maxruntime=1000*timeout + ) + except RuntimeError as exception: + if attempt == 2: + remove('{}.smi'.format(timestamp)) + if not save_csv: + remove(output_csv) + raise RuntimeError(exception) + else: + continue with open(output_csv, 'r', encoding='utf-8') as desc_file: reader = DictReader(desc_file) @@ -76,7 +80,7 @@ def from_smiles(smiles: str, output_csv: str=None, descriptors: bool=True, def from_mdl(mdl_file: str, output_csv: str=None, descriptors: bool=True, - fingerprints: bool=False, timeout: int=8) -> list: + fingerprints: bool=False, timeout: int=4) -> list: ''' from_mdl: converts MDL file into QSPR descriptors/fingerprints; multiple molecules may be represented in the MDL file @@ -105,22 +109,26 @@ def from_mdl(mdl_file: str, output_csv: str=None, descriptors: bool=True, datetime.now().strftime('%Y%m%d%H%M%S%f')[:-3] ) - try: - padeldescriptor( - mol_dir=mdl_file, - d_file=output_csv, - convert3d=True, - retain3d=True, - retainorder=True, - d_2d=descriptors, - d_3d=descriptors, - fingerprints=fingerprints, - maxruntime=1000*timeout - ) - except RuntimeError as exception: - if not save_csv: - remove(output_csv) - raise RuntimeError(exception) + for attempt in range(3): + try: + padeldescriptor( + mol_dir=mdl_file, + d_file=output_csv, + convert3d=True, + retain3d=True, + retainorder=True, + d_2d=descriptors, + d_3d=descriptors, + fingerprints=fingerprints, + maxruntime=1000*timeout + ) + except RuntimeError as exception: + if attempt == 2: + if not save_csv: + remove(output_csv) + raise RuntimeError(exception) + else: + continue with open(output_csv, 'r', encoding='utf-8') as desc_file: reader = DictReader(desc_file)