@s18h024 s18h024 / Python 分子式抜き出し 改訂版
Created at Tue Jul 20 11:41:55 JST 2021
InChiの機能追加版
Python 分子式抜き出し 改訂版
Raw
import pubchempy as pup
import os
import time


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

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


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

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

    print(out)
    try:

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