Example #1
0
def create_U_layer(mol, auxinfo):
    """
    Creates a string with the positions of the atoms that bear unpaired electrons. The string
    can be used to complement the InChI with an additional layer that allows for the differentiation
    between structures with multiple unpaired electrons.

    The string is composed of a prefix ('u') followed by the positions of each of the unpaired electrons,
    sorted in numerical order.

    Example:
    - methyl radical ([CH3]) : u1
    - triplet methylene biradical ([CH2]) : u1,1
    - ethane-1,2-diyl biradical ([CH2][CH2]): u1,2
    
    When the molecule does not bear any unpaired electrons, None is returned.

    """

    cython.declare(
                minmol=Molecule,
                #rdkitmol=,
                u_layer=list,
                i=int,
                at=Atom,
                equivalent_atoms=list,
               )

    if mol.getRadicalCount() == 0:
        return None
    elif mol.getFormula() == 'H':
        return inchiutil.U_LAYER_PREFIX + '1'


    # find the resonance isomer with the lowest u index:
    minmol = generate_minimum_resonance_isomer(mol)
    
    # create preliminary u-layer:
    u_layer = []
    for i, at in enumerate(minmol.atoms):
        u_layer.extend([i+1] * at.radicalElectrons)
    
    # extract equivalent atom pairs from E-layer of auxiliary info:
    equivalent_atoms = inchiutil.parse_E_layer(auxinfo)
    if equivalent_atoms:
        # select lowest u-layer:
        u_layer = find_lowest_u_layer(minmol, u_layer, equivalent_atoms)

    return (inchiutil.U_LAYER_PREFIX + ','.join(map(str, u_layer)))
def create_P_layer(mol, auxinfo):
    """

    Creates a string with the positions of the atoms that bear an unexpected number of lone pairs. The string
    can be used to complement the InChI with an additional layer that allows for the differentiation
    between structures with lone pairs.

    The string is composed of a prefix ('P_LAYER_PREFIX') followed by the positions of each of the atoms with an
    unexpected number of lone pairs, sorted in numerical order.

    Example:
    - singlet methylene biradical ([CH2]) : 'P_LAYER_PREFIX'1

    When the molecule does not bear any atoms with an unexpected number of lone pairs,
    None is returned.


    """

    # TODO: find the resonance isomer with the lowest p index:
    minmol = mol

    # create preliminary p-layer:
    p_layer = []
    for i, at in enumerate(mol.atoms):
        try:
            exp = element.PeriodicSystem.lone_pairs[at.symbol]
        except KeyError:
            raise Exception("Unrecognized element: {}".format(at.symbol))
        else:
            if at.lonePairs != element.PeriodicSystem.lone_pairs[at.symbol]:
                if at.lonePairs == 0:
                    p_layer.append('{}{}'.format(i, '(0)'))
                else:
                    p_layer.extend([i + 1] * at.lonePairs)

    # extract equivalent atom pairs from E-layer of auxiliary info:
    equivalent_atoms = inchiutil.parse_E_layer(auxinfo)
    if equivalent_atoms:
        # select lowest u-layer:
        u_layer = find_lowest_p_layer(minmol, p_layer, equivalent_atoms)

    if p_layer:
        return (inchiutil.P_LAYER_PREFIX +
                inchiutil.P_LAYER_SEPARATOR.join(map(str, p_layer)))
    else:
        return None
Example #3
0
def create_P_layer(mol, auxinfo):
    """

    Creates a string with the positions of the atoms that bear an unexpected number of lone pairs. The string
    can be used to complement the InChI with an additional layer that allows for the differentiation
    between structures with lone pairs.

    The string is composed of a prefix ('P_LAYER_PREFIX') followed by the positions of each of the atoms with an
    unexpected number of lone pairs, sorted in numerical order.

    Example:
    - singlet methylene biradical ([CH2]) : 'P_LAYER_PREFIX'1

    When the molecule does not bear any atoms with an unexpected number of lone pairs,
    None is returned.


    """

    # TODO: find the resonance isomer with the lowest p index:
    minmol = mol

    # create preliminary p-layer:
    p_layer = []
    for i, at in enumerate(mol.atoms):
        try:
            exp = adjlist.PeriodicSystem.lone_pairs[at.symbol]
        except KeyError:
            raise Exception("Unrecognized element: {}".format(at.symbol))
        else:
            if at.lonePairs != adjlist.PeriodicSystem.lone_pairs[at.symbol]:
                if at.lonePairs == 0:
                    p_layer.append('{}{}'.format(i, '(0)'))
                else:
                    p_layer.extend([i+1] * at.lonePairs)

    # extract equivalent atom pairs from E-layer of auxiliary info:
    equivalent_atoms = inchiutil.parse_E_layer(auxinfo)
    if equivalent_atoms:
        # select lowest u-layer:
        u_layer = find_lowest_p_layer(minmol, p_layer, equivalent_atoms)

    if p_layer:
        return (inchiutil.P_LAYER_PREFIX + inchiutil.P_LAYER_SEPARATOR.join(map(str, p_layer)))
    else:
        return None