## PubChem網(wǎng)站查詢
### 訪問PubChem網(wǎng)站
打開瀏覽器,進(jìn)入 PubChem 的官方網(wǎng)站(https://pubchem.ncbi.nlm.nih.gov/)。
### 搜索化合物
在搜索框中輸入想要查詢的化合物的名稱、CAS 號(hào)或其他標(biāo)識(shí)符。例如,如果你想查詢乙醇,可以直接在搜索框中輸入“ethanol”。
### 查看化合物詳情頁(yè)面
點(diǎn)擊搜索結(jié)果中你所關(guān)注的化合物,進(jìn)入該化合物的詳情頁(yè)面。
### 找到SMILES信息
- 在化合物的詳情頁(yè)面中,通??梢栽凇癗ames and Identifiers”等類似的欄目下找到該化合物的 SMILES 信息(對(duì)于乙醇,其 Canonical SMILES 為 `CCO`)。
## PubChem網(wǎng)站API查詢
### 示例程序
```python
import requests
def get_smiles_from_pubchem(compound_name):
? ? """
? ? 根據(jù)化合物名稱從PubChem數(shù)據(jù)庫(kù)獲取其SMILES表示。
? ? 參數(shù):
? ? compound_name (str): 化合物的名稱。
? ? 返回:
? ? str: 化合物的SMILES表示,如果請(qǐng)求成功并找到化合物則返回SMILES,否則返回None。
? ? """
? ? # 構(gòu)建請(qǐng)求URL,將化合物名稱插入到URL中以查詢相應(yīng)的SMILES
? ? url = f"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/{compound_name}/property/CanonicalSMILES/TXT"
? ? # 發(fā)起GET請(qǐng)求到PubChem數(shù)據(jù)庫(kù)
? ? response = requests.get(url)
? ? # 檢查HTTP響應(yīng)狀態(tài)碼,200表示請(qǐng)求成功
? ? if response.status_code == 200:
? ? ? ? # 從響應(yīng)中提取SMILES信息,并去除可能的前后空格
? ? ? ? smiles = response.text.strip()
? ? ? ? # 返回化合物的SMILES表示
? ? ? ? return smiles
? ? else:
? ? ? ? # 如果請(qǐng)求未成功,打印錯(cuò)誤信息
? ? ? ? print(f"Error: {response.status_code}")
? ? ? ? # 返回None表示未能獲取SMILES信息
? ? ? ? return None
# 示例:查詢乙醇的 SMILES
compound_name = "ethanol"
# 調(diào)用函數(shù)獲取乙醇的SMILES表示
smiles = get_smiles_from_pubchem(compound_name)
# 檢查是否成功獲取SMILES,如果是,則打印出來
if smiles:
? ? print(f"The SMILES of {compound_name} is: {smiles}")
```
https://gitee.com/biox-lab/biclass.biox/blob/master/%E4%BF%AE%E4%B8%9A/Chemistry/Chemoinformatics/Chem-Data/Database/PubChem/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8PubChem%E6%9F%A5%E8%AF%A2%E5%8C%96%E5%90%88%E7%89%A9%E7%9A%84SMILES.md
#PubChem #SMILES