Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ jobs:
- name: Install package
run: |
python -m pip install --upgrade pip
pip install flake8
pip install flake8 pytest
pip install .
- name: Lint with flake8
run: |
flake8 . --count --exit-zero --show-source --max-line-length=127 --statistics
- name: Run tests
run: |
pytest .
pynml -h
./test-ghactions.sh
- name: Lint with flake8
run: |
flake8 . --count --exit-zero --show-source --max-line-length=127 --statistics
8 changes: 6 additions & 2 deletions examples/Vm_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
'''

import sys
import logging

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


logger = logging.getLogger(__name__)


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

ref = "Test"
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))
logger.info("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
4 changes: 2 additions & 2 deletions pyneuroml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
# 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)
logger.setLevel(logging.INFO)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setLevel(logging.INFO)
formatter = logging.Formatter('pyNeuroML >>> %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
12 changes: 8 additions & 4 deletions pyneuroml/analysis/ChannelDensityPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@

import os
import math
import logging

import pprint

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


logger = logging.getLogger(__name__)


pp = pprint.PrettyPrinter(depth=6)

height = 18
Expand Down Expand Up @@ -105,7 +109,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("Extracting channel density info from %s" % cell.id)
logger.info("Extracting channel density info from %s" % cell.id)
sb = ''
ions = {}
maxes = {}
Expand All @@ -131,7 +135,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("cd: %s, ion_channel: %s, ion: %s, density: %s (SI: %s)" % (cd.id, cd.ion_channel, cd.ion, cd.cond_density, dens_si))
logger.info("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 +221,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("Written to %s" % os.path.abspath(svg_file))
logger.info("Written to %s" % os.path.abspath(svg_file))

pp.pprint(all_info)

Expand Down
42 changes: 23 additions & 19 deletions pyneuroml/analysis/ChannelHelper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from math import exp
from pyneuroml.pynml import get_value_in_si, print_comment
from pyneuroml.pynml import get_value_in_si
import logging


logger = logging.getLogger(__name__)


def evaluate_HHExpLinearRate(rate, midpoint, scale, v):
Expand All @@ -12,13 +16,13 @@ def evaluate_HHExpLinearRate(rate, midpoint, scale, v):
scale_si = get_value_in_si(scale)
v_si = get_value_in_si(v)

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))
logger.info('Evaluating: rate * ((v - (midpoint))/scale) / ( 1 - exp(-1 * (v - (midpoint)) / scale)) ')
logger.info(' %s * ((v - (%s))/%s) / ( 1 - exp(-1 * (v - (%s)) / %s)) for v = %s' % (rate, midpoint, scale, midpoint, scale, v))
logger.info(' %s * ((%s - (%s))/%s) / ( 1 - exp(-1 * (%s - (%s)) / %s)) ' % (rate_si, v_si, midpoint_si, scale_si, v_si, midpoint_si, scale_si))
logger.info(' <... 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(' = %s per_s' % r)
print_comment(' = %s per_ms' % (r / 1000.))
logger.info(' = %s per_s' % r)
logger.info(' = %s per_ms' % (r / 1000.))


def evaluate_HHSigmoidRate(rate, midpoint, scale, v):
Expand All @@ -31,13 +35,13 @@ def evaluate_HHSigmoidRate(rate, midpoint, scale, v):
scale_si = get_value_in_si(scale)
v_si = get_value_in_si(v)

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))
logger.info('Evaluating: rate / (1 + exp(-1 * (v - midpoint)/scale)) ')
logger.info(' %s / ( 1 + exp(-1 * (v - (%s)) / %s)) for v = %s' % (rate, midpoint, scale, v))
logger.info(' %s / ( 1 + exp(-1 * (%s - (%s)) / %s)) ' % (rate_si, v_si, midpoint_si, scale_si))
logger.info(' <... 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(' = %s per_s' % r)
print_comment(' = %s per_ms' % (r / 1000.))
logger.info(' = %s per_s' % r)
logger.info(' = %s per_ms' % (r / 1000.))


def evaluate_HHExpRate(rate, midpoint, scale, v):
Expand All @@ -50,10 +54,10 @@ def evaluate_HHExpRate(rate, midpoint, scale, v):
scale_si = get_value_in_si(scale)
v_si = get_value_in_si(v)

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))
logger.info('Evaluating: rate * exp( (v - midpoint) / scale) ')
logger.info(' %s * exp( (v - (%s)) / %s) for v = %s' % (rate, midpoint, scale, v))
logger.info(' %s * exp( (%s - (%s)) / %s) ' % (rate_si, v_si, midpoint_si, scale_si))
logger.info(' <... type="HHExpRate" rate="%s" midpoint="%s" scale="%s" />' % (rate, midpoint, scale))
r = rate_si * exp((v_si - midpoint_si) / scale_si)
print_comment(' = %s per_s' % r)
print_comment(' = %s per_ms' % (r / 1000.))
logger.info(' = %s per_s' % r)
logger.info(' = %s per_ms' % (r / 1000.))
15 changes: 7 additions & 8 deletions pyneuroml/analysis/NML2ChannelAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import airspeed
import matplotlib.pyplot as plt

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


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -256,9 +255,9 @@ def generate_lems_channel_analyser(channel_file, channel, min_target_voltage,
gates, temperature, ca_conc, iv_curve, scale_dt=1,
dat_suffix='', verbose=True):

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

target_voltages = []
v = min_target_voltage
Expand Down Expand Up @@ -624,7 +623,7 @@ def make_html_file(info):
lf = open(new_html_file, 'w')
lf.write(merged)
lf.close()
print_comment('Written HTML info to: %s' % new_html_file)
logger.info('Written HTML info to: %s' % new_html_file)


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


def build_namespace(a=None, **kwargs):
Expand Down Expand Up @@ -707,7 +706,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("\nAnalysing channels from files: %s\n" % channel_files)
logger.info("\nAnalysing channels from files: %s\n" % channel_files)

for channel_file in channel_files:
channels_info = process_channel_file(channel_file, a)
Expand Down
10 changes: 5 additions & 5 deletions pyneuroml/analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,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)

pynml.print_comment("Generating an IF curve for cell %s in %s using %s %s" %
(cell_id, nml2_file, simulator, stim_info))
logger.info("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 @@ -134,7 +134,7 @@ def generate_current_vs_frequency_curve(

lems_file_name = ls.save_to_file()

pynml.print_comment("Written LEMS file %s (%s)" % (lems_file_name, os.path.abspath(lems_file_name)))
logger.info("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 @@ -161,7 +161,7 @@ def generate_current_vs_frequency_curve(
else:
raise Exception("Sorry, cannot yet run current vs frequency analysis using simulator %s" % simulator)

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

# print(results.keys())
times_results = []
Expand Down Expand Up @@ -346,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)

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

xs = []
Expand Down
8 changes: 5 additions & 3 deletions pyneuroml/lems/LEMSSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@

import airspeed
import os.path
import logging

from pyneuroml import __version__ as pynml_ver
from neuroml import __version__ as libnml_ver
from pyneuroml.pynml import read_neuroml2_file
from pyneuroml.pynml import read_lems_file
from pyneuroml.pynml import print_comment
from pyneuroml.pynml import get_next_hex_color
import random

logger = logging.getLogger(__name__)


class LEMSSimulation():

Expand Down Expand Up @@ -70,7 +72,7 @@ def set_report_file(self, report_file_name):
def include_neuroml2_file(self, nml2_file_name, include_included=True, relative_to_dir='.'):
full_path = os.path.abspath(relative_to_dir + '/' + nml2_file_name)
base_path = os.path.dirname(full_path)
# print_comment_v("Including in generated LEMS file: %s (%s)"%(nml2_file_name, full_path))
# logger.info_v("Including in generated LEMS file: %s (%s)"%(nml2_file_name, full_path))
if nml2_file_name not in self.lems_info['include_files']:
self.lems_info['include_files'].append(nml2_file_name)

Expand Down Expand Up @@ -165,7 +167,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))
logger.info("Written LEMS Simulation %s to file: %s" % (self.lems_info['sim_id'], file_name))

return file_name

Expand Down
16 changes: 8 additions & 8 deletions pyneuroml/lems/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import shutil
import os
import logging
from pyneuroml.pynml import read_neuroml2_file, get_next_hex_color, print_comment
from pyneuroml.pynml import read_neuroml2_file, get_next_hex_color
import random
import neuroml

Expand Down Expand Up @@ -47,7 +47,7 @@ def generate_lems_file_for_neuroml(sim_id,

file_name_full = '%s/%s' % (target_dir, lems_file_name)

print_comment('Creating LEMS file at: %s for NeuroML 2 file: %s (copy: %s)' % (file_name_full, neuroml_file, copy_neuroml))
logger.info('Creating LEMS file at: %s for NeuroML 2 file: %s (copy: %s)' % (file_name_full, neuroml_file, copy_neuroml))

ls = LEMSSimulation(sim_id, duration, dt, target, simulation_seed=simulation_seed)

Expand Down Expand Up @@ -95,15 +95,15 @@ def generate_lems_file_for_neuroml(sim_id,
if os.path.isfile(include.href):
incl_curr = include.href

print_comment(' - Including %s (located at %s; nml dir: %s), copying to %s' % (include.href, incl_curr, nml_dir, target_dir))
logger.info(' - Including %s (located at %s; nml dir: %s), copying to %s' % (include.href, incl_curr, nml_dir, target_dir))

'''
if not os.path.isfile("%s/%s" % (target_dir, os.path.basename(incl_curr))) and \
not os.path.isfile("%s/%s" % (target_dir, incl_curr)) and \
not os.path.isfile(incl_curr):
shutil.copy(incl_curr, target_dir)
else:
print_comment("No need to copy...")'''
logger.info("No need to copy...")'''

