Joe*_*Joe 6 python bioinformatics cheminformatics rdkit molecule
是否存在将图(或邻接矩阵)转换为SMILES字符串的方法或程序包?
例如,我知道原子是[6 6 7 6 6 6 6 8] ([C C N C C C C O]),邻接矩阵是
[[ 0., 1., 0., 0., 0., 0., 0., 0.],
[ 1., 0., 2., 0., 0., 0., 0., 1.],
[ 0., 2., 0., 1., 0., 0., 0., 0.],
[ 0., 0., 1., 0., 1., 0., 0., 0.],
[ 0., 0., 0., 1., 0., 1., 0., 0.],
[ 0., 0., 0., 0., 1., 0., 1., 1.],
[ 0., 0., 0., 0., 0., 1., 0., 0.],
[ 0., 1., 0., 0., 0., 1., 0., 0.]]
Run Code Online (Sandbox Code Playgroud)
我需要一些功能来输出'CC1=NCCC(C)O1'。
如果某些功能可以输出相应的"mol"对象,它也可以工作。RDkit软件具有'MolFromSmiles'功能。我不知道是否有类似的东西'MolFromGraphs'。
先感谢您。
据我所知,这是一个简单的解决方案,RDKit中没有内置函数。
def MolFromGraphs(node_list, adjacency_matrix):
# create empty editable mol object
mol = Chem.RWMol()
# add atoms to mol and keep track of index
node_to_idx = {}
for i in range(len(node_list)):
a = Chem.Atom(node_list[i])
molIdx = mol.AddAtom(a)
node_to_idx[i] = molIdx
# add bonds between adjacent atoms
for ix, row in enumerate(adjacency_matrix):
for iy, bond in enumerate(row):
# only traverse half the matrix
if iy <= ix:
continue
# add relevant bond type (there are many more of these)
if bond == 0:
continue
elif bond == 1:
bond_type = Chem.rdchem.BondType.SINGLE
mol.AddBond(node_to_idx[ix], node_to_idx[iy], bond_type)
elif bond == 2:
bond_type = Chem.rdchem.BondType.DOUBLE
mol.AddBond(node_to_idx[ix], node_to_idx[iy], bond_type)
# Convert RWMol to Mol object
mol = mol.GetMol()
return mol
Chem.MolToSmiles(MolFromGraphs(nodes, a))
Run Code Online (Sandbox Code Playgroud)
出:
'CC1=NCCC(C)O1'
此解决方案是https://github.com/dakoner/keras-molecules/blob/dbbb790e74e406faa70b13e8be8104d9e938eba2/convert_rdkit_to_networkx.py的简化版本。
可能还需要设置许多其他原子属性(例如手性或质子化状态)和键类型(三重,导数...)。如果可能的话,最好在图形中明确地跟踪它们(如上面的链接所示),但是如果需要的话,也可以扩展此功能以合并它们。