Below is an example script to run many SMARTIES simulations and export the T-matrices in HDF5. The script is available as standalone script smarties_batch.R.
library(glue)library(dplyr)library(purrr)# read in the templatetemplate <-glue_collapse(readLines('smarties/_template.m'), sep ="\n")parameters <-expand.grid(a =seq(10, 100, by=5), c =seq(10, 100, by=5),material =c("Au", "Ag", "Si"), medium =c("vacuum", "water")) |>filter(a != c) |># use Mie for thismutate(shape =ifelse(a > c, "oblate", "prolate"),n =ifelse(medium =="water", 1.33, 1.0),source =case_when(material =="Au"~"Raschke et al 10.1103/PhysRevB.86.235147", material =="Ag"~"Raschke et al 10.1103/PhysRevB.91.235137", material =="Si"~"Aspnes et al 10.1103/PhysRevB.27.985",.default ="Unknown material!"))parameters$step <-1nrow(parameters)
[1] 2052
For initial testing, we’ll run much fewer combinations
parameters <-expand.grid(a =seq(20, 50, by=10), c =seq(20, 50, by=10),material =c("Au", "Ag"), medium =c("water")) |>filter(a != c) |># use Mie for thismutate(shape =ifelse(a > c, "oblate", "prolate"),n =ifelse(medium =="water", 1.33, 1.0),source =case_when(material =="Au"~"Raschke et al 10.1103/PhysRevB.86.235147", material =="Ag"~"Raschke et al 10.1103/PhysRevB.91.235137", material =="Si"~"Aspnes et al 10.1103/PhysRevB.27.985",.default ="Unknown material!"))parameters$step <-5
Even with these restricted options, there’s already 24 combinations.
a
c
shape
material
medium
30
20
oblate
Au
water
40
20
oblate
Au
water
50
20
oblate
Au
water
20
30
prolate
Au
water
40
30
oblate
Au
water
50
30
oblate
Au
water
20
40
prolate
Au
water
30
40
prolate
Au
water
50
40
oblate
Au
water
20
50
prolate
Au
water
30
50
prolate
Au
water
40
50
prolate
Au
water
30
20
oblate
Ag
water
40
20
oblate
Ag
water
50
20
oblate
Ag
water
20
30
prolate
Ag
water
40
30
oblate
Ag
water
50
30
oblate
Ag
water
20
40
prolate
Ag
water
30
40
prolate
Ag
water
50
40
oblate
Ag
water
20
50
prolate
Ag
water
30
50
prolate
Ag
water
40
50
prolate
Ag
water
We use the “glue” package to inject the parameters into the template, where the variables are indicated between braces {}. The process loops over each parameter combination and outputs a new file with corresponding filename.
write_script <-function(a, c, material, medium, shape, n, step, source){ script <-glue(template) cat(script, file =glue('smarties/run_{material}_{medium}_{a}_{c}.m'))cat(glue("run_{material}_{medium}_{a}_{c}\n\n"), file ="smarties/batch.m", append =TRUE)}cat("%% Running all the files below\n",file ="smarties/batch.m", append =FALSE)pwalk(rowwise(parameters), write_script)
Running the batch script in Matlab results in 24 output T-matrix files of size between 4 and 6Mb each, with the 5nm step defined above. The value of Lmax needed for \(10^{-10}\) accuracy in \(\langle\sigma_\text{ext}\rangle\) appears to be around 11.