# -*-shell-script-*-
# Si nano-indentation 2d simulation

#*******************************************
# Definition of procedures
#*******************************************
proc initmd { } { MD++ {
setnolog
setoverwrite
dirname = runs/si-indent-compare

# LJ parameters
C12 = 0.1  C6 = 0.04  initLJ  writeall = 1
#C12 = 0.1  C6 = 0  initLJ  writeall = 1

conj_ftol = 2e-6 conj_itmax = 1000 conj_fevalmax = 1000 conj_fixbox = 1
} }

proc markconfig { } { MD++ {    
#-----------------------------------------------
# Mark the tip
input = [ 1  -10 10 0    10 -10 10 ] fixatoms_by_position input = 0 setfixedatomsgroup freeallatoms
input = [ 1  -10 10 0.35 10 -10 10 ] fixatoms_by_position input = 4 setfixedatomsgroup freeallatoms

#-----------------------------------------------
# Mark the substrate
input = [ 1  -10 10 -10  0    -10 10 ] fixatoms_by_position input = 1 setfixedatomsgroup freeallatoms
input = [ 1  -10 10 -10 -0.48 -10 10 ] fixatoms_by_position input = 2 setfixedatomsgroup freeallatoms

#-----------------------------------------------
# fix atoms
input = [ 1  -10 10  0.35  10 -10 10 ] fixatoms_by_position 
input = [ 1  -10 10 -10 -0.48 -10 10 ] fixatoms_by_position
} }
#end of proc initmd

#-------------------------------------------------------------
proc openwindow { } { MD++ {
# Plot Configuration
#
atomradius = 0.67 bondradius = 0.3 bondlength = 2 #2.8285 #for Si
atomcolor = orange bondcolor = red backgroundcolor = gray70 fixatomcolor = yellow
plotfreq = 10  rotateangles = [ 0 0 0 1.25 ]
color00 = "orange"  color01 = "purple" color02 = "green"
color03 = "magenta" color04 = "cyan"   color05 = "purple"
color06 = "gray80"  color07 = "white"
plot_color_windows = [ 2
                          -4.3 -4.0  0  #color00 = orange
                          -4.0  10   1  #color01 = purple
                       1                #draw fixed atoms   
                     ]
plot_atom_info = 1
openwin  alloccolors rotate saverot eval plot
} }
#end of proc openwindow

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

#--------------------------------------------
# for diagnosis purposes
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 5} {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 0} {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)":" "}]"
    }
}
# end of diagnosis procs

    



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

#MD++ incnfile = haneesh.cn readcn
#markconfig
#MD++ finalcnfile = h.marked.cn writecn quit

#MD++ incnfile = h.marked.cn readcn
MD++ incnfile = h.relaxed.cn readcn
#MD++ incnfile = h.s2.cn readcn

openwindow

MD++  {

#input = [ 2  0 -0.5 0  0 4 ] movegroup # move group 0 and 4 downward    
input = [ 2  0 -15 0  0 4 ] movegroup # move group 0 and 4 downward    

#relax  finalcnfile = h.relaxed.cn writecn
#relax  finalcnfile = h.s1.cn writecn
#relax  finalcnfile = h.s2.cn writecn
relax  finalcnfile = h.s3.cn writecn

sleep quit

srand48bytime  DOUBLE_T = 0  timestep = 0.0001 # (ps)
equilsteps = 0  atommass = 28.0855 # (g/mol)
integrator_type = 0 #0: Gear6, 1: Velocity Verlet

saveprop = 1 savepropfreq = 20 openpropfile
savecn = 1 savecnfreq = 1000 openintercnfile writeall = 1 
plotfreq = 10

output_fmt = "curstep Tinst EPOT HELMP tipforce(0) tipforce(1) tipforce(2)"

T_OBJ = 300 initvelocity

input = [ 1 0 0 0  0 ] setgroupcomvel 
input = [ 1 0 0 0  1 ] setgroupcomvel



#totalsteps = 5  usenosehoover = 1  vt2 = 2e28  run  finalcnfile = equil.cn writeall = 1 writecn
relax finalcnfile  

input = [ 2  0 -1 0  0 4 ] movegroup # move group 0 and 4 downward
input = [ ]
movegroup
run

}



#for {set x 1} {$x < 100} {incr x} {
#    set distance [expr { $x/100 } ]
#    puts "x=$x distance=$distance  equil.$x.cn"
#}
#
#for{set x 1}{$x < 100}{incr x} {
#    set distance [expr $x/100  ]
#    MD++ input = [ 0 ] movegroup
#    MD++  totalsteps = 1000 run
#    finalcnfile = equil.$x.cn writecn
#}



exitmd
