-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsdf-converter.py
43 lines (34 loc) · 1.28 KB
/
sdf-converter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 25 21:47:15 2020
@author: lzt
"""
import pathlib
from openbabel.pybel import (readfile,Outputfile)
'''
def MolFormatConversion(input_file:str,output_file:str,input_format="xyz",output_format="sdf"):
molecules = readfile(input_format,input_file)
output_file_writer = Outputfile(output_format,output_file)
for i,molecule in enumerate(molecules):
output_file_writer.write(molecule)
output_file_writer.close()
print('%d molecules converted'%(i+1))
'''
file_name=[]
sdf_dir = pathlib.Path('./')
for sdf_file in sdf_dir.glob("*.xyz"):
file_name.append(sdf_file.name)
# print(file_name)
print(len(file_name))
def MolFormatConversion(input_file:str,output_file:str,input_format="xyz",output_format="sdf"):
molecules = readfile(input_format,input_file)
output_file_writer = Outputfile(output_format,output_file)
for i,molecule in enumerate(molecules):
output_file_writer.write(molecule)
output_file_writer.close()
print('%d molecules converted'%(i+1))
for i in file_name:
input_file=i.split('.')[0]+".xyz"
output_file=i.split('.')[0]+".sdf"
MolFormatConversion(input_file, output_file)
#MolFormatConversion("2.xyz", "2.sdf")