Diff of /docs/source/selfies.rst [000000] .. [1aa732]

Switch to unified view

a b/docs/source/selfies.rst
1
API Reference
2
==================
3
4
.. currentmodule:: selfies
5
6
Core Functions
7
------------------------
8
.. autofunction:: encoder
9
.. autofunction:: decoder
10
11
Customization Functions
12
------------------------
13
14
The SELFIES grammar is derived dynamically from a set of semantic constraints,
15
which assign bonding capacities to various atoms.
16
By default, :mod:`selfies` operates under the following constraints:
17
18
.. table::
19
    :align: center
20
21
    +-----------+------------------------------+
22
    | Max Bonds | Atom(s)                      |
23
    +===========+==============================+
24
    | 1         | F, Cl, Br, I                 |
25
    +-----------+------------------------------+
26
    | 2         | O                            |
27
    +-----------+------------------------------+
28
    | 3         | B, N                         |
29
    +-----------+------------------------------+
30
    | 4         | C                            |
31
    +-----------+------------------------------+
32
    | 5         | P                            |
33
    +-----------+------------------------------+
34
    | 6         | S                            |
35
    +-----------+------------------------------+
36
    | 8         | All other atoms              |
37
    +-----------+------------------------------+
38
39
The +1 and -1 charged versions of O, N, C, S, and P are also constrained,
40
where a +1 increases the bonding capacity of the neutral atom by 1,
41
and a -1 decreases the bonding capacity of the neutral atom by 1.
42
For example, N+1 has a bonding capacity of :math:`3 + 1 = 4`,
43
and N-1 has a bonding capacity of :math:`3 - 1 = 2`. The charged versions
44
B+1 and B-1 are constrained to a capacity of 2 and 4 bonds, respectively.
45
46
However, the default constraints are inadequate for SMILES strings that violate them. For
47
example, nitrobenzene ``O=N(=O)C1=CC=CC=C1`` has a nitrogen with 6 bonds and
48
the chlorate anion ``O=Cl(=O)[O-]`` has a chlorine with 5 bonds - these
49
SMILES strings *cannot* be represented by SELFIES strings under the default constraints.
50
Additionally, users may want to specify their own custom constraints. Thus, we
51
provide the following methods for configuring the semantic constraints
52
of :mod:`selfies`.
53
54
.. warning::
55
56
    SELFIES strings may be translated differently under different semantic constraints.
57
    Therefore, if custom semantic constraints are used, it is recommended to report
58
    them for reproducibility reasons.
59
60
.. autofunction:: get_preset_constraints
61
.. autofunction:: get_semantic_constraints
62
.. autofunction:: set_semantic_constraints
63
64
65
Utility Functions
66
------------------------
67
.. autofunction:: len_selfies
68
.. autofunction:: split_selfies
69
.. autofunction:: get_alphabet_from_selfies
70
.. autofunction:: get_semantic_robust_alphabet
71
.. autofunction:: selfies_to_encoding
72
.. autofunction:: encoding_to_selfies
73
.. autofunction:: batch_selfies_to_flat_hot
74
.. autofunction:: batch_flat_hot_to_selfies
75
76
77
Exceptions
78
------------------------
79
.. autoexception:: EncoderError
80
.. autoexception:: DecoderError