SELFIES中的函数简介

import selfies as sf

点进入selfies,可以看到inti中有如下方法:

1、"encoder",

>>> import selfies as sf
>>> sf.encoder("C=CF")
'[C][=C][F]'

2、"decoder",

>>> import selfies as sf
>>> sf.decoder('[C][=C][F]')
'C=CF'

3、"get_preset_constraints",

返回给定名称的预设语义约束。


4、"get_semantic_robust_alphabet",

返回在当前语义约束下受 :mod:`selfies` 约束的所有 SELFIES 符号的子集。

5、"get_semantic_constraints",

语义约束,可以查看SELFIES里面存在的语义约束,我觉得就是化合价,SELFIES里面定义了如下语义约束

default_constraints = sf.get_semantic_constraints()
default_constraints

{'H': 1,
 'F': 1,
 'Cl': 1,
 'Br': 1,
 'I': 1,
 'O': 2,
 'O+1': 3,
 'O-1': 1,
 'N': 3,
 'N+1': 4,
 'N-1': 2,
 'C': 4,
 'C+1': 5,
 'C-1': 3,
 'S': 6,
 'S+1': 7,
 'S-1': 5,
 'P': 7,
 'P+1': 8,
 'P-1': 6,
 '?': 8}


6、"set_semantic_constraints",

更新:mod: ' selfie '操作的语义约束。


7、"len_selfies",

>>> import selfies as sf
>>> sf.len_selfies("[C][=C][F].[C]")
5


8、"split_selfies",

将SELFIES有序的拆分为多个独立的token

>>> import selfies as sf
>>> list(sf.split_selfies("[C][=C][F].[C]"))
['[C]', '[=C]', '[F]', '.', '[C]']
"""


9、"get_alphabet_from_selfies",

获得单个/多个SELFIES的词库,有点像去重的"split_selfies"方法 + 可以同时处理多个SELFIES

>>> import selfies as sf
>>> selfies_list = ["[C][F][O]", "[C].[O]", "[F][F]"]
>>> alphabet = sf.get_alphabet_from_selfies(selfies_list)
>>> sorted(list(alphabet))
['[C]', '[F]', '[O]']


10、"selfies_to_encoding",

Converts a SELFIES string into its label (integer)and/or one-hot encoding.

>>> import selfies as sf
>>> sf.selfies_to_encoding("[C][F]", {"[C]": 0, "[F]": 1})
([0, 1], [[1, 0], [0, 1]])


11、"batch_selfies_to_flat_hot",

将 多个SELFIES转为one-hot encodings

>>> import selfies as sf
>>> batch = ["[C]", "[C][C]"]
>>> vocab_stoi = {"[nop]": 0, "[C]": 1}
>>> sf.batch_selfies_to_flat_hot(batch, vocab_stoi, 2)
[[0, 1, 1, 0], [0, 1, 0, 1]]


12、"encoding_to_selfies",

>>> import selfies as sf
>>> one_hot = [[0, 1, 0], [0, 0, 1], [1, 0, 0]]
>>> vocab_itos = {0: "[nop]", 1: "[C]", 2: "[F]"}
>>> sf.encoding_to_selfies(one_hot, vocab_itos, enc_type="one_hot")
'[C][F][nop]'


13、"batch_flat_hot_to_selfies",

>>> import selfies as sf
>>> batch = [[0, 1, 1, 0], [0, 1, 0, 1]]
>>> vocab_itos = {0: "[nop]", 1: "[C]"}
>>> sf.batch_flat_hot_to_selfies(batch, vocab_itos)
['[C][nop]', '[C][C]']


14、"EncoderError",

Exception raised by :func:`selfies.encoder`.


15、"DecoderError"

Exception raised by :func:`selfies.decoder`.

自引用嵌入式字符串(SELFIES):一种鲁棒性100%的分子字符串表现形式 - 知乎

猜你喜欢

转载自blog.csdn.net/weixin_43135178/article/details/131926478