diff --git a/README.md b/README.md index b2b27d2..455e694 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,9 @@ desc_fp = from_smiles('CCC', fingerprints=True) # only calculate fingerprints fingerprints = from_smiles('CCC', fingerprints=True, descriptors=False) +# setting the number of threads, this uses one cpu thread to compute descriptors +descriptors = from_smiles(['CCC', 'CCCC'], threads = 1) + # save descriptors to a CSV file _ = from_smiles('CCC', output_csv='descriptors.csv') ``` @@ -70,6 +73,9 @@ desc_fp = from_mdl('mols.mdl', fingerprints=True) # only calculate fingerprints fingerprints = from_mdl('mols.mdl', fingerprints=True, descriptors=False) +# setting the number of threads, this uses one cpu thread to compute descriptors +desc_fp = from_mdl('mols.mdl', threads=1) + # save descriptors to a CSV file _ = from_mdl('mols.mdl', output_csv='descriptors.csv') ``` @@ -92,6 +98,9 @@ desc_fp = from_sdf('mols.sdf', fingerprints=True) # only calculate fingerprints fingerprints = from_sdf('mols.sdf', fingerprints=True, descriptors=False) +# setting the number of threads, this uses one cpu thread to compute descriptors +desc_fp = from_mdl('mols.sdf', threads=1) + # save descriptors to a CSV file _ = from_sdf('mols.sdf', output_csv='descriptors.csv') ``` diff --git a/padelpy/functions.py b/padelpy/functions.py index d125b59..41372d8 100644 --- a/padelpy/functions.py +++ b/padelpy/functions.py @@ -33,6 +33,7 @@ def from_smiles(smiles, fingerprints: bool = False, timeout: int = 60, maxruntime: int = -1, + threads: int = -1 ) -> OrderedDict: """ from_smiles: converts SMILES string to QSPR descriptors/fingerprints. @@ -44,6 +45,7 @@ def from_smiles(smiles, fingerprints (bool): if `True`, calculates fingerprints timeout (int): maximum time, in seconds, for conversion maxruntime (int): maximum running time per molecule in seconds. default=-1. + threads (int): number of threads to use; defaults to -1 for max available Returns: list or OrderedDict: if multiple SMILES strings provided, returns a @@ -85,8 +87,9 @@ def from_smiles(smiles, d_3d=descriptors, fingerprints=fingerprints, sp_timeout=timeout, + retainorder=True, maxruntime=maxruntime, - retainorder=True + threads=threads ) break except RuntimeError as exception: @@ -149,6 +152,7 @@ def from_mdl(mdl_file: str, fingerprints: bool = False, timeout: int = 60, maxruntime: int = -1, + threads: int = -1 ) -> list: """ from_mdl: converts MDL file into QSPR descriptors/fingerprints; multiple molecules may be represented in the MDL file @@ -178,7 +182,8 @@ def from_mdl(mdl_file: str, fingerprints=fingerprints, timeout=timeout, maxruntime=maxruntime, - ) + threads=threads + ) return rows @@ -188,7 +193,8 @@ def from_sdf(sdf_file: str, fingerprints: bool = False, timeout: int = 60, maxruntime: int = -1, - ) -> list: + threads: int = -1 + ) -> list: """ Converts sdf file into QSPR descriptors/fingerprints. Multiple molecules may be represented in the sdf file @@ -216,9 +222,10 @@ def from_sdf(sdf_file: str, output_csv=output_csv, descriptors=descriptors, fingerprints=fingerprints, - sp_timeout=timeout, + timeout=timeout, maxruntime=maxruntime, - ) + threads=threads + ) return rows @@ -226,8 +233,9 @@ def _from_mdl_lower(mol_file: str, output_csv: str = None, descriptors: bool = True, fingerprints: bool = False, - sp_timeout: int = 60, + timeout: int = 60, maxruntime: int = -1, + threads: int = -1 ) -> list: # unit conversion for maximum running time per molecule # seconds -> milliseconds @@ -253,7 +261,8 @@ def _from_mdl_lower(mol_file: str, d_2d=descriptors, d_3d=descriptors, fingerprints=fingerprints, - sp_timeout=sp_timeout, + sp_timeout=timeout, + threads=threads ) break except RuntimeError as exception: