Пример #1
0
def set_atomic_charges(
    mol: rdkit.Chem.rdchem.Mol,
    atomic_numbers: Iterable[int],
    atomic_valence_electrons,
    BO_valences,
    BO_matrix,
    mol_charge,
) -> rdkit.Chem.rdchem.Mol:
    q = 0
    for i, atom in enumerate(atomic_numbers):
        a = mol.GetAtomWithIdx(i)
        charge = _get_atomic_charge(atom, atomic_valence_electrons[atom],
                                    BO_valences[i])
        q += charge
        if atom == 6:
            number_of_single_bonds_to_C = list(BO_matrix[i, :]).count(1)
            if number_of_single_bonds_to_C == 2 and BO_valences[i] == 2:
                q += 1
                charge = 0
            if number_of_single_bonds_to_C == 3 and q + 1 < mol_charge:
                q += 2
                charge = 1

        if abs(charge) > 0:
            a.SetFormalCharge(int(charge))

    mol = _clean_charges(mol)

    return mol
Пример #2
0
def set_atomic_radicals(
    mol: rdkit.Chem.rdchem.Mol,
    atomic_numbers: Iterable[int],
    atomic_valence_electrons,
    BO_valences,
) -> rdkit.Chem.rdchem.Mol:
    # The number of radical electrons = absolute atomic charge
    for i, atom in enumerate(atomic_numbers):
        a = mol.GetAtomWithIdx(i)
        charge = _get_atomic_charge(atom, atomic_valence_electrons[atom],
                                    BO_valences[i])

        if abs(charge) > 0:
            a.SetNumRadicalElectrons(abs(int(charge)))

    return mol