diff --git a/rxnfp/models.py b/rxnfp/models.py index d79c69e..cd1ac10 100644 --- a/rxnfp/models.py +++ b/rxnfp/models.py @@ -12,7 +12,6 @@ import logging import random import warnings -import pkg_resources import sklearn from transformers import ( @@ -562,4 +561,4 @@ def __init__( continue elif 'pooler' in name: continue - param.requires_grad = False \ No newline at end of file + param.requires_grad = False diff --git a/rxnfp/tokenization.py b/rxnfp/tokenization.py index 986c659..c160307 100644 --- a/rxnfp/tokenization.py +++ b/rxnfp/tokenization.py @@ -10,8 +10,7 @@ import re import numpy as np from rdkit import Chem - -import pkg_resources +from importlib.resources import files from typing import List @@ -21,11 +20,8 @@ SMI_REGEX_PATTERN = r"(\%\([0-9]{3}\)|\[[^\]]+]|Br?|Cl?|N|O|S|P|F|I|b|c|n|o|s|p|\||\(|\)|\.|=|#|-|\+|\\|\/|:|~|@|\?|>>?|\*|\$|\%[0-9]{2}|[0-9])" def get_default_tokenizer(): - default_vocab_path = ( - pkg_resources.resource_filename( - "rxnfp", - "models/transformers/bert_ft_10k_25s/vocab.txt" - ) + default_vocab_path = str( + files("rxnfp") / "models/transformers/bert_ft_10k_25s/vocab.txt" ) return SmilesTokenizer(default_vocab_path, do_lower_case=False) @@ -150,4 +146,4 @@ def process_reaction(rxn): joined_precursors = ".".join(sorted(precursors)) joined_products = ".".join(sorted(products)) - return f"{joined_precursors}>>{joined_products}" \ No newline at end of file + return f"{joined_precursors}>>{joined_products}" diff --git a/rxnfp/transformer_fingerprints.py b/rxnfp/transformer_fingerprints.py index 83fbee6..fdcbe65 100644 --- a/rxnfp/transformer_fingerprints.py +++ b/rxnfp/transformer_fingerprints.py @@ -5,8 +5,8 @@ # Cell import torch -import pkg_resources import numpy as np +from importlib.resources import files from typing import List from tqdm import tqdm from itertools import islice @@ -109,16 +109,10 @@ def convert_batch(self, rxn_smiles_list: List[str]): def get_default_model_and_tokenizer(model='bert_ft', force_no_cuda=False): - model_path = pkg_resources.resource_filename( - "rxnfp", - f"models/transformers/{model}" - ) + model_path = str(files("rxnfp") / f"models/transformers/{model}") - tokenizer_vocab_path = ( - pkg_resources.resource_filename( - "rxnfp", - f"models/transformers/{model}/vocab.txt" - ) + tokenizer_vocab_path = str( + files("rxnfp") / f"models/transformers/{model}/vocab.txt" ) device = torch.device("cuda" if (torch.cuda.is_available() and not force_no_cuda) else "cpu") @@ -142,4 +136,4 @@ def generate_fingerprints(rxns: List[str], fingerprint_generator:FingerprintGene fps_batch = fingerprint_generator.convert_batch(batch) fps += fps_batch - return np.array(fps) \ No newline at end of file + return np.array(fps) diff --git a/settings.ini b/settings.ini index c3b5b1e..3fddfc3 100644 --- a/settings.ini +++ b/settings.ini @@ -9,13 +9,13 @@ author_email = phs@zurich.ibm.com copyright = RXN for Chemistry team / University of Bern branch = master version = 0.1.0 -min_python = 3.6 +min_python = 3.9 audience = Developers language = English custom_sidebar = True license = mit status = 2 -requirements = transformers>=4.5.0 torch>=1.6 scipy==1.4.1 scikit-learn==0.23.1 matplotlib==3.2.2 faerun==0.3.20 +requirements = transformers torch scipy scikit-learn matplotlib faerun nbs_path = nbs doc_path = docs doc_host = https://rxn4chemistry.github.io diff --git a/setup.py b/setup.py index 6975698..b031a77 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ -from pkg_resources import parse_version +from packaging.version import Version from configparser import ConfigParser import setuptools -assert parse_version(setuptools.__version__)>=parse_version('36.2') +assert Version(setuptools.__version__) >= Version("36.2") # note: all settings are in settings.ini; edit there, not here config = ConfigParser(delimiters=['=']) @@ -19,7 +19,7 @@ } statuses = [ '1 - Planning', '2 - Pre-Alpha', '3 - Alpha', '4 - Beta', '5 - Production/Stable', '6 - Mature', '7 - Inactive' ] -py_versions = '2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8'.split() +py_versions = "2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12".split() requirements = cfg.get('requirements','').split() lic = licenses[cfg['license']] @@ -45,4 +45,3 @@ zip_safe = False, entry_points = { 'console_scripts': cfg.get('console_scripts','').split() }, **setup_cfg) -