Skip to content

Commit

Permalink
In progrss
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjorthmedh committed Oct 12, 2023
1 parent 01b186e commit 446f380
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions snudda/place/bend_morphologies.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import numpy as np
from scipy.spatial.transform import Rotation

from snudda.neurons import NeuronMorphologyExtended
from snudda.place.region_mesh_redux import RegionMeshRedux


class BendMorphologies:

def __init__(self, region_mesh: RegionMeshRedux):
def __init__(self, region_mesh: RegionMeshRedux, rng):

self.region_mesh = region_mesh

pass
self.rng = rng

def check_if_inside(self, morphology: NeuronMorphologyExtended):

Expand All @@ -19,14 +19,37 @@ def check_if_inside(self, morphology: NeuronMorphologyExtended):

return inside_flag

def bend_morphology(self, morphology: NeuronMorphologyExtended):
def bend_morphology(self, morphology: NeuronMorphologyExtended, k=50e-6):

# k -- decay constant

parent_rotation_matrices = dict() # indexed by parent_point_idx in SectionMetaData

# Iterate over all parts of neuron
for section in morphology.section_iterator():

# We need to track the rotation of each point, in particular save rotations
# for each branch point, so that all children can start with that rotation

if section.parent_section_idx in parent_rotation_matrices:
rotation_matrix = parent_rotation_matrices[section.parent_section_idx]
else:
rotation_matrix = np.eye(3)

# Loop over all points in section
for point_idx in section.point_idx:
coords = section.morphology_data.geometry[point_idx, :]
dist = self.region_mesh.distance_to_border(points=coords)

P = 1 / (1 + np.exp(-k * dist))

if self.rng.uniform(1) < P:
# We need to randomize new rotation matrix
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.transform.Rotation.html
Rotation
pass



# Gradient is calculated based on distance to mesh
# Calculate delta_gradient = gradient_self - gradient_parent
Expand All @@ -36,6 +59,7 @@ def bend_morphology(self, morphology: NeuronMorphologyExtended):
# After section is done, store the last rotation matrix, so its children can get their parent rotation
# store in dictionary?

parent_rotation_matrices[point_idx] = rotation_matrix



Expand Down

0 comments on commit 446f380

Please sign in to comment.