@db2021 db2021 / Python 分子式抜き出し
Created at Wed Jun 23 14:49:21 JST 2021
Python 分子式抜き出し
Raw
import pubchempy as pup
import os
import time


element = []
files =os.listdir("./output")
element_z = [f for f in files if os.path.isfile(os.path.join("./output", f))]

for i in element_z:
    a=i.replace(".sdf","")
    print(a)
    element.append(a)


req = ["MolecularFormula"]
for j in element:

    out = pup.get_properties(req,j,'name')

    try:

        fname = "./bunshi/" + j + ".txt"
        with open(fname,"w") as e:
            e.write(out[0].get("MolecularFormula"))
        time.sleep(1)
    except:
        fname = "./bunshi/" + j + "__error__.txt"
        with open(fname,"w") as e:
            e.write("ERROR!\nPlease check your self.")
        time.sleep(1)