Code Chemistry - Introduction
Previously, real experimental is really important for chemistry research. It is only way to prove truth of new chemistry theory. It is still true, while computer simulation can reduce the number of experimental trials by programming and executing the reaction invoked by the new theory in a thinking machine.
I found that pythonpath must be set for importing new library. The pythonpath can be set up externally or internally in Python.
from rdkit import Chem
m = Chem.MolFromSmiles( 'C1=CC=CC=C1')
Second, the 2D coordination of the molecule can be calculated. For coordination calculation, AllChem sub-tool should be included.
from rdkit.Chem import AllChem
AllChem.Compute2DCoords( m)
Then, the molecular graph is drawn and save it so as to see in the picture manipulation tool.
from rdkit.Chem import Draw
Draw.MolToFile(m, 'benzene.png')
Now it is the time to read image files and show on display.
import matplotlib.pyplot as plt
img_m = plt.imread( 'benzene.png')
plt.imshow( img_m)
The same process can be applied for H atom included molecule.
mH = Chem.AddHs( m)
RDKit
We use RDKit for showing about examples for code chemistry. If 'import rdkit' is not working we can refer to the following link:
http://stackoverflow.com/questions/11191946/cannot-install-rdkit-in-ubuntu-11-10I found that pythonpath must be set for importing new library. The pythonpath can be set up externally or internally in Python.
Example: Draw Benzene
First, benzene can be defined as follows. Before defining molecule, the basic library of rdkit can be loaded using the import command.from rdkit import Chem
m = Chem.MolFromSmiles( 'C1=CC=CC=C1')
Second, the 2D coordination of the molecule can be calculated. For coordination calculation, AllChem sub-tool should be included.
from rdkit.Chem import AllChem
AllChem.Compute2DCoords( m)
Then, the molecular graph is drawn and save it so as to see in the picture manipulation tool.
from rdkit.Chem import Draw
Draw.MolToFile(m, 'benzene.png')
Now it is the time to read image files and show on display.
import matplotlib.pyplot as plt
img_m = plt.imread( 'benzene.png')
plt.imshow( img_m)
The same process can be applied for H atom included molecule.
mH = Chem.AddHs( m)
Comments
Post a Comment