TABLE OF CONTENTS


::pwtk::input::namelistItyp2AtmSymb

SYNOPSIS

proc ::pwtk::input::namelistItyp2AtmSymb {nmlName varName} {    

PURPOSE

This routine is typically used internally by PWTK.

Transform "ntyp"-type variable by replacing the atomic-index with atomic-label, e.g., "starting_magnetization(1)" will be transformed to "starting_magnetization(Fe)", where 1 is the index of the Fe species.

Beware that such transformation should be only done immediately after "load_from" operation.

RETURN VALUE

SOURCE

    global ::pwtk::ntyp_variables
    global ::pwtk::ntyp_dimensions
    global ::pwtk::ntyp_multidimensions

    set dimL   [::pwtk::varvalue ::pwtk::ntyp_dimensions($nmlName)]
    set multiL [::pwtk::varvalue ::pwtk::ntyp_multidimensions($nmlName)]

    # split var(index) to {var index}
    lassign [split $varName ()] var index

    if { ($dimL eq {} && $multiL eq {}) || $index eq {} } {
        return $varName
    }

    set atomic_labels [::pwtk::pwi::getAllAtomicLabels]
    set ntyp [llength $atomic_labels]
    
    if { $var in $dimL } {
        if { $index > $ntyp } {
            # index is greater than the number of atomic-species; make no transformation
            return $varName
        }
        set atmSymb [lindex $atomic_labels $index-1] 
        return ${var}($atmSymb)
    } elseif { $var in $multiL } {
        set dim [lindex $multiL [lsearch -nocase $multiL $var]+1]
        if { ! [string is integer -strict $dim] } {
            ::pwtk::error "::pwtk::ntyp_multidimensions list is malformed, check the respective config/*i.tcl config file" 1
        }
        set indL [split $index ,]
        set ityp [lindex $indL $dim]
        if { [string is integer -strict $ityp] } {
            if { $ityp > $ntyp } {
                # index is greater than the number of atomic-species; make no transformation
                return $varName
            }
            set symb [lindex $atomic_labels $ityp-1]
            set newi [join [lreplace $indL $dim $dim $symb] ,]
            return ${var}($newi)
        }
    }
    
    return $varName    
}