Skip to content

Commit

Permalink
Prepare release (#9)
Browse files Browse the repository at this point in the history
* prepare release

* fix conflict version and prepare release
  • Loading branch information
TieuLongPhan authored Oct 28, 2024
1 parent 4aa9601 commit 479a8a1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 155 deletions.
46 changes: 0 additions & 46 deletions Test/SynUtils/test_chemutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
seaborn>=0.13.2
joblib>=1.3.2
synrbl>=0.0.25
103 changes: 0 additions & 103 deletions syntemp/SynUtils/chemutils.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 479a8a1

Please sign in to comment.