Ejemplo n.º 1
0
    def test_2_elements_sets(self):
        to_be_swapped = [2, 3]
        sample = [1, 3]

        result = swap(to_be_swapped, sample)
        expected = (1, 3, 2)
        self.assertEquals(result, expected)
Ejemplo n.º 2
0
def _fix_mobile_h(mol, inchi, u1, u2):
    """

    Identifies a system of atoms bearing unpaired electrons and mobile hydrogens
    at the same time.

    The system will consist of a central atom that does not bear any mobile hydrogens,
    but that is bound to an atom that does bear a mobile hydrogen, called the "original atom".

    The algorithm identifies the "new partner" atom that is part of the mobile hydrogen
    system.

    Next, the mobile hydrogen is transferred from the original atom, to the new partner,
    and a bond is removed and added respectively.

    Finally, the central atom and the original atom will each receive an unpaired electron,
    and the bond between them will decrease in order.
    """

    mobile_hydrogens = _parse_h_layer(inchi)

    if mobile_hydrogens:
        # WIP: only consider the first system of mobile hydrogens:
        mobile_hydrogens = mobile_hydrogens[0]

        # find central atom:
        central, original, new_partner = swap(mobile_hydrogens, [u1, u2])

        central, original, new_partner = \
            mol.atoms[central - 1], mol.atoms[original - 1], mol.atoms[new_partner - 1]

        # search hydrogen atom and bond
        hydrogen = None
        for at, bond in original.bonds.items():
            if at.number == 1:
                hydrogen = at
                mol.remove_bond(bond)
                break

        new_h_bond = Bond(new_partner, hydrogen, order='S')
        mol.add_bond(new_h_bond)

        mol.get_bond(central, new_partner).decrement_order()

        central.radical_electrons += 1
        original.radical_electrons += 1
        return True

    return False
Ejemplo n.º 3
0
def fix_mobile_h(mol, inchi, u1, u2):
    """

    Identifies a system of atoms bearing unpaired electrons and mobile hydrogens
    at the same time.

    The system will consist of a central atom that does not bear any mobile hydrogens,
    but that is bound to an atom that does bear a mobile hydrogen, called the "original atom".

    The algorithm identifies the "new partner" atom that is part of the mobile hydrogen 
    system.

    Next, the mobile hydrogen is transferred from the original atom, to the new partner,
    and a bond is removed and added respectively.

    Finally, the central atom and the original atom will each receive an unpaired electron,
    and the bond between them will decrease in order.
    """

    mobile_hydrogens = inchiutil.parse_H_layer(inchi)

    if mobile_hydrogens:
        # WIP: only consider the first system of mobile hydrogens:
        mobile_hydrogens = mobile_hydrogens[0]

        #find central atom:
        central, original, new_partner = util.swap(mobile_hydrogens, [u1, u2])

        central, original, new_partner = \
        mol.atoms[central - 1], mol.atoms[original - 1], mol.atoms[new_partner - 1]

        # search hydrogen atom and bond
        hydrogen = None
        for at, bond in original.bonds.iteritems():
            if at.number == 1:
                hydrogen = at
                mol.removeBond(bond)
                break

        new_h_bond = Bond(new_partner, hydrogen, order='S')
        mol.addBond(new_h_bond)
        
        mol.getBond(central, new_partner).decrementOrder()

        central.radicalElectrons += 1
        original.radicalElectrons += 1
        return True

    return False