f1 = "%s/%s" % (target_dir, os.path.basename(incl_curr))
f2 = "%s/%s" % (target_dir, incl_curr)
Expand All @@ -121,7 +121,7 @@ def generate_lems_file_for_neuroml(sim_id,
if sub_doc.__class__ == neuroml.nml.nml.NeuroMLDocument:
for include in sub_doc.includes:
incl_curr = '%s/%s' % (sub_dir, include.href)
print_comment(' -- Including %s located at %s' % (include.href, incl_curr))
logger.info(' -- Including %s located at %s' % (include.href, incl_curr))

if not os.path.isfile("%s/%s" % (target_dir, os.path.basename(incl_curr))) and \
not os.path.isfile("%s/%s" % (target_dir, incl_curr)):
Expand Down Expand Up @@ -173,7 +173,7 @@ def generate_lems_file_for_neuroml(sim_id,
size = len(population.instances)

if gen_plots_for_all_v or population.id in gen_plots_for_only_populations:
print_comment('Generating %i plots for %s in population %s' % (size, component, population.id))
logger.info('Generating %i plots for %s in population %s' % (size, component, population.id))

disp0 = 'DispPop__%s' % population.id
ls.create_display(disp0, "Membrane potentials of cells in %s" % population.id, "-90", "50")
Expand All @@ -189,7 +189,7 @@ def generate_lems_file_for_neuroml(sim_id,
ls.add_line_to_display(disp0, "%s[%i]: v" % (population.id, i), quantity, "1mV", get_next_hex_color(my_random))

if gen_saves_for_all_v or population.id in gen_saves_for_only_populations:
print_comment('Saving %i values of %s for %s in population %s' % (size, variable, component, population.id))
logger.info('Saving %i values of %s for %s in population %s' % (size, variable, component, population.id))

of0 = 'Volts_file__%s' % population.id
ls.create_output_file(of0, "%s.%s.%s.dat" % (sim_id, population.id, variable))
Expand All @@ -206,7 +206,7 @@ def generate_lems_file_for_neuroml(sim_id,
quantities_saved.append(quantity)

if gen_spike_saves_for_all_somas or population.id in gen_spike_saves_for_only_populations:
print_comment('Saving spikes in %i somas for %s in population %s' % (size, component, population.id))
logger.info('Saving spikes in %i somas for %s in population %s' % (size, component, population.id))

eof0 = 'Spikes_file__%s' % population.id
ls.create_event_output_file(eof0, "%s.%s.spikes" % (sim_id, population.id), format=spike_time_format)
Expand Down
Loading