sapiopycommons 2024.12.4a375__py3-none-any.whl → 2024.12.9a377__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of sapiopycommons might be problematic. Click here for more details.

@@ -10,7 +10,50 @@ indigo.setOption("render-stereo-style", "ext")
10
10
  indigo.setOption("aromaticity-model", "generic")
11
11
  indigo.setOption("render-coloring", True)
12
12
  indigo.setOption("molfile-saving-mode", "3000")
13
- indigo_inchi = IndigoInchi(indigo);
13
+ indigo_inchi = IndigoInchi(indigo)
14
+
15
+
16
+ # Function to process dative bonds in a molecule
17
+ # Returns True if at least one dative bond (_BOND_COORDINATION) was removed
18
+ def remove_dative_bonds_in_mol(molecule: IndigoObject) -> bool:
19
+ """
20
+ Remove all dative bonds in a molecule or a query molecule.
21
+ :param molecule: The molecule to remove.
22
+ :return: Whether there are any dative bonds in the molecule that were removed.
23
+ """
24
+ dative_bond_removed = False # Flag to track if any dative bond was removed
25
+
26
+ bonds_idx_to_remove = []
27
+ for bond in molecule.iterateBonds():
28
+ # Check if the bond is of a dative type (_BOND_COORDINATION = 9)
29
+ if bond.bondOrder() == 9: # _BOND_COORDINATION
30
+ atom1 = bond.source()
31
+ atom2 = bond.destination()
32
+
33
+ # Print bond details for debugging
34
+ print(f"Processing dative bond between atoms {atom1.index()} and {atom2.index()}")
35
+
36
+ # Cache bond information
37
+ # bond.setBondOrder(1)
38
+ bonds_idx_to_remove.append(bond.index())
39
+ dative_bond_removed = True # Set flag to True
40
+
41
+ if not dative_bond_removed:
42
+ return False
43
+
44
+ molecule.removeBonds(bonds_idx_to_remove)
45
+ return True # Return whether any dative bond was removed
46
+
47
+
48
+ def remove_dative_in_reaction(reaction: IndigoObject) -> bool:
49
+ """
50
+ Remove all dative bonds in a reaction or a query reaction, from all reactants and products.
51
+ :param reaction: The reaction to remove dative bonds.
52
+ :return: Whether there are any dative bonds in the reaction that were removed.
53
+ """
54
+ reactant_dative_removed: bool = any(remove_dative_bonds_in_mol(reactant) for reactant in reaction.iterateReactants())
55
+ product_dative_removed: bool = any(remove_dative_bonds_in_mol(product) for product in reaction.iterateProducts())
56
+ return reactant_dative_removed or product_dative_removed
14
57
 
15
58
 
16
59
  def highlight_mol_substructure(query: IndigoObject, sub_match: IndigoObject):
@@ -9,7 +9,8 @@ from rdkit.Chem import rdMolDescriptors
9
9
  from rdkit.Chem.EnumerateStereoisomers import StereoEnumerationOptions, EnumerateStereoisomers
10
10
  from rdkit.Chem.MolStandardize import rdMolStandardize
11
11
  from rdkit.Chem.SaltRemover import SaltRemover
12
- from rdkit.Chem.rdchem import Mol
12
+ from rdkit.Chem.rdChemReactions import ChemicalReaction
13
+ from rdkit.Chem.rdchem import Mol, RWMol, Bond
13
14
 
14
15
  from sapiopycommons.chem.IndigoMolecules import indigo, renderer, indigo_inchi
15
16
 
@@ -22,6 +23,24 @@ tautomer_params.tautomerRemoveIsotopicHs = True
22
23
  enumerator = rdMolStandardize.TautomerEnumerator(tautomer_params)
23
24
 
24
25
 
26
+ def remove_dative_bonds_from_mol(mol: Mol) -> RWMol:
27
+ """
28
+ Create a new copy of RWMol molecule and remove all dative bonds in the molecule.
29
+ :param mol: The original molecule
30
+ :return: The new molecule with dative bonds removed.
31
+ """
32
+ ret: RWMol = Chem.RWMol(mol)
33
+ bonds_to_remove = []
34
+ bond: Bond
35
+ for bond in ret.GetBonds():
36
+ if bond.GetBondType() in [Chem.BondType.DATIVER, Chem.BondType.DATIVE, Chem.BondType.DATIVEL,
37
+ Chem.BondType.DATIVEONE]:
38
+ bonds_to_remove.append((bond.GetBeginAtomIdx(), bond.GetEndAtomIdx()))
39
+ for atom1_idx, atom2_idx in bonds_to_remove:
40
+ ret.RemoveBond(atom1_idx, atom2_idx)
41
+ return ret
42
+
43
+
25
44
  def get_enhanced_stereo_reg_hash(mol: Mol, enhanced_stereo: bool) -> str:
