问题
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