load_lowe_examples_into_db_details.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:ochem_predict_nn 作者: connorcoley 项目源码 文件源码
def main(db_fpath, N = 15):
    '''Read reactions from Lowe's patent reaction SMILES'''

    try:
        # Open file
        file_generator = get_reaction_file(db_fpath)
        print(file_generator)
        documents = []
        for i, rxn in enumerate(file_generator):
            if i == N:
                break

            print('~~~~~~~ {} ~~~~~~'.format(i))
            print('{}: {}'.format(i, rxn))
            document = minidom.parse(rxn)
            try:
                dic = doc_to_dic(document)
                dic['random'] = random()
                documents.append(dic)
            except ValueError as e:
                print(e)

            # Report progress and insert every 1000
            if ((i+1) % 1000) == 0:
                print('{}/{}'.format(i+1, N))
                result = collection.insert(documents)
                documents = []

        if documents: result = collection.insert(documents)
    except KeyboardInterrupt:
        print('Stopped early!')     

    print('Created {} database entries'.format(collection.find().count()))

    return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号