TABLE OF CONTENTS


::pwtk::vecFromTo

SYNOPSIS

proc ::pwtk::vecFromTo {fromUnit toUnit vecs} {

PURPOSE

Transform 3D vectors from one unit to another one. Units can be bohr, angstrom, or a real number interpreted as 'alat'.

ARGUMENTS

SOURCE

    # transform to Bohr
    
    switch -glob $fromUnit {
        bohr  { set scale 1.0 }
        angs* { set scale $::pwtk::angs2bohr }
        default  {
            if { [string is double -strict $fromUnit] } {
                # interpreted as alat
                set scale $fromUnit
            } else {
                ::pwtk::error "wrong input unit (aka fromUnit); expected bohr, angstrom, or a real number, but got $fromUnit"
            }
        }
    }
    set vecs [scaleVec $scale $vecs]

    # transform to $toUnit
    
    switch -glob $toUnit {
        bohr  { set scale 1.0 }
        angs* { set scale $::pwtk::bohr2angs }
        default  {
            if { [string is double -strict $toUnit] } {
                # interpreted as alat
                set scale [expr 1.0/$toUnit]
            } else {
                ::pwtk::error "wrong output unit (aka toUnit); expected bohr, angstrom, or a real number, but got $toUnit"
            }
        }
    }
    return [scaleVec $scale $vecs]
}