Skip to content

Commit

Permalink
Merge pull request #38 from dinabandhu50/master
Browse files Browse the repository at this point in the history
Added "threads" argument to from_smiles function
  • Loading branch information
tjkessler authored Sep 8, 2022
2 parents 903a04e + 537411a commit 20d179a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
```
Expand All @@ -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')
```
Expand All @@ -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')
```
Expand Down
23 changes: 16 additions & 7 deletions padelpy/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -178,7 +182,8 @@ def from_mdl(mdl_file: str,
fingerprints=fingerprints,
timeout=timeout,
maxruntime=maxruntime,
)
threads=threads
)
return rows


Expand All @@ -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
Expand Down Expand Up @@ -216,18 +222,20 @@ 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


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
Expand All @@ -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:
Expand Down

0 comments on commit 20d179a

Please sign in to comment.