How to create a .cdx file from InChI with ChemDraw/Python?

我是研究僧i 提交于 2020-01-05 04:17:18

问题


I would like to create a ChemDraw .cdx file from an InChI with Python. This answer gives a solution for cdx --> InChI.

The minimal example below cdx_to_inchi works fine, but I could not figure out how I can get inchi_to_cdx to work.

import comtypes.client as w32

def cdx_to_inchi(cdx):
    ChemDraw = w32.CreateObject("ChemDraw.Application")
    ChemDraw.Visible = False
    Compound = ChemDraw.Documents.Open(cdx)            # opens existing file
    inchi = Compound.Objects.Data("chemical/x-inchi")
    print(inchi)
    ChemDraw.Quit()

def inchi_to_cdx(inchi):
    ChemDraw = w32.CreateObject("ChemDraw.Application")
    ChemDraw.Visible = False

    Compound = ChemDraw.Documents.Open("Emtpy.cdx")   # opens existing file
    # ChemDraw.Documents.New("NewFile.cdx")           # How to create a new file?

    # Compound.Objects.SetData(inchi)                 # How to paste InChi data?
    # ChemDraw.Documents.Save()                       # How to save?
    # ChemDraw.Documents.SaveAs("MyMolecule.cdx")     # How to save under different name?
    ChemDraw.Quit()

cdx = r'C:\Data\Test.cdx'
inchi = '1S/C6H6/c1-2-4-6-5-3-1/h1-6H'

cdx_to_inchi(cdx)
inchi_to_cdx(inchi)

来源:https://stackoverflow.com/questions/58183902/how-to-create-a-cdx-file-from-inchi-with-chemdraw-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!