besmarts.codecs.codec_native module

besmarts.codecs.codec_native

SMARTS and SMILES parsing using native BESMARTS formats

class besmarts.codecs.codec_native.graph_codec_native(primitive_codecs: Dict[primitive_key, primitive_codec], atom_primitives: Sequence[primitive_key], bond_primitives: Sequence[primitive_key])[source]

Bases: graph_codec

The native graph codec implements the SMARTS and SMILES encoders which can transform SMARTS primitives in binary form to string form.

To use this interface, supply a dictionary of primitive codecs that know how to encode/decode the primitives, and then supply the initial list of primitives that will be used when encoding SMARTS. Manipulating the lists controls which primitives are active.

smarts_encode(g: graph) str[source]

Transform a graph into a SMARTS string.

Parameters:

g (graph) – The graph to encode

Returns:

The SMARTS representation of the graph

Return type:

str

smiles_encode(g: graph) str[source]

Transform a graph into a SMILES string. The graph must be a fragment, i.e. all primitives have exactly one value set (one-hot encoding).

Parameters:

g (graph) – The graph to encode

Returns:

The SMILES representation of the graph

Return type:

str

besmarts.codecs.codec_native.graph_codec_native_encode(graphs)[source]
besmarts.codecs.codec_native.graph_codec_native_load(fname) Sequence[source]
besmarts.codecs.codec_native.graph_codec_native_read(f) Sequence[source]
besmarts.codecs.codec_native.graph_codec_native_save(fname, graphs)[source]
besmarts.codecs.codec_native.graph_codec_native_write(f, graphs)[source]
besmarts.codecs.codec_native.graph_load(lines, dtype=<class 'besmarts.core.arrays.bitvec'>)[source]
besmarts.codecs.codec_native.graph_save(g: graph, order=None)[source]
besmarts.codecs.codec_native.primitive_codecs_get() Dict[primitive_key, primitive_codec][source]

Return the primitives that the BESMARTS native codec is aware of.

Returns:

  • Dict[codecs.primitive_key, codecs.primitive_codec]

  • The map of primitive keys (e.g. “element”) and the respective codec that

  • can encode/decode into binary form

besmarts.codecs.codec_native.primitive_codecs_get_atom() Dict[primitive_key, primitive_codec][source]

Return the node (atom) primitives that the BESMARTS native codec is aware of.

besmarts.codecs.codec_native.primitive_codecs_get_bond() Dict[primitive_key, primitive_codec][source]

Return the edge (bond) primitives that the BESMARTS native codec is aware of.

besmarts.codecs.codec_native.primitive_load(line, primitive_codecs)[source]