Recent Changes - Search:

edit SideBar

Doing An Energy-only Geometry Optimization In Parallel

Since geometry optimizations are best done with analytic gradients (and CFOUR has analytic gradients for most methods), an energy-only geometry optimization is something which one should avoid doing. However, there are cases (for example, EOM-CCSDT) where there are no gradients available for a useful method, and the METHOD=ENERONLY (or METHOD=TSENERONLY for transition states) approach to a geometry optimization is unavoidable. Running such a calculation in serial can be quite costly as a number of energy points must be run to evaluate each numerical gradient used in the optimization. Fortunately, a strategy entirely analogous to those used for parallel harmonic and anharmonic frequencies can also be used for optimizations, which is outlined here for a normal optimization. TSENERONLY jobs can be run in the same fashion.

1. Create a directory that will be your "workspace" for the optimization. In this directory, everything will be done except for the actual quantum chemical energy calculations.

2. Now, construct your ZMAT file for the optimization, making sure to use the keywords METHOD=ENERONLY and FREQ_ALGORITHM=PARALLEL (actually you are not calculating frequencies, so this is perhaps a strange keyword choice...). An example is given below for formamide, using SCF and a small basis (which makes this a good example test case to make sure you are doing all steps correctly).

formamide
O
C 1 RCO*
H 2 RCH* 1 A1*
N 2 RCN* 1 A2* 3 T180
H 4 NH1* 2 A3* 1 T0
H 4 NH2* 2 A4* 1 T180

RCO = 1.4035727376
RCH = 1.0822141466
A1 = 119.7453132747
RCN = 1.3967624803
A2 = 115.5916277063
NH1 = 1.0043425811
A3 = 120.6830303327
NH2 = 1.0035589108
A4 = 120.0229720517
T180 = 180.000000000000000
T0 = 0.000000000000000

*CRAPS(CALC=SCF,ICONTL=8
BASIS=DZ,SCF_CONV=11
METHOD=ENERONLY
FREQ_ALGORITHM=PARALLEL)

3. Now, run the pfindif_setup script which is described in Scripts For Calculating Harmonic Frequencies By Finite Differences In Parallel (it in turn relies on a run.dummy script, also described there), and a number of files called run.000.xxx will be generated. Each of these is one of the energy calculations needed to compute the gradient. Submit the various energy jobs in whatever manner you prefer.

4. After the jobs run, you will have a number of fja.xxx files in your directory. Process these and generate the Cartesian gradient and do one cycle of optimization with the following script (you might want to send the output to a file):

 
#!/bin/csh
foreach i (fja.*)
cp $i FJOBARC
xja2fja
xsymcor
mv $i old.$i
end
xjoda
rm zmat*
rm GRD ALLDONE
xsymcor

With the test ZMAT file, the Cartesian gradient generated in xsymcor and the geometry optimization step generated in xjoda are as follows:

Numerical Cartesian gradient:
0.1055297421 0.0529894995 0.0000000000
-0.0680312859 -0.0498697873 0.0000000000
-0.0135728169 0.0028154177 0.0000000000
-0.0237936934 -0.0044146890 0.0000000000
0.0049669360 0.0033450119 0.0000000000
-0.0050988820 -0.0048654527 0.0000000000


--------------------------------------------------------------------------
Parameter dV/dR Step Rold Rnew
--------------------------------------------------------------------------
RCO 0.1180103785 -0.0608181826 1.4035727376 1.3427545550
RCH -0.0040115546 0.0020674068 1.0822141466 1.0842815534
A1 0.0244845992 -5.0680666949 119.7453132747 114.6772465798
RCN 0.0170745866 -0.0087996101 1.3967624803 1.3879628702 A2 0.0536747672 -11.1101389972 115.5916277063 104.4814887091
NH1 0.0027997632 -0.0014428944 1.0043425811 1.0028996867
A3 -0.0069330274 1.4350672042 120.6830303327 122.1180975369
NH2 0.0073699799 -0.0037982149 1.0035589108 0.9997606959
A4 -0.0060937575 1.2613467344 120.0229720517 121.2843187861
--------------------------------------------------------------------------
Minimum force: 0.002799763 / RMS force: 0.044549493

