Skip to content

Commit

Permalink
feat(utils): replace undetermined gates with standard ones
Browse files Browse the repository at this point in the history
Wherever possible.

Fixes #205
  • Loading branch information
sanjayankur31 committed Jan 14, 2025
1 parent 41597db commit 299d0f7
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions neuroml/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,63 @@ def fix_external_morphs_biophys_in_cell(
return newdoc


def create_new_typed_gate(gate):
"""Convert an undetermined gate to a "determined" gate
:param gate: gate object of GateHHUndetermined type
:returns: new gate object, or None if the gate is not of a standard type
"""
gates_name_map = {
"gateHHrates": "GateHHRates",
"gateHHratesTau": "GateHHRatesTau",
"gateHHratesInf": "GateHHRatesInf",
"gateHHratesTauInf": "GateHHRatesTauInf",
"gateHHtauInf": "GateHHTauInf",
"gateHHInstantaneous": "GateHHInstantaneous",
"gateFractional": "GateFractional",
"gateKS": "GateKS",
}
gate_type = getattr(gate, "type", None)
if gate_type:
try:
gate_class_type = gates_name_map[gate_type]
# if it isn't in our dict, it's non standard
except KeyError:
return None

new_gate = component_factory(component_type=gate_class_type, validate=False)
print(gate.__dict__)
new_gate.__dict__.update(gate.__dict__)
return new_gate


def move_undetermined_gates_to_typed(nml2_doc):
"""Replace gates of GateHHUndetermined type with their standard
counterparts where possible.
Note that this modifies the passed NeuroMLDocument object in-place.
:param nml2_doc: NeuroMLDocument object
:returns: None
"""
all_channels = (
list(nml2_doc.ion_channel_hhs.__iter__())
+ list(nml2_doc.ion_channel.__iter__())
+ list(nml2_doc.ion_channel_v_shifts.__iter__())
)
for achannel in all_channels:
determined_gates = []
undetermined_gates = getattr(achannel, "gates", [])
for gate in undetermined_gates:
new_typed_gate = create_new_typed_gate(gate)
if new_typed_gate:
achannel.add(new_typed_gate)
determined_gates.append(gate)
for d_gate in determined_gates:
undetermined_gates.remove(d_gate)


def main():
if len(sys.argv) != 2:
print("Please specify the name of the NeuroML2 file...")
Expand Down

0 comments on commit 299d0f7

Please sign in to comment.