# -*-shell-script-*-
#TCL script file created from scripts/work/si_ge/si-T-expans.script
# Silicon bulk, thermal expansion by Parrinello-Rahman MD

#*******************************************
# Definition of procedures
#*******************************************
proc initmd { } { MD++ {
#setnolog
setoverwrite
#dirname = runs/si-expans-w2e3-damp5e-4
#dirname = runs/si-expans-fixbox
#dirname = runs/si-expans-test
dirname = runs/si-expans-w2e3-NPT
#------------------------------------------------------------
# Read in MEAM potential
meamfile = "/home/caiwei/Codes/MD++/Fortran/MEAM-Baskes/meamf"
ntypes = 1  ename0 = "Siz  " #leave spaces to be compatible with fortran
rcut = 6  kode0 = "library"
readMEAM
NIC = 200 NNM = 200
#--------------------------------------------
# Create Perfect Lattice Configuration
#
latticestructure = diamond-cubic
latticeconst = 5.430949821 #(A) for Si
makecnspec = [ 1 0 0  3
               0 1 0  3
               0 0 1  3 ]
#makecrystal
} }
#end of proc initmd

#-------------------------------------------------------------
proc openwindow { } { MD++ {
# Plot Configuration
#
atomradius = 0.67 bondradius = 0.3 bondlength = 2.8285 #for Si
atomcolor = orange bondcolor = red backgroundcolor = gray70
#plot_color_bar = [ 1 -4.85 -4.50 ] 
plotfreq = 10  rotateangles = [ 0 0 0 1.25 ] #[ 0 -90 -90 1.5 ]
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 = 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 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)":" "}]"
    }
}




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

MD++  {

makecrystal    

saveH # Use current H as reference (H0)

T_OBJ = 300 #Kelvin

usenosehoover = 1  vt2 = 2e28  

#fixbox = 1 # constant volume (NVE)
fixbox = 0 # Parrinello-Rahman, but box remain rectangular
fixboxvec = [ 0 1 1
              1 0 1
              1 1 0 ]

atommass = 28.0855 # (g/mol)
wallmass = 2e3     # atommass * NP = 14380
boxdamp = 1e-3     # optimal damping for 216 atoms and wallmass 1e-3

srand48bytime  DOUBLE_T = 1  timestep = 0.0001 # (ps)
initvelocity
#fixallatoms
eval
}

#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++_PrintVectorArray VSR "no unit" 0 5
#MD++_PrintArray EPOT_IND "eV"      0 5
#MD++_PrintVar   EPOT     "eV"      
#MD++_PrintVar   EPBOX    "eV"      
#MD++_PrintVar   KATOM    "eV"      
#MD++_PrintVar   KBOX     "eV"      
#MD++_PrintVar   HELM     "eV"      
#MD++_PrintVar   HELMP    "eV"      
#MD++_PrintVar   atommass "eV"      


MD++ {

totalsteps = 50000   equilsteps = 0  
integrator_type = 0 #0: Gear6, 1: Velocity Verlet
saveprop = 1 savepropfreq = 100 openpropfile
savecn = 1 savecnfreq = 10000 openintercnfile writeall = 1 
plotfreq = 20
    
run
    
finalcnfile = si100.cn  writecn
}

#MD++ usenosehoover = 0 conj_fixbox = 0 totalsteps = 100000  run
#MD++ finalcnfile = si101.cn writecn
#
#MD++_PrintMatrix VIRIAL  "eV"
#MD++_PrintMatrix SIGMA   "eV"
#MD++_PrintMatrix PSTRESS "eV"
#MD++_PrintMatrix TSTRESS "eV/A^3"
#MD++_PrintMatrix H       "A"
#MD++_PrintMatrix GH      "eV/A"
#MD++_PrintMatrix VH      "A"
#MD++_PrintVectorArray SR "no unit" 0 5
#MD++_PrintVectorArray VSR "no unit" 0 5
#MD++_PrintArray EPOT_IND "eV"      0 5
#MD++_PrintVar   EPOT     "eV"      
#MD++_PrintVar   EPBOX    "eV"      
#MD++_PrintVar   KATOM    "eV"      
#MD++_PrintVar   KBOX     "eV"      
#MD++_PrintVar   HELM     "eV"      
#MD++_PrintVar   HELMP    "eV"      
#MD++_PrintVar   atommass "eV"      


#
MD++ quit
