TABLE OF CONTENTS


::pwtk::pwi::CELL_PARAMETERS_fromPWO

SYNOPSIS

proc ::pwtk::pwi::CELL_PARAMETERS_fromPWO {pwoFile {index end}} {

PURPOSE

Load a CELL_PARAMETERS card from the pw.x output file. CELL_PARAMETERS are loaded only if the record is present in the pw.x output file unless index==0 or index==end (in this case the initial lattice-vectors are returned; for index==end, the initial lattice-vectors are returned if CELL_PARAMETERS records are missing in the output).

ARGUMENTS

SIDE EFFECTS

1. The ibrav is set to 0 if CELL_PARAMETERS are found in $pwoFile and loaded into PWTK. 2.

SOURCE

    set vec [::pwtk::pwo::getPrimVec -k $pwoFile $index]
    
    if { $vec eq "" } {
        ::pwtk::warning "failed to load CELL_PARAMETERS with index = $index\nfrom the PWO file '$pwoFile'; record not found"
    } else {
        set ibrav [::pwtk::pwi::ibrav]
        if { $ibrav != 0 } {
            ::pwtk::infoMsg "from [::pwtk::procName]:\nsetting ibrav = 0,\nwhile loading CELL_PARAMETERS from the PWO file '$pwoFile'"
            SYSTEM " ibrav = 0 "
        }

        if { [string match {*alat*} $vec] } {
            # CELL_PAREMETERS in alat: alat must be defined in the SYSTEM namelist
            
            set alat_not_set [expr { [::pwtk::pwi::aA] eq {} &&             
                                     [::pwtk::input::namelistGetVarValue SYSTEM celldm(1)] eq {} }]
                
            if { ! [string match {*=*} $vec] } {
                # we have the initial lattice vectors: CELL_PARAMETERS (alat)
                if { $alat_not_set } {
                    set pwo_alat [::pwtk::pwo::alat $pwoFile 0]
                    
                    ::pwtk::infoMsg "from [::pwtk::procName]:\nsetting celldm(1) = $pwo_alat,\nwhile loading the initial lattice vectors from the PWO file '$pwoFile'"
                    
                    SYSTEM " celldm(1) = $pwo_alat "
                }
            } else {
                # we have: CELL_PARAMETERS (alat= 21.08089896)

                set iron_alat [::pwtk::pwi::alat]
                set pwo_vec   $vec
                set cell_line [lindex [split $vec \n] 0]
                set alat      [lindex [split $cell_line =\)] 1]

                if { $alat_not_set } {
                    ::pwtk::warning "from [::pwtk::procName]:\nCELL_PARAMETERS are specified in alat units in '$pwoFile',\nbut alat is currently not set.\n
Using the alat calculated from the CELL_PARAMETERS record in '$pwoFile',\ni.e., setting celldm(1) = $alat"
                    
                    SYSTEM " celldm(1) = $alat "                    
                } else {
                    # we need to rescale cell_parameters wrt iron and new alat            
                    set vec [::pwtk::scaleVec $alat/$iron_alat [::pwtk::purifyVec $vec]]
            
                    ::pwtk::infoMsg "from [::pwtk::procName]:\n\"$cell_line\" line found in '$pwoFile';\n
rescaling cell vectors from PWO by a factor $alat/$iron_alat\n* extracted cell vectors:\n$pwo_vec\n
* rescaled cell vectors:\nCELL_PARAMETERS (alat)\n[::pwtk::CELL_PARAMETERS_math_parser $vec]"
                }
            }
            #
            CELL_PARAMETERS (alat) [::pwtk::purifyVec $vec]
            #
        } else {
            # we have: CELL_PARAMETERS (angstrom) or CELL_PARAMETERS (bohr)
            # unset celldm & A
            SYSTEM { celldm(1) = , A = , a = }
            CELL_PARAMETERS [lindex $vec 1] [::pwtk::purifyVec $vec]
        }
    }
}