@@ -55,7 +55,7 @@ def canonicalize(self: 'MoleculeContainer', *, fix_tautomers=True, keep_kekule=F
5555 h , changed = self .implicify_hydrogens (_fix_stereo = False , logging = True )
5656
5757 if fix_tautomers and (logging or keep_kekule ): # thiele can change tautomeric form
58- hgs = {n : a .implicit_hydrogens for n , a in self ._atoms . items ()}
58+ hgs = {n : a .implicit_hydrogens for n , a in self .atoms ()}
5959 if keep_kekule : # save bond orders
6060 bonds = [(b , b .order ) for _ , _ , b in self .bonds ()]
6161
@@ -66,7 +66,7 @@ def canonicalize(self: 'MoleculeContainer', *, fix_tautomers=True, keep_kekule=F
6666
6767 if keep_kekule and t : # restore
6868 # check ring charge/hydrogen moving
69- if c or fix_tautomers and hgs != self . _hydrogens : # noqa
69+ if c or fix_tautomers and any ( hgs [ n ] != a . implicit_hydrogens for n , a in self . atoms ()):
7070 self .kekule () # we need to do full kekule again
7171 else :
7272 for b , o in bonds : # noqa
@@ -81,12 +81,12 @@ def canonicalize(self: 'MoleculeContainer', *, fix_tautomers=True, keep_kekule=F
8181 s .append ((tuple (changed ), - 1 , 'implicified' ))
8282 if t :
8383 s .append (((), - 1 , 'aromatized' ))
84- if fix_tautomers and (x := tuple (n for n , a in self ._atoms . items () if hgs [n ] != a .implicit_hydrogens )):
84+ if fix_tautomers and (x := tuple (n for n , a in self .atoms () if hgs [n ] != a .implicit_hydrogens )):
8585 s .append ((x , - 1 , 'aromatic tautomer found' ))
8686 if c :
8787 s .append ((tuple (c ), - 1 , 'recharged' ))
8888 if keep_kekule and t :
89- if c or fix_tautomers and any (hgs [n ] != a .implicit_hydrogens for n , a in self ._atoms . items ()):
89+ if c or fix_tautomers and any (hgs [n ] != a .implicit_hydrogens for n , a in self .atoms ()):
9090 s .append (((), - 1 , 'kekulized again' ))
9191 else :
9292 s .append (((), - 1 , 'kekule form restored' ))
@@ -123,7 +123,7 @@ def standardize(self: Union['MoleculeContainer', 'Standardize'], *, logging=Fals
123123 log .extend (l )
124124 fixed .update (f )
125125
126- if b := fixed .intersection (n for n , a in self ._atoms . items () if a .implicit_hydrogens is None ):
126+ if b := fixed .intersection (n for n , a in self .atoms () if a .implicit_hydrogens is None ):
127127 if ignore :
128128 log .append ((tuple (b ), - 1 , 'standardization failed' ))
129129 else :
@@ -271,17 +271,15 @@ def remove_coordinate_bonds(self: 'MoleculeContainer', *, keep_to_terminal=True,
271271 :param keep_to_terminal: Keep any bonds to terminal hydrogens
272272 :return: removed bonds count
273273 """
274- bonds = self ._bonds
275-
276274 ab = [(n , m ) for n , m , b in self .bonds () if b == 8 ]
277275
278276 if keep_to_terminal :
279277 skeleton = self .not_special_connectivity
280- hs = {n for n , a in self ._atoms . items () if a == H and not skeleton [n ]}
278+ hs = {n for n , a in self .atoms () if a == H and not skeleton [n ]}
281279 ab = [(n , m ) for n , m in ab if n not in hs and m not in hs ]
282280
283281 for n , m in ab :
284- del bonds [ n ][ m ], bonds [ m ][ n ]
282+ self . delete_bond ( n , m , _skip_calculation = True )
285283
286284 if ab :
287285 self .flush_cache (keep_sssr = True )
@@ -404,7 +402,7 @@ def check_valence(self: 'MoleculeContainer') -> List[int]:
404402 :return: list of invalid atoms
405403 """
406404 # only invalid atoms have None hydrogens.
407- return [n for n , a in self ._atoms . items () if a .implicit_hydrogens is None ]
405+ return [n for n , a in self .atoms () if a .implicit_hydrogens is None ]
408406
409407 def clean_isotopes (self : 'MoleculeContainer' ) -> bool :
410408 """
0 commit comments