-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomLocation.hoc
85 lines (73 loc) · 2.32 KB
/
RandomLocation.hoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
fprint("RandomLocation_ver = '$Revision: 1.2 $';\n")
/*
RandomLocation
rl = new RandomLocation(SectionList)
rl.loc(PointProcess)
relocates the PointProcess to a random location with respect to
uniform distribution based on position.
SectionList defines the set of sections to sample.
PointProcess must have a loc() member function.
There must be a default section declared to measure distance from.
*/
begintemplate RandomLocation
public loc
public total_length, dstart, dend
objectvar seclist, ran
proc init() { local
dstart = -1
if ( numarg () == 4) {
dstart = $3
dend = $4
}
seclist = $o1
ran = new Random($2)
total_length = 0
forsec seclist {
// Add length of current section
total_length = total_length + L
// Find the distance of the ends from the origin
d0 = distance(0)
d1 = distance(1)
// This should remove any length of section beyond the
// Limits specified by dstart and dend
if ( min(d0,d1) < dstart ) {
total_length = total_length - (dstart-min(d0,d1))
}
if ( max(d0,d1) > dend ) {
total_length = total_length - (max(d0,d1)-dend)
}
}
}
// randomize location of synapse
func loc() {local l, done, rpos, secx, dx, gl, lsec, d0, d1
rpos = ran.uniform(0, total_length)
done = 0
l = 0 // Cumulative length
// distance() // assumes soma is currently accessed
// sets the currently-accessed section as the origin
forsec seclist {
lsec = L
d0 = distance(0)
d1 = distance(1)
// This should remove any length of section beyond the
// Limits specified by dstart and dend
if ( min(d0,d1) < dstart ) {
lsec = lsec - (dstart-min(d0,d1))
}
if ( max(d0,d1) > dend ) {
lsec = lsec - (max(d0,d1)-dend)
}
l = l + lsec // L is length of section
if (l > rpos) {
// print l, " ", rpos, " ", L
secx = (rpos - l + L)/L
// print secx
$o1.loc(secx)
dx = distance(secx)
print secname(), " ", secx, " ", dx
rpos = 1e20 // a break would screw up the stack?
}
}
return secx
}
endtemplate RandomLocation