TABLE OF CONTENTS


::pwtk::spinSetup

SYNOPSIS

proc ::pwtk::spinSetup {magn {mo 0}} {

USAGE

    spinSetup magn ?mo?

DESCRIPTION

This routine is used by ::pwtk::calcmol to setup proper "magnetization" for molecule-in-a-box calculation. If the number of electrons is odd, spin-polarization is turned on (even if $magn == 0), otherwise the "tot_magnetization" will be set to $magn and if $magn > 0 then spin-polarization is turned on.

ARGUMENTS

RETURN VALUE

The value of "nbnd" (i.e. number-of-bands); if mo == true then nbnd is set to the index of LUMO orbital if this index is greater than the current nbnd.

SOURCE

    # let's make a dry pw.x run as to get the number of electrons
    
    set pwo   [dryrunPW]
    set nbnd  [::pwtk::pwo::nbnd $pwo]
    set nelec [::pwtk::pwo::nelec $pwo]
    if { $nelec == {} } {
        ::pwtk::error "Cannot get the number of electrons from the pw.x dry-run.
This probably indicates that pw.x input specification is invalid/insufficient." 1
    }
    set odd   [expr int($nelec)%2]
    set nhomo [expr int($nelec/2) + $odd]    
    set odd_magn [expr int($magn)%2]
    
    print "Calculating indices of HOMO and LUMO orbitals via a dry run ..."
    print "- number of valence electrons : $nelec"    
    print "- number of Kohn-Sham states  : $nbnd"
    print "- HOMO is orbital #.$nhomo"
    
    if { $odd } {
        if { $magn == 0 } {
            # odd number of electrons   
            print "  INFO: odd number of electrons (nelec = $nelec)"
            set nspin [::pwtk::input::namelistGetVarValue SYSTEM nspin]     
            set occ   [::pwtk::input::namelistGetVarValue SYSTEM occupations trim]
            if { $occ != "smearing" && ($nspin == {} || $nspin < 2) } {
                print "        using spin-polarization"
                set magn 1
            }
        } elseif { ! $odd_magn } {
            ::pwtk::error "odd number of electrons and even magnetization (magn = $magn) are not consistent" 1
        }       
        print "- HOMO is SOMO (single-occupied molecular-orbital)"
    }
    if { $magn > 0 } {
        print "- total magnetization = $magn"
        SYSTEM " nspin = 2, tot_magnetization = $magn "
    }
    
    set nlumo [expr $nhomo + 1]
    if { ! [expr int($nelec)%2] } {
        print "- LUMO is orbital #.$nlumo"
    }
    puts ""
    
    set nbnd [expr $nlumo > $nbnd ? $nlumo : $nbnd]    
    if { $mo } {
        SYSTEM " nbnd = $nbnd "
    }
    
    # delete dry-run files
    file delete $pwo [file rootname $pwo].in
    
    return $nbnd
}