<commit_before># coding: utf-8
import os
from os.path import join, exists
import subprocess
import shutil
import pybel
from .config import CALCULATE_DATA_PATH
from .mopac import MopacModel
from .gaussian_optimize import GaussianOptimizeModel
from utils import chemistry_logger
from django.conf import settings


class Converter():
    def __init__(self, smiles=None, molfiles=None, modeltype=None):
        self.__invalid_smile = []
        self.__smilenum_list = []
        self.__molfile = []
        self.modeltype = modeltype

        # smiles 可以传入list，也可以传入以comma作为分隔符的smiles字符串
        if isinstance(smiles, list):
            self.__smilenum_list = [s for s in smiles]
        elif isinstance(smiles, basestring):
            self.__smilenum_list = smiles.split(',')

        # molfies 传递的地址是完整路径
        if isinstance(molfiles, list):
            self.__molfile = [f for f in molfiles]
        elif isinstance(molfiles, basestring):
            self.__molfile = molfiles.split(',')

    def smile2_3d(self, smile):
        mymol = pybel.readstring('smi', smile)
        if self.modeltype == 3:
            mymol.addh()
        mymol.make3D()
        name = self.format_filename(smile)
        mol_fpath = join(settings.MOL_ABSTRACT_FILE_PATH, '%s.mol' % name)
        mymol.write('mol', mol_fpath, overwrite=True)
        return mol_fpath

    def iter_smiles_files(self, src_list, src_type):
        for element in src_list:
            if src_type == 'smile':
                name = self.format_filename(element)
            elif src_type == 'file':
                name = os.path.basename(element).split('.')[0]
            else:
                raise Exception('No support %s' % src_type)

            dragon_dpath = join(CALCULATE_DATA_PATH.DRAGON, name)
            mopac_dpath = join(CALCULATE_DATA_PATH.MOPAC, name)
            mop_fpath = join(mopac_dpath, '%s.mop' % name)<commit_msg>check file exists<commit_after># coding: utf-8
import os
from os.path import join, exists
import subprocess
import shutil
import pybel
from .config import CALCULATE_DATA_PATH
from .mopac import MopacModel
from .gaussian_optimize import GaussianOptimizeModel
from utils import chemistry_logger
from django.conf import settings


class Converter():
    def __init__(self, smiles=None, molfiles=None, modeltype=None):
        self.__invalid_smile = []
        self.__smilenum_list = []
        self.__molfile = []
        self.modeltype = modeltype

        # smiles 可以传入list，也可以传入以comma作为分隔符的smiles字符串
        if isinstance(smiles, list):
            self.__smilenum_list = [s for s in smiles]
        elif isinstance(smiles, basestring):
            self.__smilenum_list = smiles.split(',')

        # molfies 传递的地址是完整路径
        if isinstance(molfiles, list):
            self.__molfile = [f for f in molfiles if exists(f)]
        elif isinstance(molfiles, basestring):
            self.__molfile = [f for f in molfiles.split(',') if exists(f)]

    def smile2_3d(self, smile):
        mymol = pybel.readstring('smi', smile)
        if self.modeltype == 3:
            mymol.addh()
        mymol.make3D()
        name = self.format_filename(smile)
        mol_fpath = join(settings.MOL_ABSTRACT_FILE_PATH, '%s.mol' % name)
        mymol.write('mol', mol_fpath, overwrite=True)
        return mol_fpath

    def iter_smiles_files(self, src_list, src_type):
        for element in src_list:
            if src_type == 'smile':
                name = self.format_filename(element)
            elif src_type == 'file':
                name = os.path.basename(element).split('.')[0]
            else:
                raise Exception('No support %s' % src_type)

            dragon_dpath = join(CALCULATE_DATA_PATH.DRAGON, name)
            mopac_dpath = join(CALCULATE_DATA_PATH.MOPAC, name)
            mop_fpath = join(mopac_dpath, '%s.mop' % name)
{'fraction_non_alphanumeric': 0.09669872628021835, 'fraction_numerical': 0.0031193137509747857, 'mean_word_length': 2.5465437788018432, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1760464', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1271, 'n_words': 281}