(in_file, out_file, model_path, r, uncommon=None)
Featurize mols in SDF, SMI.
    SMILES are regenerated with RDKit to get canonical SMILES without chirality information.

    Parameters
    ----------
    in_file : str
        Input SDF, SMI, ISM (or GZ)
    out_file : str
        Output csv
    model_path : str
        File path to pre-trained Gensim word2vec model
    r : int
        Radius of morgan fingerprint
    uncommon : str
        String to used to replace uncommon words/identifiers while training. Vector obtained for 'uncommon' will be used
        to encode new (unseen) identifiers

    Returns
    -------
Featurize mols in SDF, SMI.
    SMILES are regenerated with RDKit to get canonical SMILES without chirality information.
Featurize mols in SDF SMI . SMILES are regenerated with RDKit to get canonical SMILES without chirality information .
def featurize(in_file, out_file, model_path, r, uncommon=None):
    """Featurize mols in SDF, SMI.
    SMILES are regenerated with RDKit to get canonical SMILES without chirality information.

    Parameters
    ----------
    in_file : str
        Input SDF, SMI, ISM (or GZ)
    out_file : str
        Output csv
    model_path : str
        File path to pre-trained Gensim word2vec model
    r : int
        Radius of morgan fingerprint
    uncommon : str
        String to used to replace uncommon words/identifiers while training. Vector obtained for 'uncommon' will be used
        to encode new (unseen) identifiers

    Returns
    -------
    """
    # Load the model
    word2vec_model = word2vec.Word2Vec.load(model_path)
    if uncommon:
        try:
            word2vec_model[uncommon]
        except KeyError:
            raise KeyError('Selected word for uncommon: %s not in vocabulary' % uncommon)

    # File type detection
    in_split = in_file.split('.')
    f_type = in_split[-1].lower()
    if f_type not in ['sdf', 'smi', 'ism', 'gz']:
        raise ValueError('File extension not supported (sdf, smi, ism, sdf.gz, smi.gz)')
    if f_type == 'gz':
        if in_split[-2].lower() not in ['sdf', 'smi', 'ism']:
            raise ValueError('File extension not supported (sdf, smi, ism, sdf.gz, smi.gz)')
        else:
            f_type = in_split[-2].lower()

    print('Loading molecules.')
    if f_type == 'sdf':
        df = PandasTools.LoadSDF(in_file)
        print("Keeping only molecules that can be processed by RDKit.")
        df = df[df['ROMol'].notnull()]
        df['Smiles'] = df['ROMol'].map(Chem.MolToSmiles)
    else:
        df = pd.read_csv(in_file, delimiter='\t', usecols=[0, 1], names=['Smiles', 'ID'])  # Assume <tab> separated
        PandasTools.AddMoleculeColumnToFrame(df, smilesCol='Smiles')
        print("Keeping only molecules that can be processed by RDKit.")
        df = df[df['ROMol'].notnull()]
        df['Smiles'] = df['ROMol'].map(Chem.MolToSmiles)  # Recreate SMILES

    print('Featurizing molecules.')
    df['mol-sentence'] = df.apply(lambda x: MolSentence(mol2alt_sentence(x['ROMol'], r)), axis=1)
    vectors = sentences2vec(df['mol-sentence'], word2vec_model, unseen=uncommon)
    df_vec = pd.DataFrame(vectors, columns=['mol2vec-%03i' % x for x in range(vectors.shape[1])])
    df_vec.index = df.index
    df = df.join(df_vec)

    df.drop(['ROMol', 'mol-sentence'], axis=1).to_csv(out_file)
def featurize ( in_file , out_file , model_path , r , uncommon = None ) : # Load the model word2vec_model = word2vec . Word2Vec . load ( model_path ) if uncommon : try : word2vec_model [ uncommon ] except KeyError : raise KeyError ( 'Selected word for uncommon: %s not in vocabulary' % uncommon ) # File type detection in_split = in_file . split ( '.' ) f_type = in_split [ - 1 ] . lower ( ) if f_type not in [ 'sdf' , 'smi' , 'ism' , 'gz' ] : raise ValueError ( 'File extension not supported (sdf, smi, ism, sdf.gz, smi.gz)' ) if f_type == 'gz' : if in_split [ - 2 ] . lower ( ) not in [ 'sdf' , 'smi' , 'ism' ] : raise ValueError ( 'File extension not supported (sdf, smi, ism, sdf.gz, smi.gz)' ) else : f_type = in_split [ - 2 ] . lower ( ) print ( 'Loading molecules.' ) if f_type == 'sdf' : df = PandasTools . LoadSDF ( in_file ) print ( "Keeping only molecules that can be processed by RDKit." ) df = df [ df [ 'ROMol' ] . notnull ( ) ] df [ 'Smiles' ] = df [ 'ROMol' ] . map ( Chem . MolToSmiles ) else : df = pd . read_csv ( in_file , delimiter = '\t' , usecols = [ 0 , 1 ] , names = [ 'Smiles' , 'ID' ] ) # Assume <tab> separated PandasTools . AddMoleculeColumnToFrame ( df , smilesCol = 'Smiles' ) print ( "Keeping only molecules that can be processed by RDKit." ) df = df [ df [ 'ROMol' ] . notnull ( ) ] df [ 'Smiles' ] = df [ 'ROMol' ] . map ( Chem . MolToSmiles ) # Recreate SMILES print ( 'Featurizing molecules.' ) df [ 'mol-sentence' ] = df . apply ( lambda x : MolSentence ( mol2alt_sentence ( x [ 'ROMol' ] , r ) ) , axis = 1 ) vectors = sentences2vec ( df [ 'mol-sentence' ] , word2vec_model , unseen = uncommon ) df_vec = pd . DataFrame ( vectors , columns = [ 'mol2vec-%03i' % x for x in range ( vectors . shape [ 1 ] ) ] ) df_vec . index = df . index df = df . join ( df_vec ) df . drop ( [ 'ROMol' , 'mol-sentence' ] , axis = 1 ) . to_csv ( out_file )