From 479a8a1a08ba9edd8c26ab87a5be77b0fd0c7c98 Mon Sep 17 00:00:00 2001 From: Tieu Long Phan <125431507+TieuLongPhan@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:21:58 +0100 Subject: [PATCH] Prepare release (#9) * prepare release * fix conflict version and prepare release --- Test/SynUtils/test_chemutils.py | 46 -------------- pyproject.toml | 4 +- requirements.txt | 8 +-- syntemp/SynUtils/chemutils.py | 103 -------------------------------- 4 files changed, 6 insertions(+), 155 deletions(-) diff --git a/Test/SynUtils/test_chemutils.py b/Test/SynUtils/test_chemutils.py index b91e4e8..9106667 100644 --- a/Test/SynUtils/test_chemutils.py +++ b/Test/SynUtils/test_chemutils.py @@ -2,13 +2,6 @@ from rdkit import Chem from pathlib import Path from syntemp.SynUtils.chemutils import ( - normalize_molecule, - canonicalize_tautomer, - salts_remover, - reionize_charges, - uncharge_molecule, - assign_stereochemistry, - fragments_remover, remove_hydrogens_and_sanitize, ) @@ -21,45 +14,6 @@ def setUp(self): self.caffeine_smiles = "CN1C=NC2=C1C(=O)N(C(=O)N2C)C" self.mol = Chem.MolFromSmiles(self.caffeine_smiles) - def test_normalize_molecule(self): - normalized_mol = normalize_molecule(self.mol) - self.assertIsInstance(normalized_mol, Chem.Mol) - - def test_canonicalize_tautomer(self): - canonical_tautomer = canonicalize_tautomer(self.mol) - self.assertIsInstance(canonical_tautomer, Chem.Mol) - - def test_salts_remover(self): - # Using a molecule with a known salt - mol_with_salt = Chem.MolFromSmiles("CC(=O)O.[Na+]") - salt_removed_mol = salts_remover(mol_with_salt) - self.assertNotEqual( - Chem.MolToSmiles(salt_removed_mol), Chem.MolToSmiles(mol_with_salt) - ) - - def test_reionize_charges(self): - reionized_mol = reionize_charges(self.mol) - self.assertIsInstance(reionized_mol, Chem.Mol) - - def test_uncharge_molecule(self): - charged_mol = Chem.AddHs(Chem.MolFromSmiles("[NH4+].[Cl-]")) - uncharged_mol = uncharge_molecule(charged_mol) - self.assertEqual(Chem.rdmolops.GetFormalCharge(uncharged_mol), 0) - - def test_assign_stereochemistry(self): - mol_with_stereo = Chem.MolFromSmiles("C[C@H](O)[C@@H](O)C") - assign_stereochemistry(mol_with_stereo) - self.assertEqual( - len(Chem.FindMolChiralCenters(mol_with_stereo, includeUnassigned=True)), 2 - ) - - def test_fragments_remover(self): - mol_with_fragments = Chem.MolFromSmiles("CCO.OCC") - largest_fragment = fragments_remover(mol_with_fragments) - self.assertEqual( - largest_fragment.GetNumAtoms(), 3 - ) # Expecting the ethyl alcohol fragment - def test_remove_hydrogens_and_sanitize(self): mol_with_h = Chem.AddHs(self.mol) cleaned_mol = remove_hydrogens_and_sanitize(mol_with_h) diff --git a/pyproject.toml b/pyproject.toml index 74107ab..8b23634 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,11 +27,11 @@ dependencies = [ "chytorch==1.60", "chytorch-rxnmap==1.4", "torchdata==0.7.1", - "rdkit>=2023.9.5", + "rdkit>=2024.3.3", "networkx>=3.3", "seaborn>=0.13.2", "joblib>=1.3.2", - "synrbl>=0.0.24", + "synrbl>=0.0.25", ] [project.urls] diff --git a/requirements.txt b/requirements.txt index 6cb1475..0872d2c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,8 +8,8 @@ chython==1.75 chytorch==1.60 chytorch-rxnmap==1.4 torchdata==0.7.1 -rdkit>=2023.9.5 +rdkit>=2024.3.3 networkx>=3.3 -seaborn==0.13.2 -joblib==1.3.2 -synrbl>=0.0.24 \ No newline at end of file +seaborn>=0.13.2 +joblib>=1.3.2 +synrbl>=0.0.25 \ No newline at end of file diff --git a/syntemp/SynUtils/chemutils.py b/syntemp/SynUtils/chemutils.py index ea05efc..2423ae7 100644 --- a/syntemp/SynUtils/chemutils.py +++ b/syntemp/SynUtils/chemutils.py @@ -1,7 +1,5 @@ import re from rdkit import Chem -from rdkit.Chem.MolStandardize import normalize, tautomer, charge -from rdkit.Chem.SaltRemover import SaltRemover from rdkit.Chem import rdmolops from rdkit.Chem.MolStandardize import rdMolStandardize from rdkit.Chem.rdMolDescriptors import CalcMolFormula @@ -10,107 +8,6 @@ from itertools import combinations_with_replacement -def normalize_molecule(mol: Chem.Mol) -> Chem.Mol: - """ - Normalize a molecule using RDKit's Normalizer. - - Args: - mol (Chem.Mol): RDKit Mol object to be normalized. - - Returns: - Chem.Mol: Normalized RDKit Mol object. - """ - return normalize.Normalizer().normalize(mol) - - -def canonicalize_tautomer(mol: Chem.Mol) -> Chem.Mol: - """ - Canonicalize the tautomer of a molecule using RDKit's TautomerCanonicalizer. - - Args: - - mol (Chem.Mol): RDKit Mol object. - - Returns: - - Chem.Mol: Mol object with canonicalized tautomer. - """ - return tautomer.TautomerCanonicalizer().canonicalize(mol) - - -def salts_remover(mol: Chem.Mol) -> Chem.Mol: - """ - Remove salt fragments from a molecule using RDKit's SaltRemover. - - Args: - - mol (Chem.Mol): RDKit Mol object. - - Returns: - - Chem.Mol: Mol object with salts removed. - """ - remover = SaltRemover() - return remover.StripMol(mol) - - -def reionize_charges(mol: Chem.Mol) -> Chem.Mol: - """ - Adjust molecule to its most likely ionic state using RDKit's Reionizer. - - Args: - - mol: RDKit Mol object. - - Returns: - - Mol object with reionized charges. - """ - return charge.Reionizer().reionize(mol) - - -def uncharge_molecule(mol: Chem.Mol) -> Chem.Mol: - """ - Neutralize a molecule by removing counter-ions using RDKit's Uncharger. - - Args: - mol: RDKit Mol object. - - Returns: - Neutralized Mol object. - """ - uncharger = rdMolStandardize.Uncharger() - return uncharger.uncharge(mol) - - -def assign_stereochemistry( - mol: Chem.Mol, cleanIt: bool = True, force: bool = True -) -> None: - """ - Assigns stereochemistry to a molecule using RDKit's AssignStereochemistry. - - Args: - mol: RDKit Mol object. - cleanIt: Flag indicating whether to clean the molecule. - Default is True. - force: Flag indicating - whether to force stereochemistry assignment. - Default is True. - - Returns: - None - """ - Chem.AssignStereochemistry(mol, cleanIt=cleanIt, force=force) - - -def fragments_remover(mol: Chem.Mol) -> Chem.Mol: - """ - Remove small fragments from a molecule, keeping only the largest one. - - Args: - mol (Chem.Mol): RDKit Mol object. - - Returns: - Chem.Mol: Mol object with small fragments removed. - """ - frags = Chem.GetMolFrags(mol, asMols=True, sanitizeFrags=True) - return max(frags, default=None, key=lambda m: m.GetNumAtoms()) - - def remove_hydrogens_and_sanitize(mol: Chem.Mol) -> Chem.Mol: """ Remove explicit hydrogens and sanitize a molecule.