From 6c10c20442cd9bf319b3756681ea63e564c0d768 Mon Sep 17 00:00:00 2001 From: Kessler Date: Fri, 7 Jun 2019 14:48:25 -0400 Subject: [PATCH 1/6] maxruntime is now an argument, timeout, in seconds --- padelpy/functions.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/padelpy/functions.py b/padelpy/functions.py index 88f3b09..2ae9b9e 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) -> OrderedDict: + fingerprints: bool=False, timeout: int=15) -> OrderedDict: ''' from_smiles: converts SMILES string to QSPR descriptors/fingerprints Args: @@ -28,6 +28,7 @@ def from_smiles(smiles: str, output_csv: str=None, descriptors: bool=True, output_csv (str): if supplied, saves descriptors to this CSV file descriptors (bool): if `True`, calculates descriptors fingerprints (bool): if `True`, calculates fingerprints + timeout (int): maximum time, in seconds, for conversion Returns: OrderedDict: descriptors/fingerprint labels and values @@ -53,7 +54,7 @@ def from_smiles(smiles: str, output_csv: str=None, descriptors: bool=True, d_2d=descriptors, d_3d=descriptors, fingerprints=fingerprints, - maxruntime=10000 + maxruntime=1000*timeout ) except RuntimeError as exception: remove('{}.smi'.format(timestamp)) @@ -75,7 +76,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) -> list: + fingerprints: bool=False, timeout: int=15) -> list: ''' from_mdl: converts MDL file into QSPR descriptors/fingerprints; multiple molecules may be represented in the MDL file @@ -84,6 +85,7 @@ def from_mdl(mdl_file: str, output_csv: str=None, descriptors: bool=True, output_csv (str): if supplied, saves descriptors/fingerprints here descriptors (bool): if `True`, calculates descriptors fingerprints (bool): if `True`, calculates fingerprints + timeout (int): maximum time, in seconds, for conversion Returns: list: list of dicts, where each dict corresponds sequentially to a @@ -113,7 +115,7 @@ def from_mdl(mdl_file: str, output_csv: str=None, descriptors: bool=True, d_2d=descriptors, d_3d=descriptors, fingerprints=fingerprints, - maxruntime=10000 + maxruntime=1000*timeout ) except RuntimeError as exception: if not save_csv: From 757e2adf283ad81ba4157b830708a679f9af7ab9 Mon Sep 17 00:00:00 2001 From: Kessler Date: Fri, 7 Jun 2019 14:49:11 -0400 Subject: [PATCH 2/6] Set default timeout time to 30 seconds --- padelpy/functions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/padelpy/functions.py b/padelpy/functions.py index 2ae9b9e..d48751e 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=15) -> OrderedDict: + fingerprints: bool=False, timeout: int=30) -> OrderedDict: ''' from_smiles: converts SMILES string to QSPR descriptors/fingerprints Args: @@ -76,7 +76,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=15) -> list: + fingerprints: bool=False, timeout: int=30) -> list: ''' from_mdl: converts MDL file into QSPR descriptors/fingerprints; multiple molecules may be represented in the MDL file From d7feab3cce6d742fd3e32780e61ee2f074f65739 Mon Sep 17 00:00:00 2001 From: tjkessler Date: Fri, 7 Jun 2019 16:07:26 -0400 Subject: [PATCH 3/6] Moved molecule timeout to 8 sec, 30 is rediculous --- padelpy/functions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/padelpy/functions.py b/padelpy/functions.py index d48751e..16fdbf8 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=30) -> OrderedDict: + fingerprints: bool=False, timeout: int=8) -> OrderedDict: ''' from_smiles: converts SMILES string to QSPR descriptors/fingerprints Args: @@ -76,7 +76,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=30) -> list: + fingerprints: bool=False, timeout: int=8) -> list: ''' from_mdl: converts MDL file into QSPR descriptors/fingerprints; multiple molecules may be represented in the MDL file From 623ca3b0e4210c6b02c9104444577c2b6d3f6904 Mon Sep 17 00:00:00 2001 From: tjkessler Date: Sat, 8 Jun 2019 11:20:14 -0400 Subject: [PATCH 4/6] PaDEL exception now decoded from bytes --- padelpy/wrapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/padelpy/wrapper.py b/padelpy/wrapper.py index b1ac9dc..c1e63da 100644 --- a/padelpy/wrapper.py +++ b/padelpy/wrapper.py @@ -121,6 +121,6 @@ def padeldescriptor(maxruntime: int=-1, waitingjobs: int=-1, threads: int=-1, _, err = p.communicate() if err != b'': raise RuntimeError('PaDEL-Descriptor encountered an error: {}'.format( - err + err.decode('utf-8') )) return From dd9101e6ed50ba27d5bc83ae9a2b4807ec240042 Mon Sep 17 00:00:00 2001 From: tjkessler Date: Sat, 8 Jun 2019 11:20:40 -0400 Subject: [PATCH 5/6] 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) From ccd449251e95469f828c484c299df3697a486fb2 Mon Sep 17 00:00:00 2001 From: tjkessler Date: Sat, 8 Jun 2019 11:47:32 -0400 Subject: [PATCH 6/6] Version bump: 0.1.2 -> 0.1.3 --- padelpy/__init__.py | 2 +- padelpy/functions.py | 2 +- padelpy/wrapper.py | 2 +- setup.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/padelpy/__init__.py b/padelpy/__init__.py index eccd7d4..8770971 100644 --- a/padelpy/__init__.py +++ b/padelpy/__init__.py @@ -1,3 +1,3 @@ from padelpy.wrapper import padeldescriptor from padelpy.functions import from_mdl, from_smiles -__version__ = '0.1.2' +__version__ = '0.1.3' diff --git a/padelpy/functions.py b/padelpy/functions.py index 0932b16..3d57c0f 100644 --- a/padelpy/functions.py +++ b/padelpy/functions.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # padelpy/functions.py -# v.0.1.2 +# v.0.1.3 # Developed in 2019 by Travis Kessler # # Contains various functions commonly used with PaDEL-Descriptor diff --git a/padelpy/wrapper.py b/padelpy/wrapper.py index c1e63da..906ba4a 100644 --- a/padelpy/wrapper.py +++ b/padelpy/wrapper.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # padelpy/wrapper.py -# v.0.1.2 +# v.0.1.3 # Developed in 2019 by Travis Kessler # # Contains the `padeldescriptor` function, a wrapper for PaDEL-Descriptor diff --git a/setup.py b/setup.py index a5e6dff..a17deee 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='padelpy', - version='0.1.2', + version='0.1.3', description='A Python wrapper for PaDEL-Descriptor', url='https://github.com/ecrl/padelpy', author='Travis Kessler',