||
安装chemscript
###########基础知识点###########################
WriteFile(file, format=None)Write StructureData or Reaction into a file with file format indicated by *format*.>>> m.ReadFile('output.cdx', 'cdx')
#################第一步把sdf拆分成cdx###########################
# Example 003
from sys import *
from os import *
from os.path import *
from ChemScript12 import *
if not exists('Output'):
mkdir('Output')
# Make an SD reader object for the output file
reader = SDFileReader('./Input/input.sdf')
fileNumber = 1
m = reader.ReadNext()
while m != None:
filename = './Output/out%02d' % fileNumber + '.cdxml'
m.WriteFile(filename, 'text/xml')
fileNumber += 1
m = reader.ReadNext()
# close reader
reader.Close()
################第二部把cdx保存为sdf#############################
from ChemScript12 import *
reader=SDFileReader("DWF-14.sdf")
mol=reader.ReadNext()
output=SDFileWriter("./3d.sdf")
while(mol != None):
mol.ConvertTo3DStructure()
output.WriteStructure(mol)
mol=reader.ReadNext()
#####################最后的脚本#####################################
###################bug: 2d的sdf转cdx的时候丢失了注释信息#####################################
from ChemScript12 import *
reader=SDFileReader('total264chiral.sdf')
m=reader.ReadNext()
filebasename=0;
output=SDFileWriter('./3dtotal.sdf')
while(m !=None):
filebasename+=1
filename=str(filebasename)+'.cdx'
m.WriteFile(filename,'cdx')
mol2=StructureData()
mol2.ReadFile(filename)
mol2.ConvertTo3DStructure()
output.WriteStructure(mol2)
m=reader.ReadNext()
reader.Close()
########添加了MOLNAME的注释信息,但是又发现了新的问题sdf转cdx的时候,结构扁平化#########
from ChemScript12 import *
reader=SDFileReader('total264chiral.sdf')
m=reader.ReadNext()
filebasename=0;
output=SDFileWriter('./3dtotal.sdf')
while(m !=None):
filebasename+=1
filename=str(filebasename)+'.cdx'
m.WriteFile(filename,'cdx')
mol2=StructureData()
mol2.ReadFile(filename)
mol2.ConvertTo3DStructure()
mol2["MOLNAME"]=m["MOLNAME"]
output.WriteStructure(mol2)
m=reader.ReadNext()
reader.Close()
#############################2dsdftocdx#############################################
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-20 07:38
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社