4
$\begingroup$

I have around 1000 SMILES entries in Excel and I have to generate .sdf file for all. Is there any way to automate this whole process, preferably with an offline tool?

$\endgroup$
0
4
$\begingroup$

Working with this many SMILES you should consider to have a look at Open Babel, both, because it may transcribe many chemistry relevant formats as well as extract and filter information from them. This being said, you have at least two options:

  • One time use, preferentially with shorter lists to convert: Use Open Babel's GUI which equally is freely available. On the left hand side, select the input format as .smi and that you would like to paste the SMILES, rather than to read them from a file. Select on the right hand column the export format and enter the directory where your permanent .sdf shall be written. Helpful for a human is to add the option (center column) "Append output index to title" as a counter, and highly recommended for future work with the .sdf to activate "Generate 3D coordinates" a bit lower in this column, too.

    Screenshot of the Open Babel GUI

  • Depending on the operational system at your disposition, Open Babel has multiple interfaces to languages like Python. Let us assume you saved your data in the .xlsx format (e.g., Excel, LibreOffice Calc or gnumeric) in the second column of your spreadsheet:

    Screenshot of LibreOffice Calc with partially filled table

    Even without entering into the inner tools of Open Babel, you then may already benefit from a module like openpyxl to access the SMILES directly, relaying them to Open Babel, e.g.

    # name:  reader.py
    
    import openpyxl
    import subprocess as sub
    import sys
    
    try:
        source_file = sys.argv[1]
        workbook = openpyxl.load_workbook(source_file)
        sheet = workbook['Sheet1']
    except:
        print("Call the script on the CLI by 'python reader.py [my_data.xlsx]'.")
        sys.exit()
    
    
    def reading():
        """ retrieve the SMILES from the .xlsx """
        global smiles_collector
        smiles_collector = ""
        for cell in sheet['B']:
            smiles_collector += str('-:"') + str(cell.value) + str('" ')
    
    
    def writing():
        """ provide a container .sdf """
        reading()
        conversion = str("obabel {} -osdf > output.sdf --gen3d".format(smiles_collector))
        sub.call(conversion, shell=True)
    
    
    reading()
    writing()
    sys.exit()
    
$\endgroup$
4
$\begingroup$

Datawarrior lets you do it. Export a csv sheet with two columns: The name of the compound and its SMILES code. Be sure to use a comma as a delimiter. Your output file, opened with a text editor, should look like this:

Name,SMILES
Hexazine,n1nnnnn1
Furazan,c1nonc1
Benzisoxazole,c1noc2c1cccc2

From DataWarrior, File>Open and open your file. Structures are automatically generated from SMILES codes.

Then, File>Save Special>SD-File, and you are done.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.