Skip to content

Instantly share code, notes, and snippets.

@chenyuxiang0425
Last active March 9, 2022 10:07
Show Gist options
  • Save chenyuxiang0425/3a861abef352e0d78cfcf718da34fca3 to your computer and use it in GitHub Desktop.
Save chenyuxiang0425/3a861abef352e0d78cfcf718da34fca3 to your computer and use it in GitHub Desktop.
draw_structures
from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem import Draw
import os
import pandas as pd
import argparse
def get_all_file(path):
filename_list=[]
files = os.listdir(path)
for filename in files:
filename_list.append(filename)
return filename_list
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='filename')
parser.add_argument('filename')
args = parser.parse_args()
data = pd.read_csv(args.filename)
smiles = data["smiles"]
index=0
for smile in smiles:
index+=1
print(smile)
try:
mols_suppl = Chem.MolFromSmiles(smile)
Draw.MolToFile(mols_suppl,'.//png//'+str(index)+"."+smile+'.png',kekulize=True)
except Exception as identifier:
print(index, " is None.")
@chenyuxiang0425
Copy link
Author

chenyuxiang0425 commented Jan 12, 2022

What is it?

This is a script that uses rdkit library to convert molecules to images.

What are its requirements?

python3
rdkit
pandas

The input file must be in "CSV" format and it must have a png directory.
It can only be used in the Anaconda Prompt because the rdkit library only is supported in Anaconda.

How to use it in the command line?

python draw_structures.py yourfilename.csv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment