# -*-shell-script-*-
# Silicon nanowire bending (TCL)

source "scripts/Examples/Tcl/startup.tcl"
#*******************************************
# Definition of procedures
#*******************************************
proc initmd {  } { MD++ {
setnolog
setoverwrite
dirname = runs/si-nw-nebmep

atommass = 28.0855  # Si
timestep = 0.001    # 1fs
} }
#end of proc initmd

#------------------------------------------------------------
proc readmeam-lammps { } { MD++ {
#Read in MEAM potential (Baskes format)
meamfile = "/home/caiwei/Codes/lammps-15Dec06/examples/meam/meamf"
nspecies = 1  element0 = "Siz" rcut = 6.0  readMEAM
NNM = 300
} }

#------------------------------------------------------------
proc readmeam { } { MD++ {
#Read in MEAM potential (MD++ format)
potfile = "/home/caiwei/Codes/MD++/potentials/MEAMDATA/meamdata.Siz" readMEAM
#xzbl = -10 xzbl0 = -9 #turn off correction
} }

#-------------------------------------------------------------
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 = 100  rotateangles = [ 90 0 0 1.25 ]
openwin  alloccolors rotate saverot eval plot
} }
#end of proc openwindow

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

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

#--------------------------------------------
proc setup_md { } { MD++ {     
equilsteps = 0  timestep = 0.0001 # (ps)
atommass = 28.0855 # (g/mol)
DOUBLE_T = 0
saveprop = 1 savepropfreq = 100 openpropfile 
savecn = 1 savecnfreq = 1000 openintercnfile
plotfreq = 100
vt2 = 2e28  #1e28 2e28 5e28
wallmass = 2e3     # atommass * NP = 14380
boxdamp = 1e-3     # optimal damping for 216 atoms and wallmass 1e-3
saveH # Use current H as reference (H0), needed for specifying stress
fixboxvec  = [ 1 1 1 
               1 1 1
               1 1 0 ]
stress = [ 0 0 0
           0 0 0
           0 0 0 ]
output_fmt = "curstep EPOT KATOM Tinst HELM HELMP TSTRESS_zz P_com(0) P_com(1) P_com(2) F_com(0) F_com(1) F_com(2) Ptheta_com Torque" 
ensemble_type = "NVT" integrator_type = "VVerlet" implementation_type = 1
} }
#end of proc setup_md


    



#*******************************************
# Main program starts here
#*******************************************
# status 0:prepare liquid, 1: prepare liquid-solid interface, 2,3: measure Tm
# read in status from command line argument
if { $argc == 0 } {
 set status 0
} elseif { $argc > 0 } {
 set status [lindex $argv 0]
}
puts "status = $status"

if { $status == 0 } {
  initmd
  #readmeam-lammps

  MD++ {
      input = [220000 1] # time_frame scale(0:no, 1:yes)
      incnfile = dump.SiNW.400K.220000 readLAMMPS
  }
  
  #MD++ input = \[ 1 -0.5 0.5 -0.5 0.5 0.1912 0.2672 \] fixatoms_by_position
  MD++ input = \[ 1 -0.5 0.5 -0.5 0.5 0.21 0.25 \] fixatoms_by_position
  MD++ constrain_fixedatoms
  
  MD++ {
      input = [460000 1] # time_frame scale(0:no, 1:yes)
      incnfile = dump.SiNW.400K.300k.460000 readLAMMPS setconfig2
      input = [220000 1] # time_frame scale(0:no, 1:yes)
      incnfile = dump.SiNW.400K.220000 readLAMMPS setconfig1
  }

  MD++ fix_constrainedatoms
  MD++_PrintArray fixed "(integer)" 40 50 "%d"
  
  openwindow 

  #MD++ sleep
  
  MD++ chainlength = 20  allocchain totalsteps = 100
  MD++ timestep = 0.01 printfreq = 1

  MD++ initRchain
  #MD++ incnfile = neb.chain readRchain

  MD++ nebspec = \[ 0 1 \] #0:do not interpolate surrounding atoms, 1:redistribution frequency

  MD++ nebrelax
  MD++ finalcnfile = neb.chain.500 writeRchain

  MD++_PrintArray constrainatoms "(integer)" 0 10 "%d"
  MD++_PrintVectorArray SR "(A)" 0 10 "%20.12e"

  MD++ sleep
  exitmd 

  
} else {
 
  puts "unknown status = $status"
  exitmd
}

