Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mypy]
ignore_missing_imports = True
6 changes: 2 additions & 4 deletions examples/Vm_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
from pyneuroml.lems.LEMSSimulation import LEMSSimulation
import neuroml as nml

from pyneuroml.pynml import print_comment_v


def generate_Vm_vs_time_plot(nml2_file,
cell_id,
Expand All @@ -28,8 +26,8 @@ def generate_Vm_vs_time_plot(nml2_file,
include_included=True):

ref = "Test"
print_comment_v("Generating Vm(mV) vs Time(ms) plot for cell %s in %s using %s (Inj %snA / %sms dur after %sms delay)" %
(cell_id, nml2_file, simulator, inj_amp_nA, inj_dur_ms, delay_ms))
pynml.print_comment("Generating Vm(mV) vs Time(ms) plot for cell %s in %s using %s (Inj %snA / %sms dur after %sms delay)" %
(cell_id, nml2_file, simulator, inj_amp_nA, inj_dur_ms, delay_ms))

sim_id = 'Vm_%s' % ref
duration = sim_dur_ms
Expand Down
12 changes: 11 additions & 1 deletion pyneuroml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@

import logging

__version__ = '0.5.13'

JNEUROML_VERSION = '0.11.0'

# Define a logger for the package
logging.basicConfig(format="pyNeuroML >>> %(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.WARN)
logger = logging.getLogger(__name__)
logger.setLevel(logging.WARN)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('pyNeuroML >>> %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
8 changes: 4 additions & 4 deletions pyneuroml/analysis/ChannelDensityPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import pprint

from pyneuroml.pynml import get_value_in_si, print_comment_v, read_neuroml2_file
from pyneuroml.pynml import get_value_in_si, print_comment, read_neuroml2_file
from pyneuroml.analysis.NML2ChannelAnalysis import get_ion_color
from neuroml import Cell, Cell2CaPools

Expand Down Expand Up @@ -105,7 +105,7 @@ def generate_channel_density_plots(nml2_file, text_densities=False, passives_ere
for cell in cell_elements:
info = {}
all_info[cell.id] = info
print_comment_v("Extracting channel density info from %s" % cell.id)
print_comment("Extracting channel density info from %s" % cell.id)
sb = ''
ions = {}
maxes = {}
Expand All @@ -131,7 +131,7 @@ def generate_channel_density_plots(nml2_file, text_densities=False, passives_ere

for cd in cds:
dens_si = get_value_in_si(cd.cond_density)
print_comment_v("cd: %s, ion_channel: %s, ion: %s, density: %s (SI: %s)" % (cd.id, cd.ion_channel, cd.ion, cd.cond_density, dens_si))
print_comment("cd: %s, ion_channel: %s, ion: %s, density: %s (SI: %s)" % (cd.id, cd.ion_channel, cd.ion, cd.cond_density, dens_si))

ions[cd.ion_channel] = cd.ion
erev_V = get_value_in_si(cd.erev) if hasattr(cd, 'erev') else None
Expand Down Expand Up @@ -217,7 +217,7 @@ def generate_channel_density_plots(nml2_file, text_densities=False, passives_ere
sf = open(svg_file, 'w')
sf.write(sb)
sf.close()
print_comment_v("Written to %s" % os.path.abspath(svg_file))
print_comment("Written to %s" % os.path.abspath(svg_file))

pp.pprint(all_info)

Expand Down
50 changes: 25 additions & 25 deletions pyneuroml/analysis/ChannelHelper.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
from math import exp
from pyneuroml.pynml import get_value_in_si, print_comment_v
from pyneuroml.pynml import get_value_in_si, print_comment


def evaluate_HHExpLinearRate(rate, midpoint, scale, v):
'''
Helper for putting values into HHExpLinearRate,
see also https://www.neuroml.org/NeuroML2CoreTypes/Channels.html#HHExpLinearRate
Helper for putting values into HHExpLinearRate, see also
https://docs.neuroml.org/Userdocs/Schemas/Channels.html#hhexplinearrate
'''
rate_si = get_value_in_si(rate)
midpoint_si = get_value_in_si(midpoint)
scale_si = get_value_in_si(scale)
v_si = get_value_in_si(v)

print_comment_v('Evaluating: rate * ((v - (midpoint))/scale) / ( 1 - exp(-1 * (v - (midpoint)) / scale)) ')
print_comment_v(' %s * ((v - (%s))/%s) / ( 1 - exp(-1 * (v - (%s)) / %s)) for v = %s' % (rate, midpoint, scale, midpoint, scale, v))
print_comment_v(' %s * ((%s - (%s))/%s) / ( 1 - exp(-1 * (%s - (%s)) / %s)) ' % (rate_si, v_si, midpoint_si, scale_si, v_si, midpoint_si, scale_si))
print_comment_v(' <... type="HHExpLinearRate" rate="%s" midpoint="%s" scale="%s" />' % (rate, midpoint, scale))
print_comment('Evaluating: rate * ((v - (midpoint))/scale) / ( 1 - exp(-1 * (v - (midpoint)) / scale)) ')
print_comment(' %s * ((v - (%s))/%s) / ( 1 - exp(-1 * (v - (%s)) / %s)) for v = %s' % (rate, midpoint, scale, midpoint, scale, v))
print_comment(' %s * ((%s - (%s))/%s) / ( 1 - exp(-1 * (%s - (%s)) / %s)) ' % (rate_si, v_si, midpoint_si, scale_si, v_si, midpoint_si, scale_si))
print_comment(' <... type="HHExpLinearRate" rate="%s" midpoint="%s" scale="%s" />' % (rate, midpoint, scale))
r = rate_si * ((v_si - (midpoint_si)) / scale_si) / (1 - exp(-(v_si - (midpoint_si)) / scale_si))
print_comment_v(' = %s per_s' % r)
print_comment_v(' = %s per_ms' % (r / 1000.))
print_comment(' = %s per_s' % r)
print_comment(' = %s per_ms' % (r / 1000.))


def evaluate_HHSigmoidRate(rate, midpoint, scale, v):
'''
Helper for putting values into HHSigmoidRate,
see also https://www.neuroml.org/NeuroML2CoreTypes/Channels.html#HHSigmoidRate
Helper for putting values into HHSigmoidRate, see also
https://docs.neuroml.org/Userdocs/Schemas/Channels.html#hhsigmoidrate
'''
rate_si = get_value_in_si(rate)
midpoint_si = get_value_in_si(midpoint)
scale_si = get_value_in_si(scale)
v_si = get_value_in_si(v)

print_comment_v('Evaluating: rate / (1 + exp(-1 * (v - midpoint)/scale)) ')
print_comment_v(' %s / ( 1 + exp(-1 * (v - (%s)) / %s)) for v = %s' % (rate, midpoint, scale, v))
print_comment_v(' %s / ( 1 + exp(-1 * (%s - (%s)) / %s)) ' % (rate_si, v_si, midpoint_si, scale_si))
print_comment_v(' <... type="HHSigmoidRate" rate="%s" midpoint="%s" scale="%s" />' % (rate, midpoint, scale))
print_comment('Evaluating: rate / (1 + exp(-1 * (v - midpoint)/scale)) ')
print_comment(' %s / ( 1 + exp(-1 * (v - (%s)) / %s)) for v = %s' % (rate, midpoint, scale, v))
print_comment(' %s / ( 1 + exp(-1 * (%s - (%s)) / %s)) ' % (rate_si, v_si, midpoint_si, scale_si))
print_comment(' <... type="HHSigmoidRate" rate="%s" midpoint="%s" scale="%s" />' % (rate, midpoint, scale))
r = rate_si / (1 + exp(-1 * (v_si - midpoint_si) / scale_si))
print_comment_v(' = %s per_s' % r)
print_comment_v(' = %s per_ms' % (r / 1000.))
print_comment(' = %s per_s' % r)
print_comment(' = %s per_ms' % (r / 1000.))


def evaluate_HHExpRate(rate, midpoint, scale, v):
'''
Helper for putting values into HHExpRate,
see also https://www.neuroml.org/NeuroML2CoreTypes/Channels.html#HHExpRate
Helper for putting values into HHExpRate, see also
https://docs.neuroml.org/Userdocs/Schemas/Channels.html#hhexprate
'''
rate_si = get_value_in_si(rate)
midpoint_si = get_value_in_si(midpoint)
scale_si = get_value_in_si(scale)
v_si = get_value_in_si(v)

print_comment_v('Evaluating: rate * exp( (v - midpoint) / scale) ')
print_comment_v(' %s * exp( (v - (%s)) / %s) for v = %s' % (rate, midpoint, scale, v))
print_comment_v(' %s * exp( (%s - (%s)) / %s) ' % (rate_si, v_si, midpoint_si, scale_si))
print_comment_v(' <... type="HHExpRate" rate="%s" midpoint="%s" scale="%s" />' % (rate, midpoint, scale))
print_comment('Evaluating: rate * exp( (v - midpoint) / scale) ')
print_comment(' %s * exp( (v - (%s)) / %s) for v = %s' % (rate, midpoint, scale, v))
print_comment(' %s * exp( (%s - (%s)) / %s) ' % (rate_si, v_si, midpoint_si, scale_si))
print_comment(' <... type="HHExpRate" rate="%s" midpoint="%s" scale="%s" />' % (rate, midpoint, scale))
r = rate_si * exp((v_si - midpoint_si) / scale_si)
print_comment_v(' = %s per_s' % r)
print_comment_v(' = %s per_ms' % (r / 1000.))
print_comment(' = %s per_s' % r)
print_comment(' = %s per_ms' % (r / 1000.))
21 changes: 12 additions & 9 deletions pyneuroml/analysis/NML2ChannelAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
import argparse
import pprint
import re
import logging

import airspeed
import matplotlib.pyplot as plt

from pyneuroml.pynml import run_lems_with_jneuroml, print_comment, \
print_comment_v, read_neuroml2_file
read_neuroml2_file


logger = logging.getLogger(__name__)
pp = pprint.PrettyPrinter(depth=4)

OUTPUT_DIR = os.getcwd()
Expand Down Expand Up @@ -255,7 +258,7 @@ def generate_lems_channel_analyser(channel_file, channel, min_target_voltage,

print_comment(("Generating LEMS file to investigate %s in %s, %smV->%smV, "
"%sdegC") % (channel, channel_file, min_target_voltage,
max_target_voltage, temperature), verbose)
max_target_voltage, temperature))

target_voltages = []
v = min_target_voltage
Expand Down Expand Up @@ -331,7 +334,7 @@ def get_includes_from_channel_file(channel_file):
def process_channel_file(channel_file, a):
# Get name of channel mechanism to test
if a.v:
print_comment_v("Going to test channel from file: " + channel_file)
logger.info("Going to test channel from file: " + channel_file)

if not os.path.isfile(channel_file):
raise IOError("File could not be found: %s!\n" % channel_file)
Expand All @@ -341,7 +344,7 @@ def process_channel_file(channel_file, a):
channels_info = []
for channel in channels:
if len(get_channel_gates(channel)) == 0:
print_comment_v("Skipping %s in %s as it has no channels (probably passive conductance)" % (channel.id, channel_file))
logger.warning("Skipping %s in %s as it has no channels (probably passive conductance)" % (channel.id, channel_file))
else:
new_lems_file = make_lems_file(channel, a)
if not a.norun:
Expand Down Expand Up @@ -397,7 +400,7 @@ def make_lems_file(channel, a):
lf.write(lems_content)
lf.close()
if a.v:
print_comment_v("Written generated LEMS file to %s\n" % new_lems_file)
logger.info("Written generated LEMS file to %s\n" % new_lems_file)
return new_lems_file


Expand Down Expand Up @@ -519,7 +522,7 @@ def compute_iv_curve(channel, a, results, grid=True):
t_start = a.clamp_delay / 1000.0
t_steady_end = end_time_ms / 1000.0

print_comment_v('Looking at holding voltage %s V, and currents between times %s s and %s s' % (voltage, t_start, t_steady_end))
logger.info('Looking at holding voltage %s V, and currents between times %s s and %s s' % (voltage, t_start, t_steady_end))

for index in range(len(results['t'])):
i = results[r][index]
Expand Down Expand Up @@ -621,7 +624,7 @@ def make_html_file(info):
lf = open(new_html_file, 'w')
lf.write(merged)
lf.close()
print_comment_v('Written HTML info to: %s' % new_html_file)
print_comment('Written HTML info to: %s' % new_html_file)


def make_md_file(info):
Expand All @@ -631,7 +634,7 @@ def make_md_file(info):
lf = open(new_md_file, 'w')
lf.write(merged)
lf.close()
print_comment_v('Written Markdown info to: %s' % new_md_file)
print_comment('Written Markdown info to: %s' % new_md_file)


def build_namespace(a=None, **kwargs):
Expand Down Expand Up @@ -704,7 +707,7 @@ def run(a=None, **kwargs):
other_chan_files.append(channel_file)

channel_files = na_chan_files + k_chan_files + ca_chan_files + other_chan_files
print_comment_v("\nAnalysing channels from files: %s\n" % channel_files)
print_comment("\nAnalysing channels from files: %s\n" % channel_files)

for channel_file in channel_files:
channels_info = process_channel_file(channel_file, a)
Expand Down
28 changes: 15 additions & 13 deletions pyneuroml/analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import math
import os
import logging

from pyneuroml import pynml
from pyneuroml.lems.LEMSSimulation import LEMSSimulation
from pyneuroml.lems import generate_lems_file_for_neuroml
import neuroml as nml

from pyneuroml.pynml import print_comment_v, print_comment
from pyneuroml.lems import generate_lems_file_for_neuroml
import math
import os

logger = logging.getLogger(__name__)


def generate_current_vs_frequency_curve(
Expand Down Expand Up @@ -51,7 +54,7 @@ def generate_current_vs_frequency_curve(
verbose=False
):

print_comment("Running generate_current_vs_frequency_curve() on %s (%s)" % (nml2_file, os.path.abspath(nml2_file)), verbose)
logger.info("Running generate_current_vs_frequency_curve() on %s (%s)" % (nml2_file, os.path.abspath(nml2_file)))
from pyelectro.analysis import max_min
from pyelectro.analysis import mean_spike_frequency
import numpy as np
Expand All @@ -78,8 +81,8 @@ def generate_current_vs_frequency_curve(

stim_info = '(%snA->%snA; %s steps of %snA; %sms)' % (start_amp_nA, end_amp_nA, len(stims), step_nA, total_duration)

print_comment_v("Generating an IF curve for cell %s in %s using %s %s" %
(cell_id, nml2_file, simulator, stim_info))
pynml.print_comment("Generating an IF curve for cell %s in %s using %s %s" %
(cell_id, nml2_file, simulator, stim_info))

number_cells = len(stims)
pop = nml.Population(id="population_of_%s" % cell_id,
Expand Down Expand Up @@ -131,7 +134,7 @@ def generate_current_vs_frequency_curve(

lems_file_name = ls.save_to_file()

print_comment("Written LEMS file %s (%s)" % (lems_file_name, os.path.abspath(lems_file_name)), verbose)
pynml.print_comment("Written LEMS file %s (%s)" % (lems_file_name, os.path.abspath(lems_file_name)))

if simulator == "jNeuroML":
results = pynml.run_lems_with_jneuroml(lems_file_name,
Expand All @@ -158,7 +161,7 @@ def generate_current_vs_frequency_curve(
else:
raise Exception("Sorry, cannot yet run current vs frequency analysis using simulator %s" % simulator)

print_comment("Completed run in simulator %s (results: %s)" % (simulator, results.keys()), verbose)
pynml.print_comment("Completed run in simulator %s (results: %s)" % (simulator, results.keys()))

# print(results.keys())
times_results = []
Expand Down Expand Up @@ -186,7 +189,7 @@ def generate_current_vs_frequency_curve(
freq = 1000 * count / float(analysis_duration)

mean_freq = mean_spike_frequency(spike_times)
# print("--- %s nA, spike times: %s, mean_spike_frequency: %f, freq (%fms -> %fms): %f"%(stims[i],spike_times, mean_freq, analysis_delay, analysis_duration+analysis_delay, freq))
logger.debug("--- %s nA, spike times: %s, mean_spike_frequency: %f, freq (%fms -> %fms): %f" % (stims[i], spike_times, mean_freq, analysis_delay, analysis_duration + analysis_delay, freq))
if_results[stims[i]] = freq

if freq == 0:
Expand Down Expand Up @@ -324,8 +327,7 @@ def analyse_spiketime_vs_dt(nml2_file,
dts = list(np.sort(dts))

for dt in dts:
if verbose:
print_comment_v(" == Generating simulation for dt = %s ms" % dt)
logger.info(" == Generating simulation for dt = %s ms" % dt)
ref = str("Sim_dt_%s" % dt).replace('.', '_')
lems_file_name = "LEMS_%s.xml" % ref
generate_lems_file_for_neuroml(ref,
Expand All @@ -344,7 +346,7 @@ def analyse_spiketime_vs_dt(nml2_file,
if simulator == 'jNeuroML_NEURON':
results = pynml.run_lems_with_jneuroml_neuron(lems_file_name, nogui=True, load_saved_data=True, plot=False, verbose=verbose)

print("Results reloaded: %s" % results.keys())
pynml.print_comment("Results reloaded: %s" % results.keys())
all_results[dt] = results

xs = []
Expand Down
2 changes: 1 addition & 1 deletion pyneuroml/lems/LEMSSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def save_to_file(self, file_name=None):
lems_file = open(file_name, 'w')
lems_file.write(self.to_xml())
lems_file.close()
print_comment("Written LEMS Simulation %s to file: %s" % (self.lems_info['sim_id'], file_name), True)
print_comment("Written LEMS Simulation %s to file: %s" % (self.lems_info['sim_id'], file_name))

return file_name

Expand Down
Loading