Skip to content

Commit 0be9168

Browse files
author
Oliver Scott
committed
Small update to class pickling.
1 parent dbfef08 commit 0be9168

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

scaffoldgraph/core/scaffold.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ def get_canonical_identifier(self):
218218
return self.hash_func(self.mol)
219219
return self.smiles
220220

221+
def clear_cached_attribuites(self):
222+
"""Clear all cached attributes."""
223+
setattr(self, '_atoms', None)
224+
setattr(self, '_bonds', None)
225+
setattr(self, '_rings', None)
226+
setattr(self, '_ring_systems', None)
227+
221228
@classmethod
222229
def from_smiles(cls, smiles, hash_func=None):
223230
"""Construct a Scaffold object from a SMILES string.
@@ -251,10 +258,7 @@ def __getstate__(self):
251258

252259
def __setstate__(self, state):
253260
self.mol, self.hash_func = state
254-
setattr(self, '_atoms', None)
255-
setattr(self, '_bonds', None)
256-
setattr(self, '_rings', None)
257-
setattr(self, '_ring_systems', None)
261+
self.clear_cached_attribuites()
258262

259263
def __bool__(self):
260264
"""Returns True if the molecule contains at least 1 atom."""

0 commit comments

Comments
 (0)