TABLE OF CONTENTS


::pwtk::atomSymbol

SYNOPSIS

proc ::pwtk::atomSymbol {atomStr} {

USAGE

    atomSymbol atomStr

DESCRIPTION

Get the atomic symbol from the supplied string.

ARGUMENTS

RETURN VALUE

atomic-symbol; if atom is not found, "X" (e.g. dummy atom) is returned.

SOURCE

    variable atomDataList
    variable atomSymbols
    
    set unknown X
    
    # is $atomStr an atomic number ?
    
    if { [string is integer -strict $atomStr] } {
        if { $atomStr >= $::pwtk::minAtomicNumber && $atomStr <= $::pwtk::maxAtomicNumber } {
            return [lindex $atomSymbols $atomStr-1]
        } else {
            return $unknown
        }
    }

    # $atomStr is a string; first, try two letters, then a single letter
    
    foreach idx {1 0} {
        set atom [string range $atomStr 0 $idx]
        if { $atom in $atomSymbols } {
            return $atom
        }
        #foreach a $::pwtk::atomDataList {
        #    set symb [lindex $a 1]
        #    if { $atom == $symb } {
        #        return $symb
        #    }
        #}
    }

    return $unknown
}