TABLE OF CONTENTS


::pwtk::difden::run

SYNOPSIS

proc ::pwtk::difden::run {head {difdenInput ""}} {

PURPOSE

Run the "difden" calculation (difden acronym stands for difference-density). Before runing the "difden" calculation, user must specify the DIFDEN namelist.

SEE ALSO

For the description of DIFDEN namelist and "difden" calculations see ::pwtk::difden::DIFDEN

ARGUMENTS

SOURCE

    variable difden

    ::pwtk::input::pushpop {
    
        # load defaults for pw.x (i.e. outdir, pseudo_dir, etc ...)
        ::pwtk::pwi::loadDefaults_ CONTROL
        
        if { $difdenInput != "" } {
            DIFDEN $difdenInput
        }

        printTitle_ "Performing DIFDEN calculation"
        parseDIFDEN_
        
        # print some message to stdout
        
        print_      "  number of segments to compute = $difden(nsegment)\n"
        
        for {set i $difden(first)} {$i <= $difden(last)} {incr i} {
            if { [info exists difden(segment,$i)] } {
                print_ "  segment #.$i:"
                if { [info exists difden(name,$i)] } {
                    print_ "      segment name:                    $difden(name,$i)"
                }
                print_ "      weight of this segment:          $difden(weight,$i)"
                print_ "      atoms belonging to this segment: $difden(segment,$i)"     
            }
        }
        puts ""
    
        # ------------------------------------------------------
        # STEP #1: perform the SCF & pp.x (INPUTPP) calculations
        
        print_ "Step #.1: performing the pw.x (SCF) & pp.x (&INPUTPP) calculations\n"
    
        for {set i $difden(first)} {$i <= $difden(last)} {incr i} {
            if { [info exists difden(segment,$i)] } {        
                # assign atoms to the $i-th segment
                set difden(atomList,$i) [::pwtk::parseRangeString $difden(segment,$i) [::pwtk::pwi::getNAtoms]]
        
                # run SCF pw.x && pp.x
                ::pwtk::difden::runSCF_INPUTPP_ $head $i        
            }
        }
        # ------------------------------------------------------
    

        ::pwtk::input::pushpop {
        
            # prepare input file for pp.x (PLOT) calculation
            
            PLOT " nfile = $difden(nsegment) "

            set ind 1
            for {set i $difden(first)} {$i <= $difden(last)} {incr i} {
                if { [info exists difden(weight,$i)] } {
                    PLOT "filepp($ind) = '$difden(filplot,$i)' , weight($ind) = $difden(weight,$i) "
                    incr ind
                }
            }
            ::pwtk::input::namelistClear INPUTPP

            set fileout [::pwtk::input::namelistGetVarValue PLOT fileout trim]
            if { $fileout == "" } {
                # define fileout
                set fileout $head.fileout
                PLOT " fileout = '$fileout' "
            }            

            # -----------------------------------------
            # STEP #.2: perform PP.x (PLOT) calculation

            print_ "Step #.2: performing the pp.x (&PLOT) calculation\n"
            runPP plot.$head

            if { [file exists $fileout] } {
                ::pwtk::print "Requested differential property was written to file:   $fileout\n"
            } else {
                ::pwtk::error "fileout $fileout does not exist;\nsee the $head.plot.out file for possible cause."
            }
            # -----------------------------------------       
        }
    }
}