Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ repos:
rev: "0.6.0"
hooks:
- id: nbstripout
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.15.0 # (or whichever version you want)
hooks:
- id: mypy
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []
exclude_patterns: list = []


# -- Options for HTML output -------------------------------------------------
Expand Down
42 changes: 21 additions & 21 deletions exmol/exmol.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def _load_smarts(path, rank_cutoff=500):
return smarts


def name_morgan_bit(m: Any, bitInfo: Dict[Any, Any], key: int) -> str:
def name_morgan_bit(m: Any, bitInfo: Dict[Any, Any], key: int) -> Optional[str]:
"""Get the name of a Morgan bit using a SMARTS dictionary

:param m: RDKit molecule
Expand Down Expand Up @@ -273,9 +273,9 @@ def get_functional_groups(
if isinstance(mol, str):
mol = smi2mol(mol)
if mol is None:
return []
return set([])

matched_atoms = set()
matched_atoms: set = set()
result = set()

sorted_smarts = sorted(_SMARTS.items(), key=lambda x: x[1][1])
Expand Down Expand Up @@ -310,7 +310,7 @@ def clear_descriptors(
def add_descriptors(
examples: List[Example],
descriptor_type: str = "MACCS",
mols: List[Any] = None,
mols: Optional[List[Any]] = None,
) -> List[Example]:
"""Add descriptors to passed examples

Expand Down Expand Up @@ -415,7 +415,7 @@ def get_basic_alphabet() -> Set[str]:
# is always a plain uncharged element.


def _alphabet_to_elements(alphabet: List[str]) -> Set[str]:
def _alphabet_to_elements(alphabet: Union[List[str], Set[str]]) -> Set[str]:
"""Converts SELFIES alphabet to element symbols"""
symbols = []
for s in alphabet:
Expand All @@ -426,8 +426,8 @@ def _alphabet_to_elements(alphabet: List[str]) -> Set[str]:


def _check_alphabet_consistency(
smiles: str, alphabet_symbols: Set[str], check=False
) -> True:
smiles: str, alphabet_symbols: Union[Set[str], List[str]], check=False
) -> bool:
"""Checks if SMILES only contains tokens from alphabet"""

alphabet_symbols = _alphabet_to_elements(set(alphabet_symbols))
Expand All @@ -448,7 +448,7 @@ def run_stoned(
num_samples: int = 2000,
max_mutations: int = 2,
min_mutations: int = 1,
alphabet: Union[List[str], Set[str]] = None,
alphabet: Optional[Union[List[str], Set[str]]] = None,
return_selfies: bool = False,
_pbar: Any = None,
) -> Union[Tuple[List[str], List[float]], Tuple[List[str], List[str], List[float]]]:
Expand Down Expand Up @@ -491,11 +491,11 @@ def run_stoned(
# Mutate the SELFIES:
if _pbar:
_pbar.set_description(f"🥌STONED🥌 Mutations: {num_mutations}")
selfies_mut = stoned.get_mutated_SELFIES(
selfies_mut: list | tuple = stoned.get_mutated_SELFIES(
selfies_ls.copy(), num_mutations=num_mutations, alphabet=alphabet
)
# Convert back to SMILES:
smiles_back = [sf.decoder(x) for x in selfies_mut]
smiles_back: list | tuple = [sf.decoder(x) for x in selfies_mut]
# check if smiles are consistent with alphabet and downslect
selfies_mut, smiles_back = zip(
*[
Expand Down Expand Up @@ -664,10 +664,10 @@ def sample_space(
],
batched: bool = True,
preset: str = "medium",
data: List[Union[str, rdchem.Mol]] = None,
method_kwargs: Dict = None,
num_samples: int = None,
stoned_kwargs: Dict = None,
data: Optional[List[Union[str, rdchem.Mol]]] = None,
method_kwargs: Optional[Dict] = None,
num_samples: Optional[int] = None,
stoned_kwargs: Optional[Dict] = None,
quiet: bool = False,
use_selfies: bool = False,
sanitize_smiles: bool = True,
Expand Down Expand Up @@ -1017,7 +1017,7 @@ def is_low(e):
def plot_space(
examples: List[Example],
exps: List[Example],
figure_kwargs: Dict = None,
figure_kwargs: Optional[Dict] = None,
mol_size: Tuple[int, int] = (200, 200),
highlight_clusters: bool = False,
mol_fontsize: int = 8,
Expand Down Expand Up @@ -1111,11 +1111,11 @@ def normalizer(x):
def plot_cf(
exps: List[Example],
fig: Any = None,
figure_kwargs: Dict = None,
figure_kwargs: Optional[Dict] = None,
mol_size: Tuple[int, int] = (200, 200),
mol_fontsize: int = 10,
nrows: int = None,
ncols: int = None,
nrows: Optional[int] = None,
ncols: Optional[int] = None,
):
"""Draw the given set of Examples in a grid

Expand Down Expand Up @@ -1159,10 +1159,10 @@ def plot_cf(

def plot_descriptors(
examples: List[Example],
output_file: str = None,
output_file: Optional[str] = None,
fig: Any = None,
figure_kwargs: Dict = None,
title: str = None,
figure_kwargs: Optional[Dict] = None,
title: Optional[str] = None,
return_svg: bool = False,
):
"""Plot descriptor attributions from given set of Examples.
Expand Down
3 changes: 2 additions & 1 deletion exmol/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ def similarity_map_using_tstats(
if return_svg:
return text
_imgtext2mpl(text)
return None


def plot_space_by_fit(
Expand All @@ -300,7 +301,7 @@ def plot_space_by_fit(
mol_fontsize: int = 8,
offset: int = 0,
ax: Any = None,
figure_kwargs: Dict = None,
figure_kwargs: Optional[Dict] = None,
cartoon: bool = False,
rasterized: bool = False,
):
Expand Down
Empty file added exmol/py.typed
Empty file.
4 changes: 2 additions & 2 deletions paper1_CFs/RF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "exmol312",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "exmol312"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

setup(
name="exmol",
version=__version__,
version=__version__, # type: ignore
description="Counterfactual generation with STONED SELFIES",
author="Aditi Seshadri, Geemi Wellawatte, Andrew White",
Comment on lines 13 to 14
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May also be time to update description?

author_email="andrew.white@rochester.edu",
url="https://ur-whitelab.github.io/exmol/",
license="MIT",
packages=["exmol", "exmol.stoned"],
package_data={"exmol": ["lime_data/*.txt", "lime_data/*.pb"]},
package_data={"exmol": ["lime_data/*.txt", "lime_data/*.pb", "exmol/py.typed"]},
install_requires=[
"selfies >= 2.0.0",
"numpy",
Expand Down
Loading