109 lines
2.5 KiB
Plaintext
109 lines
2.5 KiB
Plaintext
/*
|
|
* Create a GUI panel for importing the extracellular potential file
|
|
* Written by Sina Shirinpour
|
|
* Modified by Zhen Qi
|
|
* Modified by Connell Paxton
|
|
*/
|
|
|
|
proc E_field_params(){ localobj pwm, file
|
|
pwm = new PWManager()
|
|
for jj = 0, pwm.count()-1 {
|
|
if (strcmp(pwm.name(jj),"E-field") == 0) {
|
|
pwm.close(jj)
|
|
break
|
|
}
|
|
}
|
|
|
|
file = new File()
|
|
getes_realistic($s1)
|
|
}
|
|
|
|
|
|
proc getes_realistic() { localobj potentials_file, ex_potential_vec
|
|
nseg_total = 0
|
|
forall { // Total number of segments
|
|
nseg_total += nseg
|
|
}
|
|
printf("Total: %d\n", nseg_total)
|
|
ex_potential_vec = new Vector(nseg_total)
|
|
|
|
potentials_file = new File()
|
|
if(!potentials_file.ropen($s1)){
|
|
printf("Extracellular potential file not found!\n")
|
|
sred("Press enter to quit", "y", "y")
|
|
quit()
|
|
}
|
|
print "Opened."
|
|
ex_potential_vec.scanf(potentials_file)
|
|
potentials_file.close()
|
|
|
|
|
|
// (Connell) NOTE: THIS DUPLICATES READINGS AS WE ONLY HAVE 1 POTENTIAL PER
|
|
// SWC node, and multiple segments per node.
|
|
ii = 0
|
|
forall {
|
|
for (x,0) {
|
|
es_xtra(x) = ex_potential_vec.x[ii]
|
|
ii += 1
|
|
}
|
|
}
|
|
printf("%d Extracellular potentials imported\n", ii)
|
|
}
|
|
// Written by Connell Paxton, to load ptntls 12/25/25 (Merry Christmas!)
|
|
objref f
|
|
strdef line
|
|
|
|
// storage
|
|
objref sec_closest
|
|
sec_closest = nil
|
|
closest_x = 0.5
|
|
min_dist = 1e9
|
|
|
|
// helper: squared distance
|
|
func dist2() { local dx, dy, dz
|
|
dx = $1 - $4
|
|
dy = $2 - $5
|
|
dz = $3 - $6
|
|
return dx*dx + dy*dy + dz*dz
|
|
}
|
|
|
|
// read file
|
|
proc load_potential_file() { local x, y, z, v, i, d2
|
|
f = new File()
|
|
if (!f.ropen($s1)) {
|
|
printf("ERROR: cannot open %s\n", $s1)
|
|
return
|
|
}
|
|
|
|
while (f.scanf("%g %g %g %g", &x, &y, &z, &v) == 4) {
|
|
|
|
min_dist = 1e9
|
|
sec_closest = nil
|
|
|
|
forall {
|
|
if (n3d() > 0) {
|
|
for i = 0, n3d()-1 {
|
|
d2 = dist2(x, y, z, x3d(i), y3d(i), z3d(i))
|
|
if (d2 < min_dist) {
|
|
min_dist = d2
|
|
sec_closest = new SectionRef()
|
|
sec_closest.sec = sec
|
|
closest_x = arc3d(i) / L
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (sec_closest != nil) {
|
|
sec_closest.sec {
|
|
// STORE POTENTIAL HERE
|
|
// Example: using extracellular
|
|
e_extracellular(closest_x) = v
|
|
}
|
|
}
|
|
}
|
|
|
|
f.close()
|
|
}
|
|
|
|
load_potential_file("pruned.ptntl") |