Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "threads" argument to from_smiles function #38

Merged
merged 8 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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