def SanityCheck(s):
    """
    Class performs a simple text-based SanityCheck
    to validate generated SMILES. Note, this method
    does not check if the SMILES defines a valid molecule,
    but just if the generated SMILES contains the
    correct number of ring indices as well as opening/closing
    brackets.
    Input:
    s -- Generated SMILES String.
    Return:
    True if the generated SMILES String is valid.
    """
    # Check ring-pairing
    for r in range(1,10):
        if s.count("%s"%(r)) % 2 != 0:
            return False

    # Check branch-pairing
    if s.count("(") != s.count(")"):
        return False

    # Check explicit info pairing
    if s.count("[") != s.count("]"):
        return False

    # All rules pass
    return True