Source code for schrodinger.test.stu.outcomes.custom.enum
import collections
import csv
from rdkit import Chem
from schrodinger.application.pathfinder import molio
from schrodinger.test.stu.outcomes.failures import WorkupFailure
[docs]def check_smarts(smarts, filename):
    """
    Check that every structure in a file maches the given SMARTS.
    """
    reader = molio.get_mol_reader(filename)
    query = Chem.MolFromSmarts(smarts)
    for i, mol in enumerate(reader, 1):
        if not mol.HasSubstructMatch(query):
            smiles = Chem.MolToSmiles(mol)
            raise WorkupFailure(
                f'Mol {filename}:{i} ({smiles}) does not match {smarts}')
    return True 
[docs]def check_csv(filename):
    """
    Check that all the rows in a CSV file have the same number of columns.
    """
    with open(filename, newline='') as fh:
        reader = csv.reader(fh)
        counter = collections.Counter(len(row) for row in reader)
        if len(counter) > 1:
            msg = 'CSV file {} has inconsistent number of columns: {}'.format(
                filename, counter)
            raise WorkupFailure(msg)
    return True