<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# ecnet/tools/conversions.py
# v.3.0.0
# Developed in 2019 by <NAME> <<EMAIL>>
#
# Contains functions for converting various chemical file formats
#

# Stdlib imports
from csv import DictReader
from os import devnull
from os.path import abspath, dirname, isfile, join
from re import compile, IGNORECASE
from shutil import which
from subprocess import call

# 3rd party imports
from pubchempy import get_compounds

_PADEL_PATH = join(
    dirname(abspath(__file__)),
    'PaDEL-Descriptor',
    'PaDEL-Descriptor.jar'
)


def get_smiles(name):
    '''Queries PubChemPy for SMILES string for supplied molecule

    Args:
        name (str): name of the molecule

    Returns:
        str or None: if molecule found, returns first idenitifying SMILES,
            else None
    '''

    smiles = [m.isomeric_smiles for m in get_compounds(name, 'name')]
    if len(smiles) == 0:
        raise IndexError('PubChem entry not found for {}'.format(name))
    else:
        return smiles[0]<commit_msg>get_smiles now returns empty string instead of throwing exception<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# ecnet/tools/conversions.py
# v.3.0.0
# Developed in 2019 by <NAME> <<EMAIL>>
#
# Contains functions for converting various chemical file formats
#

# Stdlib imports
from csv import DictReader
from os import devnull
from os.path import abspath, dirname, isfile, join
from re import compile, IGNORECASE
from shutil import which
from subprocess import call

# 3rd party imports
from pubchempy import get_compounds

_PADEL_PATH = join(
    dirname(abspath(__file__)),
    'PaDEL-Descriptor',
    'PaDEL-Descriptor.jar'
)


def get_smiles(name):
    '''Queries PubChemPy for SMILES string for supplied molecule

    Args:
        name (str): name of the molecule

    Returns:
        str or None: if molecule found, returns first idenitifying SMILES,
            else None
    '''

    smiles = [m.isomeric_smiles for m in get_compounds(name, 'name')]
    if len(smiles) == 0:
        return ''
    else:
        return smiles[0]
{'fraction_non_alphanumeric': 0.09336492890995261, 'fraction_numerical': 0.01042654028436019, 'mean_word_length': 3.370600414078675, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5255527', 'n_tokens_mistral': 710, 'n_tokens_neox': 662, 'n_words': 225}