26
45
  """
27
46
  Get the Registration Hash for the molecule by the current registration configuration.
@@ -217,7 +236,9 @@ def mol_to_sapio_substance(mol: Mol, include_stereoisomers=False,
217
236
  # This is number of H-Bond Donor
218
237
  molecule["numHBonds"] = rdMolDescriptors.CalcNumHBD(mol)
219
238
  molecule["molBlock"] = molBlock
220
- rdkit_inchi = MolToInchi(mol)
239
+ # Create a copy of molecule before modifying it for InChI generation.
240
+ inchi_mol: Mol = remove_dative_bonds_from_mol(mol)
241
+ rdkit_inchi = MolToInchi(inchi_mol)
221
242
  # If INCHI is completely invalid, we fail this molecule.
222
243
  if not rdkit_inchi:
223
244
  MolToInchi(mol, treatWarningAsError=True)
@@ -231,13 +252,13 @@ def mol_to_sapio_substance(mol: Mol, include_stereoisomers=False,
231
252
  indigo_mol.aromatize()
232
253
  if enhanced_stereo:
233
254
  # Remove enhanced stereo layer when generating InChI as the stereo hash is generated separately for reg.
234
- mol_copy: Mol = Chem.Mol(mol)
235
- Chem.CanonicalizeEnhancedStereo(mol_copy)
236
- molecule["inchi"] = Chem.MolToInchi(mol_copy)
237
- molecule["inchiKey"] = Chem.MolToInchiKey(mol_copy)
255
+ Chem.CanonicalizeEnhancedStereo(inchi_mol)
256
+ molecule["inchi"] = Chem.MolToInchi(inchi_mol)
257
+ molecule["inchiKey"] = Chem.MolToInchiKey(inchi_mol)
238
258
  else:
239
259
  indigo_inchi.resetOptions()
240
- indigo_inchi_str = indigo_inchi.getInchi(indigo_mol)
260
+ indigo_inchi_mol = indigo.loadMolecule(Chem.MolToMolBlock(inchi_mol, forceV3000=True))
261
+ indigo_inchi_str = indigo_inchi.getInchi(indigo_inchi_mol)
241
262
  molecule["inchi"] = indigo_inchi_str
242
263
  indigo_inchi_key_str = indigo_inchi.getInchiKey(indigo_inchi_str)
243
264
  molecule["inchiKey"] = indigo_inchi_key_str
@@ -245,7 +266,6 @@ def mol_to_sapio_substance(mol: Mol, include_stereoisomers=False,
245
266
  molecule["reg_hash"] = get_enhanced_stereo_reg_hash(mol, enhanced_stereo=enhanced_stereo)
246
267
  molecule["cxsmiles_hash"] = get_cxs_smiles_hash(mol, enhanced_stereo=enhanced_stereo)
247
268
  molecule["has_or_group"] = get_has_or_group(mol, enhanced_stereo=enhanced_stereo)
248
-
249
269
  return molecule
250
270
 
251
271
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sapiopycommons
3
- Version: 2024.12.4a375
3
+ Version: 2024.12.9a377
4
4
  Summary: Official Sapio Python API Utilities Package
5
5
  Project-URL: Homepage, https://github.com/sapiosciences
6
6
  Author-email: Jonathan Steck <jsteck@sapiosciences.com>, Yechen Qiao <yqiao@sapiosciences.com>
@@ -2,8 +2,8 @@ sapiopycommons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  sapiopycommons/callbacks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  sapiopycommons/callbacks/callback_util.py,sha256=nb6cXK8yFq96gtG0Z2NiK-qdNaRh88bavUH-ZoBjh18,67953
4
4
  sapiopycommons/callbacks/field_builder.py,sha256=p2XacN99MuKk3ite8GAqstUMpixqugul2CsC4gB83-o,38620
5
- sapiopycommons/chem/IndigoMolecules.py,sha256=3f-aig3AJkKJhRmhlQ0cI-5G8oeaQk_3foJTDZCvoko,2040
6
- sapiopycommons/chem/Molecules.py,sha256=SQKnqdZnhYj_6HGtEZmE_1DormonRR1-nBAQ__z4gms,11485
5
+ sapiopycommons/chem/IndigoMolecules.py,sha256=slM2y39zZFHc468c366EqR8T-GYJ24UnM9HWAqWFEwQ,3900
6
+ sapiopycommons/chem/Molecules.py,sha256=9B4sbwbvYs50XHRn0TZiu-D1Oa3pKrI9qE5vNW8zv-U,12464
7
7
  sapiopycommons/chem/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  sapiopycommons/customreport/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  sapiopycommons/customreport/column_builder.py,sha256=0RO53e9rKPZ07C--KcepN6_tpRw_FxF3O9vdG0ilKG8,3014
@@ -53,7 +53,7 @@ sapiopycommons/webhook/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
53
53
  sapiopycommons/webhook/webhook_context.py,sha256=D793uLsb1691SalaPnBUk3rOSxn_hYLhdvkaIxjNXss,1909
54
54
  sapiopycommons/webhook/webhook_handlers.py,sha256=MdsVK4bHffkMNmNWl0_qvu-5Lz8-qGu4Ryi7lZO1BZs,18586
55
55
  sapiopycommons/webhook/webservice_handlers.py,sha256=AFM2Va9Fpb2BvlFycIUUOdghtGiEv1Ab5jf44yjHSgU,17218
56
- sapiopycommons-2024.12.4a375.dist-info/METADATA,sha256=K76hHDwZ7i68OAHXdFl42xXA49M50LxMhGimBZV1PaM,3143
57
- sapiopycommons-2024.12.4a375.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
58
- sapiopycommons-2024.12.4a375.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
59
- sapiopycommons-2024.12.4a375.dist-info/RECORD,,
56
+ sapiopycommons-2024.12.9a377.dist-info/METADATA,sha256=R-mI82Ozt9hd8UYMs_9XcFF6aRhT4HqUKJ7Ge88fN7k,3143
57
+ sapiopycommons-2024.12.9a377.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
58
+ sapiopycommons-2024.12.9a377.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
59
+ sapiopycommons-2024.12.9a377.dist-info/RECORD,,