5. Subsequent optimization steps can be run very easily. After running the script above, the next set of energy points has been generated, the corresponding zmatxxx files are in place, and the points are ready to be run. After they finish, just run the script above again.
In summary, a geometry optimization can be run in the "workspace" directory as follows

create ZMAT file
run pfindif_setup
submit energy points, wait for them to finish
run "green" script above
submit energy points, wait for them to finish
run "green" script above
submit energy points, with for them to finish
run "green" script above
...

with the proviso that one should NOT run xclean at any point during this process (except, of course, at the very beginning).


The following script will "babysit" such an optimization. "qsub" below should be replaced with the appropriate command for submitting a job.
#!/bin/bash                                                                                                                                                                                                                                                                       

#Usage: Optional first argument is polling time in seconds                                                                                                                                                                                                                        
# requires green.sh below in current directory.  Run pfindif_setup first.                                                                                                                                                                                                         
# remove any fja files or opt_out.txt before running, please                                                                                                                                                                                                                      

foreach ()  
{  
    func=$1;  
    shift;  
    for arg in $@;  
    do  
        ${func} ${arg};  
    done  
}  

numjobs=`ls zmat* | wc -l`  

if [ ! -z "`ls fja* opt_out.txt 2>/dev/null`" ]; then  
echo "Please remove fja files and/or opt_out.txt."  
echo "If you are mid-optimization, just rename opt_out.txt temporarily."  
exit  
fi  

if [ -z "$1" ]; then  
time1=600 # default to check every 10 minutes                                                                                                                                                                                                                                     
else  
time1=`echo $1 | cut -d. -f1` # dump fractions of a second                                                                                                                                                                                                                        
fi  
time2=$time1  

until [ ! -z "`grep completed opt_out.txt 2>/dev/null`" ]; do  
    foreach qsub run.0* > /dev/null  
    sleep $time2  
    until [ `ls fja* 2>/dev/null | wc -l` == $numjobs ] && [ -z "`wc -l fj* 2>/dev/null | grep -v total | awk '{print $1}' | grep ^0$`" ] && [ 1 -lt "`wc -l fj* 2>/dev/null | grep -v total | awk '{print $1}' | uniq | wc -l`" ]; do  
        sleep $time1  
        if [ ! -z "`wc -l fj* 2>/dev/null | grep -v total | awk '{print $1}' |grep ^0$`" ]; then  
            echo "Zero line fja in "`pwd`  
        fi  
        if [ 1 -lt "`wc -l fj* 2>/dev/null | grep -v total | awk '{print $1}' | uniq | wc -l`" ]; then  
            echo "Not all the fja's are the same length in "`pwd`  
        fi  
    done  
    time2=`tail -n 1 out* | grep walltime | awk 'max=="" || $4 > max {max=$4} END{ print max-'$time1'}' | cut -d. -f1 | sed 's/-//'`  
    green.sh  
    grep "RMS f" opt_out.txt | tail -n 1  
done  

# put this in ./green.sh, and chmod +x green.sh                                                                                                                                                                                                                                   
##!/bin/csh                                                                                                                                                                                                                                                                       
#foreach i (fja.*)                                                                                                                                                                                                                                                                
#cp $i FJOBARC                                                                                                                                                                                                                                                                    
#xja2fja > /dev/null                                                                                                                                                                                                                                                              
#xsymcor >> opt_out.txt                                                                                                                                                                                                                                                           
#mv $i old.$i                                                                                                                                                                                                                                                                     
#end                                                                                                                                                                                                                                                                              
#xjoda >> opt_out.txt                                                                                                                                                                                                                                                             
#rm zmat*                                                                                                                                                                                                                                                                         
#rm GRD ALLDONE                                                                                                                                                                                                                                                                   
#xsymcor >> opt_out.txt  
Edit - History - Print - Recent Changes - Search
Page last modified on December 15, 2015, at 03:35 AM
CFOUR is partially supported by the U.S. National Science Foundation.