Last active
March 9, 2022 10:07
-
-
Save chenyuxiang0425/3a861abef352e0d78cfcf718da34fca3 to your computer and use it in GitHub Desktop.
draw_structures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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