저는 화학을 좋아하는데요 특히 분자 구조, 오비탈, 루이스 구조식 등 분자에 관한 것을 좋아합니다.
친구가 재밌는 것을 보내줬는데 파이썬 라이브러리에 분자 구조를 그릴 수 있는 것이 있다고 해서 바로 해봤습니다.
Netwokx를 활용하여 분자구조 그리기 (tistory.com)
Netwokx를 활용하여 분자구조 그리기
파이썬, 그래프 라이브러리를 활용하여 네트워크 그리기 기본 이해 NetworkX는 그래프와 네트워크를 연구하기위한 Python 라이브러리로서, BSD-new 라이센스에 따라 공개 된 무료 소프트웨어이다. 이
joyhong.tistory.com
이분의 블로그를 참고해서 찾아봤습니다.
코랩에서 코드를 돌려봤습니다.
rdkit 모듈이 필요하기 때문에 설치를 해줍니다.
!pip install rdkit-pypi -qqq
라이브러리를 불러오고
from rdkit import Chem
from rdkit.Chem import Draw
from rdkit.Chem.Draw import MolsToImage
from rdkit.Chem.Draw import MolToFile
import networkx as nx
import matplotlib.pyplot as plt
분자구조를 그리는 코드를 넣어주면 됩니다.
smiles = input()
mol = Chem.MolFromSmiles(smiles)
MolsToImage(mols=[mol], subImgSize=(600,600))
이렇게 그리기 위해서는 분자식의 smiles 코드를 가져와야 합니다.
smiles 코드는 이곳에서 가져올 수 있습니다.
https://pubchem.ncbi.nlm.nih.gov/
PubChem
PubChem is the world's largest collection of freely accessible chemical information. Search chemicals by name, molecular formula, structure, and other identifiers. Find chemical and physical properties, biological activities, safety and toxicity informatio
pubchem.ncbi.nlm.nih.gov
저는 일단 시험기간에 많이 먹었던 caffeine을 그려보았습니다.
caffeine: CN1C=NC2=C1C(=O)N(C(=O)N2C)C
오 신기하다
원소별로 색이 달라요.
Capsaicin: CC(C)/C=C/CCCCC(=O)NCC1=CC(=C(C=C1)O)OC
Adenine: C1=NC2=NC=NC(=C2N1)N
D-Glucose: C([C@@H]1[C@H]([C@@H]([C@H](C(O1)O)O)O)O)O
구조에서 튀어나온 결합과 들어간 결합도 표시되어 나옵니다.
smiles 코드만 알면 어떤 분자든 그릴 수 있을 거 같아요
코드 표기는 이 블로그로 찾아봤습니다.
https://process-mining.tistory.com/158
SMILES 표기법이란? (SMILES representation 설명 및 장단점)
SMILES 표기법은 Simplified Molecular Input Line Entry System의 준말로, 분자 구조를 string 형태로 표현하여 NLP에 활용된 다양한 머신러닝 / 딥러닝 알고리즘들을 분자 구조에도 적용할 수 있게 해주는 표기
process-mining.tistory.com
재밌어요 굉장히 신기합니다.
심심할 때 이걸로 놀거나 실험 보고서 쓸 때 사용할 것 같습니다.
굿
'프로그래밍 > 융합' 카테고리의 다른 글
[화학] 중화적정 곡선 (1) | 2023.10.03 |
---|