Skip to content

Commit

Permalink
fix rdkit version incompat
Browse files Browse the repository at this point in the history
  • Loading branch information
hadim committed Oct 14, 2022
1 parent 302a8dc commit a5fb1c0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
5 changes: 5 additions & 0 deletions datamol/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from ._version import __version__

from ._version import is_lower_than_current_rdkit_version
from ._version import is_greater_than_current_rdkit_version
from ._version import is_lower_eq_than_current_rdkit_version
from ._version import is_greater_eq_than_current_rdkit_version

from .types import Mol
from .types import BondType
from .types import ChemicalReaction
Expand Down
24 changes: 24 additions & 0 deletions datamol/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
__version__ = "0.7.16"


import rdkit
import packaging.version


CURRENT_RDKIT_VERSION = rdkit.__version__
CURRENT_RDKIT_VERSION_OBJ = packaging.version.parse(CURRENT_RDKIT_VERSION)


def is_lower_than_current_rdkit_version(rdkit_version: str):
return CURRENT_RDKIT_VERSION_OBJ < packaging.version.parse(rdkit_version)


def is_greater_than_current_rdkit_version(rdkit_version: str):
return CURRENT_RDKIT_VERSION_OBJ > packaging.version.parse(rdkit_version)


def is_lower_eq_than_current_rdkit_version(rdkit_version: str):
return CURRENT_RDKIT_VERSION_OBJ <= packaging.version.parse(rdkit_version)


def is_greater_eq_than_current_rdkit_version(rdkit_version: str):
return CURRENT_RDKIT_VERSION_OBJ >= packaging.version.parse(rdkit_version)
13 changes: 8 additions & 5 deletions datamol/reactions/_reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@ def rxn_to_block(
Returns:
Reaction block as string
"""
return rdChemReactions.ReactionToRxnBlock(
reaction=rxn,
separateAgents=separate_agents,
forceV3000=force_V3000,
)

args = {}
if dm.is_lower_than_current_rdkit_version("2022"):
logger.warning("RDKit version prior to 2022.* does not support the `force_V3000` flag.")
else:
args["forceV3000"] = force_V3000

return rdChemReactions.ReactionToRxnBlock(reaction=rxn, separateAgents=separate_agents, **args)


def rxn_to_block_file(
Expand Down

0 comments on commit a5fb1c0

Please sign in to comment.