stk.MoleculeJsonizer
- class stk.MoleculeJsonizer(key_makers=(InchiKey(),))[source]
Bases:
object
Abstract base class for creating JSONs of molecules.
See also
Notes
You might notice that the public methods of this abstract base class are implemented. These are just default implementations, which can be safely ignored or overridden, when implementing subclasses. However, the default implementation can be used directly, if it suits your needs.
Examples
Converting a Molecule to JSON
You want to create a JSON representation of a molecule
import stk jsonizer = stk.MoleculeJsonizer() json = jsonizer.to_json(stk.BuildingBlock('NCCN'))
Adding Additional Molecular Keys
Apart from atoms, bonds and the position matrix, the JSON representation holds additional fields, one for each
MoleculeKeyMaker
provided to the initializerimport stk jsonizer = stk.MoleculeJsonizer( key_makers=( stk.Inchi(), stk.InchiKey(), ), ) json = jsonizer.to_json(stk.BuildingBlock('NCCN'))
In this case,
json
will look something like{ # A tuple of JSON atom representations. 'atoms': (...), # A tuple of JSON bond representations. 'bonds': (...), 'InChI': 'The InChI of the molecule', 'InChIKey': 'The InChIKey of the molecule', }
For every
MoleculeKeyMaker
provided to key_makers, a new key will be added to the JSON representation, with its name given byMoleculeKeyMaker.get_key_name()
and the value given byMoleculeKeyMaker.get_key()
.Initialize a
MoleculeJsonizer
instance.- Parameters:
key_makers (MoleculeKeyMaker | Iterable[MoleculeKeyMaker]) – Used to make the keys of molecules, which should be included in their JSON representations. Keys allow molecular data to reference itself when split across multiple JSONs.
Methods
Return a JSON representation of molecule.