# -*-shell-script-*-
#TCL script file created from scripts/work/si_ge/sige-meam.script
# Germanium bulk, lattice constant and cohesive energy

#*******************************************
# Definition of procedures
#*******************************************
proc initmd { } { MD++ {
#setnolog
setoverwrite
dirname = runs/sige-meam-tcl
#--------------------------------------------
# Read in MEAM potential
meamfile = "/home/caiwei/Codes/MD++/Fortran/MEAM-Baskes/meamf"
meafile  = "/home/caiwei/Codes/MD++/Fortran/MEAM-Baskes/meafile_Si_Ge"
ntypes = 2  ename0 = "Siz  " ename1 = "Ge   " #leave spaces to be compatible with fortran
rcut = 6.0  kode0 = "library"
readMEAM
NNM = 100
#
#--------------------------------------------
# Create Perfect Lattice Configuration
#
latticestructure = zinc-blende
latticeconst = 5.5379 #(A) for Ge
makecnspec = [ 1 0 0  4
               0 1 0  4
               0 0 1  4 ]
nspecies = 2
} }
#end of proc initmd

#--------------------------------------------
proc openwindow { } { MD++ {
# Plot Configuration
#
atomradius = [ 0.8 0.5 ] bondradius = 0.3 
win_width = 500 win_height = 500
bondradius = 0.3 bondlength = 2.5 #2.8285 #for Si
atomcolor = orange atomcolor1 = gray90 highlightcolor = purple  bondcolor = green
fixatomcolor = yellow backgroundcolor = gray70
color00 = "orange"  color01 = "purple" color02 = "green"
color03 = "magenta" color04 = "cyan"   color05 = "purple"
color06 = "gray80"  color07 = "white"
plot_atom_info = 2 #2: real coordinates, 3: energy of atoms
plotfreq = 10
rotateangles = [ 0 0 0 1.2 ]
openwin alloccolors rotate saverot refreshnnlist plot
} }
#end of proc openwindow

#--------------------------------------------
proc exitmd { } { MD++ quit }
#end of proc exitmd

#--------------------------------------------
proc relax_freebox { } { MD++ {
# Conjugate-Gradient relaxation
conj_ftol = 1e-6 conj_itmax = 1000 conj_fevalmax = 1000
conj_fixbox = 0  relax
} }
#end of proc relax_freebox


proc printfile {fname} { puts [read [open $fname r]] }

proc index3 { ID coord } {
    set ind.x 1; set ind.y 2; set ind.z 3
    expr { $ID * 3 + [set ind.$coord] - 1 }
}

proc MD++_GetVector { name ID coord } {
    MD++_Get $name [index3 $ID $coord]
}

proc MD++_PrintVar { name {unit \?} {fmt %11.4e} } {
    puts "$name\t= [format $fmt [MD++_Get  $name]] (in $unit)"
}

proc MD++_PrintMatrix { name {unit \?} {fmt %11.4e} } {
    puts "$name\t= [format $fmt [MD++_Get $name 0]] [format $fmt [MD++_Get $name 1]] [format $fmt [MD++_Get $name 2]]  (in $unit)"
    puts      "\t  [format $fmt [MD++_Get $name 3]] [format $fmt [MD++_Get $name 4]] [format $fmt [MD++_Get $name 5]]"
    puts      "\t  [format $fmt [MD++_Get $name 6]] [format $fmt [MD++_Get $name 7]] [format $fmt [MD++_Get $name 8]]"
}

proc MD++_PrintArray { name {unit \?} {i0 0} {i1 3} {fmt %11.4e} } {
    for {set ID $i0} {$ID < $i1} {incr ID 1} {
        puts "$name\($ID\)= [format $fmt [MD++_Get  $name $ID]] [expr {$ID==$i0?"(in $unit)":" "}]"
    }
}

proc MD++_PrintVectorArray { name {unit \}?} {i0 0} {i1 3} {fmt %11.4e} } {
    for {set ID $i0} {$ID < $i1} {incr ID 1} {
        puts "$name\($ID\)= ([format $fmt [MD++_GetVector $name $ID x]]\
                           [format $fmt [MD++_GetVector $name $ID y]]\
                           [format $fmt [MD++_GetVector $name $ID z]])\
                           [expr {$ID==$i0?"(in $unit)":" "}]"
    }
}



#*******************************************
# Main program starts here
#*******************************************
initmd

#set amin 5.333
#set amax 5.343
#set da 0.001
#
#set datafile "Elatt.dat.tcl"
#set fileID [open $datafile w ]
#
#set a $amin
#while {$a <= $amax} {
#    MD++  latticeconst = $a makecrystal eval
#    puts $fileID "EPOT = [MD++_Get EPOT]"
#    set a [expr $a + $da]
#}
#close $fileID
#
#printfile $datafile

MD++ latticeconst = 5.3 makecrystal eval

relax_freebox

set atomID 2
set coord  x

#for {set ID 0} {$ID < 10} {incr ID 1} {
#        puts "EPOT($ID)= [format %.8e [MD++_Get EPOT_IND $ID]]  \
#               SR($ID)= ([format %.3e [MD++_GetVector SR $ID x]]\
#                         [format %.3e [MD++_GetVector SR $ID y]]\
#                         [format %.3e [MD++_GetVector SR $ID z]])" 
#}


#print results
puts "NP   = [MD++_Get NP]"
puts "EPOT = [MD++_Get EPOT]"

#MD++_Set EPOT_IND 1 2 3 4 5
#puts "EPOT_IND(0) = [MD++_Get EPOT_IND 0 ]"
#puts "EPOT_IND(1) = [MD++_Get EPOT_IND 1 ]"
#puts "EPOT_IND(2) = [MD++_Get EPOT_IND 2 ]"

MD++_PrintMatrix VIRIAL  "eV"
MD++_PrintMatrix PSTRESS "eV"
MD++_PrintMatrix TSTRESS "eV/A^3"
MD++_PrintMatrix H       "A"
MD++_PrintMatrix GH      "eV/A"
MD++_PrintVectorArray SR "no unit" 0 5
MD++_PrintArray EPOT_IND "eV"      0 5

#openwindow
#relax_freebox
#after 2000
exitmd
#--------------------------------------------


