helmkit 0.5.0__tar.gz → 0.5.2__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: helmkit
3
- Version: 0.5.0
3
+ Version: 0.5.2
4
4
  Summary: Parse HELM strings into RDKit molecules
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.11
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "helmkit"
3
- version = "0.5.0"
3
+ version = "0.5.2"
4
4
  description = "Parse HELM strings into RDKit molecules"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -1,3 +1,4 @@
1
+ import bisect
1
2
  import multiprocessing
2
3
  import re
3
4
  import warnings
@@ -735,7 +736,42 @@ class Molecule:
735
736
 
736
737
  def _sanitize(self) -> None:
737
738
  """Clean up the molecule by removing dummy atoms."""
738
- self.mol = Chem.DeleteSubstructs(self.mol, Chem.MolFromSmarts("[#0]"))
739
+ pattern = Chem.MolFromSmarts("[#0]")
740
+ matches = self.mol.GetSubstructMatches(pattern)
741
+ atoms_to_delete = sorted({idx for match in matches for idx in match})
742
+ self.mol = Chem.DeleteSubstructs(self.mol, pattern)
743
+
744
+ def correction(offset: int, idx: int) -> int:
745
+ return bisect.bisect_left(atoms_to_delete, idx) - bisect.bisect_left(
746
+ atoms_to_delete, offset
747
+ )
748
+
749
+ for i, (m1, a1, m2, a2) in enumerate(self.bondlist):
750
+ offset1 = self.offset[m1]
751
+ offset2 = self.offset[m2]
752
+ self.bondlist[i][1] -= correction(offset1, offset1 + a1)
753
+ self.bondlist[i][3] -= correction(offset2, offset2 + a2)
754
+
755
+ self.offset = [
756
+ offset - sum(d < offset for d in atoms_to_delete) for offset in self.offset
757
+ ]
758
+
759
+ @property
760
+ def bond_indices(self) -> List[int]:
761
+ return [
762
+ self.mol.GetBondBetweenAtoms(
763
+ self.offset[monomer1_idx] + atom1_idx,
764
+ self.offset[monomer2_idx] + atom2_idx,
765
+ ).GetIdx()
766
+ for monomer1_idx, atom1_idx, monomer2_idx, atom2_idx in self.bondlist
767
+ ]
768
+
769
+ @property
770
+ def monomer_indices(self) -> List[int]:
771
+ return [
772
+ bisect.bisect_right(self.offset, i) - 1
773
+ for i in range(self.mol.GetNumAtoms())
774
+ ]
739
775
 
740
776
 
741
777
  def _init_pool(monomer_df: MonomerLibrary):
@@ -196,7 +196,7 @@ wheels = [
196
196
 
197
197
  [[package]]
198
198
  name = "helmkit"
199
- version = "0.5.0"
199
+ version = "0.5.2"
200
200
  source = { editable = "." }
201
201
  dependencies = [
202
202
  { name = "rdkit" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes