df =pd.read_excel("D:\HBVdata\HBV_P.xlsx") smile_list =df['Smiles'].tolist() mols =[Chem.MolFromSmiles(smile) for smile in smile_list] fingerprints =[Chem.RDKFingerprint(mol) for mol in mols] dg =pd.read_csv("D:\HBVdata\hbvfrag_recap_delete_duplicate.csv") smi_list =dg['mol'].tolist() submols =[Chem.MolFromSmarts(smi) for smi in smi_list] count =0 for submol in submols: for mol in mols: if mol.HasSubstructMatch(submol): count +=1 print(count)改变这段代码让输出的值为每个分子对应的count
时间: 2024-02-28 17:51:54 浏览: 70
操作模式-详解pandas库pd.read_excel操作读取excel文件参数整理与实例
您可以将计数变量 `count` 转换为一个字典,其中键为分子的 SMILES 字符串,值为该分子结构中匹配子结构的数量。代码如下:
```python
df = pd.read_excel("D:\HBVdata\HBV_P.xlsx")
smile_list = df['Smiles'].tolist()
mols = [Chem.MolFromSmiles(smile) for smile in smile_list]
fingerprints = [Chem.RDKFingerprint(mol) for mol in mols]
dg = pd.read_csv("D:\HBVdata\hbvfrag_recap_delete_duplicate.csv")
smi_list = dg['mol'].tolist()
submols = [Chem.MolFromSmarts(smi) for smi in smi_list]
count_dict = {}
for mol in mols:
count = 0
for submol in submols:
if mol.HasSubstructMatch(submol):
count += 1
count_dict[mol.ToSmiles()] = count
print(count_dict)
```
这将输出一个字典,其中键为每个分子的 SMILES 字符串,值为该分子匹配子结构的数量。
阅读全文