20.1 Obtaining the Atomic Symbol of an Atom/Element

To simplify the task of dealing with the elements of the periodic table, OEChem contains several functions to obtain useful properties of the elements.

A common task is to obtain or display the atomic symbol of an atom represented by an OEAtomBase. To save space and reduce redundancy and consistency issues, the OEAtomBase class contains only an unsigned integer representing the atom's atomic number. This value may be obtained using the OEAtomBase method GetAtomicNum. This value can be converted into an atomic symbol using the OEChem function, OEGetAtomicSymbol.

# ch20_1.py
from openeye.oechem import *

symb = OEGetAtomicSymbol(OEElemNo_C)
print "The atomic symbol for carbon is", symb

The example above uses the integer constant OEElemNo_C from the OEElemNo namespace. This namespace represents the atomic numbers of the 109 elements as their symbols as a convenience.

The OEGetAtomicSymbol returns a string. For atomic number zero and elements greater than or equal to OEElemNo_MAXELEM (currently 110), OEGetAtomicSymbol returns an empty string. For all other (valid) values, the returned string contains one or two characters. The first character is always uppercase, and the second character, if it exists is lower case.