Skip to content

graphchem.preprocessing.atom_to_str

Convert an RDKit Atom object to a string representation.

The string representation includes various properties of the atom, such as chiral tag, degree, explicit valence, formal charge, hybridization, implicit valence, aromaticity, number of implicit hydrogen atoms, and more.

Parameters

atom : rdkit.Chem.Atom An RDKit Atom object representing a single atom in a molecule.

Returns

str A string representation of the atom, including its properties.

Examples

from rdkit import Chem mol = Chem.MolFromSmiles('C1=CC=CC=C1') atom = mol.GetAtomWithIdx(0) atom_to_str(atom) '(CHIRAL_NONE, 3, 4, 0, , 0, True, False, 0, 0, 0, 'C', 3, 1, 4, 5)'

Source code in graphchem/preprocessing/features.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def atom_to_str(atom: "rdkit.Chem.Atom") -> str:
    """
    Convert an RDKit Atom object to a string representation.

    The string representation includes various properties of the atom,
    such as chiral tag, degree, explicit valence, formal charge, hybridization,
    implicit valence, aromaticity, number of implicit hydrogen atoms, and more.

    Parameters
    ----------
    atom : rdkit.Chem.Atom
        An RDKit Atom object representing a single atom in a molecule.

    Returns
    -------
    str
        A string representation of the atom, including its properties.

    Examples
    --------
    >>> from rdkit import Chem
    >>> mol = Chem.MolFromSmiles('C1=CC=CC=C1')
    >>> atom = mol.GetAtomWithIdx(0)
    >>> atom_to_str(atom)
    '(CHIRAL_NONE, 3, 4, 0, <Hybridization.SP2: 6>, 0, True, False, 0, 0, 0,
     'C', 3, 1, 4, 5)'
    """
    return str((
        atom.GetChiralTag(),
        atom.GetDegree(),
        atom.GetExplicitValence(),
        atom.GetFormalCharge(),
        atom.GetHybridization(),
        atom.GetImplicitValence(),
        atom.GetIsAromatic(),
        atom.GetNoImplicit(),
        atom.GetNumExplicitHs(),
        atom.GetNumImplicitHs(),
        atom.GetNumRadicalElectrons(),
        atom.GetSymbol(),
        atom.GetTotalDegree(),
        atom.GetTotalNumHs(),
        atom.GetTotalValence(),
        get_ring_size(atom)
    ))