KeyedChain
#
- class gufe.tokenization.KeyedChain(keyed_chain)#
Keyed chain representation encoder of a GufeTokenizable.
The keyed chain representation of a GufeTokenizable provides a topologically sorted list of gufe keys and GufeTokenizable keyed dicts that can be used to fully recreate a GufeTokenizable without the need for a populated TOKENIZATION_REGISTRY.
The class wraps around a list of tuples containing the gufe key and the keyed dict form of the GufeTokenizable.
Examples
We can create a keyed chain representation from any GufeTokenizable, such as:
>>> from gufe.tokenization import KeyedChain >>> s = SolventComponent() >>> keyed_chain = KeyedChain.gufe_to_keyed_chain_rep(s) >>> keyed_chain [('SolventComponent-26b4034ad9dbd9f908dfc298ea8d449f', {'smiles': 'O', 'positive_ion': 'Na+', 'negative_ion': 'Cl-', 'ion_concentration': '0.15 molar', 'neutralize': True, '__qualname__': 'SolventComponent', '__module__': 'gufe.components.solventcomponent', ':version:': 1})]
And we can do the reverse operation as well to go from a keyed chain representation back to a GufeTokenizable:
>>> KeyedChain(keyed_chain).to_gufe() SolventComponent(name=O, Na+, Cl-)
Methods
Initialize a KeyedChain from a GufeTokenizable.
Initialize a KeyedChain from a keyed chain representation.
Create a generator that iterates over the gufe keys in the KeyedChain.
Create the keyed chain representation of a GufeTokenizable.
Create a generator that iterates over the keyed dicts in the KeyedChain.
Initialize a GufeTokenizable.
Return the keyed chain representation of this object.
- classmethod from_gufe(gufe_object: GufeTokenizable) Self #
Initialize a KeyedChain from a GufeTokenizable.
- classmethod from_keyed_chain_rep(keyed_chain: list[tuple[str, dict]]) Self #
Initialize a KeyedChain from a keyed chain representation.
- gufe_keys() Generator[str, None, None] #
Create a generator that iterates over the gufe keys in the KeyedChain.
- static gufe_to_keyed_chain_rep(gufe_object: GufeTokenizable) list[tuple[str, dict]] #
Create the keyed chain representation of a GufeTokenizable.
This represents the GufeTokenizable as a list of two-element tuples containing, as their first and second elements, the gufe key and keyed dict form of the GufeTokenizable, respectively, and provides the underlying structure used in the KeyedChain class.
- Parameters:
gufe_object – The GufeTokenizable for which the KeyedChain is generated.
- Returns:
The keyed chain representation of a GufeTokenizable.
- Return type:
key_and_keyed_dicts
- keyed_dicts() Generator[dict, None, None] #
Create a generator that iterates over the keyed dicts in the KeyedChain.
- to_gufe() GufeTokenizable #
Initialize a GufeTokenizable.
- to_keyed_chain_rep() list[tuple[str, dict]] #
Return the keyed chain representation of this object.