首页 > 编程知识 正文

如何将文件转化成zip,ptf文件转化成cad文件

时间:2023-05-04 17:54:02 阅读:184294 作者:2562

import osimport sysfrom rdkit import Chemdef split_mol2(mol_path, out_path): with open (mol_path,'r') as f: lines = f.readlines() if not os.path.exists(out_path): os.makedirs(out_path) path_protein = os.path.join(out_path,'protein') if not os.path.exists(path_protein): os.makedirs(path_protein) path_ligands = os.path.join(out_path,'ligands') if not os.path.exists(path_ligands): os.makedirs(path_ligands) start_line = 0 end_line = 0 ligand_order = 0 for i, line in enumerate(lines): if '@<TRIPOS>MOLECULE' in line and i >0 and i < len(lines)-1: # protein end_line = i s = '' for l in lines[start_line:end_line]: s+= l mol = Chem.MolFromMol2Block(s,removeHs=False) if start_line == 0: p_file = os.path.join(path_protein,'protein.sdf') if start_line >0: p_file = os.path.join(path_ligands,str(ligand_order)+'.sdf') ligand_order += 1 #print(mol,start_line) try: writer = Chem.SDWriter(p_file) writer.write(mol) writer.close() except: print(mol_path,'is error') start_line = end_line if i == len(lines)-1: s = '' for l in lines[start_line:]: s+= l mol = Chem.MolFromMol2Block(s,removeHs=False) #ligand_order += 1 p_file = os.path.join(path_ligands,str(ligand_order)+'.sdf') try: writer = Chem.SDWriter(p_file) writer.write(mol) writer.close() except: print(mol_path,'is error') def get_mol2_files(mol2_path): mol2_files = os.listdir(mol2_path) for file in mol2_files: if file.endswith('.mol2'): mol_path = os.path.join(mol2_path,file) out_dir = file.split('.')[0] #out_path = os.path.join(mol2_path,out_dir) out_path = os.path.join('result_mol2',out_dir) if not os.path.exists(out_path): os.makedirs(out_path) split_mol2(mol_path, out_path) if __name__ == '__main__': mol2_path = '***/input_structures' get_mol2_files(mol2_path) #mol_path = 'PTP1B.mol2' #out_path = 'out_1' #split_mol2(mol_path, out_path)

输出的蛋白质sdf文件在 protein 文件夹,配体在ligands文件夹

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。