Example #1
0
def readFlsFile(fileName, isomers):
    """Reads molecule file (fls file).

    :param fileName: (str) File name.
    :param isomers: (pandas Dataframe) Table with ENU code, molecular formula and SMILEs string..
    :return:
        molecules: (list) List of molecules.
    """

    with open(fileName, 'r') as f:
        lines = f.readlines()

    lines = [row.strip().split() for row in lines]

    molecules = []
    for i in range(len(lines)):
        if not lines[i]:
            continue

        if lines[i][0] == '#':

            # couldn't find a decomposition
            if len(lines[i]) > 2 and lines[i][1] == "couldn\'t":
                smiles = lines[i][6]

                iso = isomers[isomers.smiles == smiles]
                mol = Molecule(smiles, '', '', '', 0, [], 0, '')
                mol.form = iso.frm.iloc[0]
                mol.code = iso.nam.iloc[0]
                mol.enu_code = iso.nam.iloc[0]
                molecules.append(mol)

            else:
                continue

        if lines[i][0][0] == '#':
            continue

        if lines[i][0] == 'NEWMOLECULE':
            pos = i + 1
            mol = readFlsFile_helper(pos, lines)

            smi = mol.smiles
            iso = isomers[isomers.smiles == smi]
            mol.form = iso.frm.iloc[0]
            mol.code = iso.nam.iloc[0]

            molecules.append(mol)

    return molecules
Example #2
0
def getMolecules(isomers):
    """Returns list of molecules created from table with SMILES.

    :param isomers: (pandas DataFrame) List of constitutional isomers together with molecular formula and SMILES.
    :return:
        molecules: (list) List of Molecules.
    """

    molecules = []
    for idx, row in isomers.iterrows():
        smiles = row['smiles']
        form = row['frm']
        nam = row['nam']

        mol = Molecule(smiles, '', nam, '', 0, [], 0, '')
        mol.form = form
        molecules.append(mol)

    return molecules