本文整理汇总了Python中pyneuroml.pynml.print_comment_v函数的典型用法代码示例。如果您正苦于以下问题:Python print_comment_v函数的具体用法?Python print_comment_v怎么用?Python print_comment_v使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print_comment_v函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: export_to_neuroml1
def export_to_neuroml1(hoc_file, nml1_file_name, level=1, validate=True):
if not (level == 1 or level == 2):
print_comment_v("Only options for Levels in NeuroMLv1.8.1 are 1 or 2")
return None
from neuron import *
from nrn import *
h.load_file(hoc_file)
print_comment_v("Loaded NEURON file: %s" % hoc_file)
h.load_file("mview.hoc")
h("objref mv")
h("mv = new ModelView()")
h.load_file("%s/mview_neuroml1.hoc" % (os.path.dirname(__file__)))
h("objref mvnml1")
h("mvnml1 = new ModelViewNeuroML1(mv)")
h.mvnml1.exportNeuroML(nml1_file_name, level)
if validate:
validate_neuroml1(nml1_file_name)
示例2: process_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)
if not os.path.isfile(channel_file):
raise IOError("File could not be found: %s!\n" % channel_file)
channels = get_channels_from_channel_file(channel_file)
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))
else:
new_lems_file = make_lems_file(channel,a)
if not a.norun:
results = run_lems_file(new_lems_file,a)
if a.iv_curve:
iv_data = compute_iv_curve(channel,a,results)
else:
iv_data = None
if not a.nogui and not a.norun:
plot_channel(channel,a,results,iv_data=iv_data)
channel_info = {key:getattr(channel,key) for key in ['id','file','notes', 'species']}
channel_info['expression'] = get_conductance_expression(channel)
channel_info['ion_color'] = get_ion_color(channel.species)
channels_info.append(channel_info)
return channels_info
示例3: make_lems_file
def make_lems_file(channel, a):
gates = get_channel_gates(channel)
lems_content = generate_lems_channel_analyser(
channel.file,
channel.id,
a.min_v,
a.step_target_voltage,
a.max_v,
a.clamp_delay,
a.clamp_duration,
a.clamp_base_voltage,
a.duration,
a.erev,
gates,
a.temperature,
a.ca_conc,
a.iv_curve,
a.dat_suffix,
)
new_lems_file = os.path.join(OUTPUT_DIR, "LEMS_Test_%s.xml" % channel.id)
lf = open(new_lems_file, "w")
lf.write(lems_content)
lf.close()
if a.v:
print_comment_v("Written generated LEMS file to %s\n" % new_lems_file)
return new_lems_file
示例4: make_html_file
def make_html_file(info):
merged = merge_with_template(info, HTML_TEMPLATE_FILE)
html_dir = make_overview_dir()
new_html_file = os.path.join(html_dir,'ChannelInfo.html')
lf = open(new_html_file, 'w')
lf.write(merged)
lf.close()
print_comment_v('Written HTML info to: %s' % new_html_file)
示例5: make_md_file
def make_md_file(info):
merged = merge_with_template(info, MD_TEMPLATE_FILE)
md_dir = make_overview_dir()
new_md_file = os.path.join(md_dir,'README.md')
lf = open(new_md_file, 'w')
lf.write(merged)
lf.close()
print_comment_v('Written Markdown info to: %s' % new_md_file)
示例6: merge_with_template
def merge_with_template(info):
templfile = "TEMPLATE.channel.nml"
if not os.path.isfile(templfile):
templfile = os.path.join(os.path.dirname(sys.argv[0]), templfile)
print_comment_v("Merging with template %s"%templfile)
with open(templfile) as f:
templ = airspeed.Template(f.read())
return templ.merge(info)
示例7: include_neuroml2_file
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))
self.lems_info['include_files'].append(nml2_file_name)
if include_included:
cell = read_neuroml2_file(full_path)
for include in cell.includes:
self.include_neuroml2_file(include.href, include_included=True, relative_to_dir=base_path)
示例8: check_brackets
def check_brackets(line, bracket_depth):
if len(line)>0:
bracket_depth0 = bracket_depth
for c in line:
if c=='{':
bracket_depth+=1
elif c=='}':
bracket_depth-=1
if bracket_depth0 !=bracket_depth:
print_comment_v(" <%s> moved bracket %i -> %i"%(line, bracket_depth0,bracket_depth))
return bracket_depth
示例9: generate_lems_channel_analyser
def generate_lems_channel_analyser(channel_file, channel, min_target_voltage,
step_target_voltage, max_target_voltage, clamp_delay,
clamp_duration, clamp_base_voltage, duration, erev,
gates, temperature, ca_conc, iv_curve, dat_suffix=''):
print_comment_v("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
while v <= max_target_voltage:
target_voltages.append(v)
v+=step_target_voltage
target_voltages_map = []
for t in target_voltages:
fract = float(target_voltages.index(t)) / (len(target_voltages)-1)
info = {}
info["v"] = t
info["v_str"] = str(t).replace("-", "min")
info["col"] = get_colour_hex(fract)
target_voltages_map.append(info)
includes = get_includes_from_channel_file(channel_file)
includes_relative = []
base_path = os.path.dirname(channel_file)
for inc in includes:
includes_relative.append(os.path.abspath(base_path+'/'+inc))
model = {"channel_file": channel_file,
"includes": includes_relative,
"channel": channel,
"target_voltages" : target_voltages_map,
"clamp_delay": clamp_delay,
"clamp_duration": clamp_duration,
"clamp_base_voltage": clamp_base_voltage,
"min_target_voltage": min_target_voltage,
"max_target_voltage": max_target_voltage,
"duration": duration,
"erev": erev,
"gates": gates,
"temperature": temperature,
"ca_conc": ca_conc,
"iv_curve": iv_curve,
"dat_suffix": dat_suffix}
#pp.pprint(model)
merged = merge_with_template(model, TEMPLATE_FILE)
return merged
示例10: convert_to_swc
def convert_to_swc(nml_file_name):
global line_count
global line_index_vs_distals
global line_index_vs_proximals
# Reset
line_count = 1
line_index_vs_distals = {}
line_index_vs_proximals = {}
base_dir = os.path.dirname(os.path.realpath(nml_file_name))
nml_doc = pynml.read_neuroml2_file(nml_file_name, include_includes=True, verbose=False, optimized=True)
lines = []
for cell in nml_doc.cells:
swc_file_name = '%s/%s.swc' % (base_dir, cell.id)
swc_file = open(swc_file_name, 'w')
print_comment_v("Converting cell %s as found in NeuroML doc %s to SWC..." % (cell.id, nml_file_name))
lines_sg, seg_ids = _get_lines_for_seg_group(cell, 'soma_group', 1)
soma_seg_count = len(seg_ids)
lines += lines_sg
lines_sg, seg_ids = _get_lines_for_seg_group(cell, 'dendrite_group', 3)
dend_seg_count = len(seg_ids)
lines += lines_sg
lines_sg, seg_ids = _get_lines_for_seg_group(cell, 'axon_group', 2)
axon_seg_count = len(seg_ids)
lines += lines_sg
if not len(cell.morphology.segments) == soma_seg_count + dend_seg_count + axon_seg_count:
raise Exception("The numbers of the segments in groups: soma_group+dendrite_group+axon_group (%i), is not the same as total number of segments (%s)! All bets are off!" % (soma_seg_count + dend_seg_count + axon_seg_count, len(cell.morphology.segments)))
for i in range(len(lines)):
l = lines[i]
swc_line = '%s' % (l)
print(swc_line)
swc_file.write('%s\n' % swc_line)
swc_file.close()
print("Written to %s" % swc_file_name)
示例11: run
def run(a=None,**kwargs):
a = build_namespace(a,**kwargs)
#if (not a.nogui) or a.html:
# print('mpl')
info = {'info': ("Channel information at: "
"T = %s degC, "
"E_rev = %s mV, "
"[Ca2+] = %s mM") % (a.temperature, a.erev, a.ca_conc),
'channels': []}
na_chan_files = []
k_chan_files = []
ca_chan_files = []
other_chan_files = []
if len(a.channel_files) > 0:
for channel_file in a.channel_files:
channels = get_channels_from_channel_file(channel_file)
#TODO look past 1st channel...
if channels[0].species == 'na':
na_chan_files.append(channel_file)
elif channels[0].species == 'k':
k_chan_files.append(channel_file)
elif channels[0].species == 'ca':
ca_chan_files.append(channel_file)
else:
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)
for channel_file in channel_files:
channels_info = process_channel_file(channel_file,a)
for channel_info in channels_info:
info['channels'].append(channel_info)
if not a.nogui and not a.html and not a.md:
plt.show()
else:
if a.html:
make_html_file(info)
if a.md:
make_md_file(info)
示例12: run
def run(self,candidates,parameters):
"""
Run simulation for each candidate
This run method will loop through each candidate and run the simulation
corresponding to it's parameter values. It will populate an array called
traces with the resulting voltage traces for the simulation and return it.
"""
traces = []
for candidate in candidates:
sim_var = dict(zip(parameters,candidate))
print_comment_v('\n\n - RUN %i; variables: %s\n'%(self.count,sim_var))
self.count+=1
t,v = self.run_individual(sim_var)
traces.append([t,v])
return traces
示例13: read_sonata_spikes_hdf5_file
def read_sonata_spikes_hdf5_file(file_name):
full_path = os.path.abspath(file_name)
pynml.print_comment_v("Loading SONATA spike times from: %s (%s)"%(file_name,full_path))
import tables # pytables for HDF5 support
h5file=tables.open_file(file_name,mode='r')
pynml.print_comment_v("Opened HDF5 file: %s; sorting=%s"%(h5file.filename,h5file.root.spikes._v_attrs.sorting))
gids = h5file.root.spikes.gids
timestamps = h5file.root.spikes.timestamps
ids_times = {}
count=0
max_t = -1*sys.float_info.max
min_t = sys.float_info.max
for i in range(len(gids)):
id = gids[i]
t = timestamps[i]
max_t = max(max_t,t)
min_t = min(min_t,t)
if not id in ids_times:
ids_times[id] = []
ids_times[id].append(t)
count+=1
ids = ids_times.keys()
h5file.close()
pynml.print_comment_v("Loaded %s spiketimes, ids (%s -> %s) times (%s -> %s)"%(count,min(ids), max(ids),min_t,max_t))
return ids_times
示例14: export_to_neuroml2
def export_to_neuroml2(hoc_or_python_file,
nml2_file_name,
includeBiophysicalProperties=True,
separateCellFiles=False,
known_rev_potentials={},
validate=True):
from neuron import *
from nrn import *
if hoc_or_python_file is not None:
if hoc_or_python_file.endswith(".py"):
print_comment_v("***************\nImporting Python scripts not yet implemented...\n***************")
else:
if not os.path.isfile(hoc_or_python_file):
print_comment_v("***************\nProblem importing file %s (%s)..\n***************"%(hoc_or_python_file, os.path.abspath(hoc_or_python_file)))
h.load_file(1, hoc_or_python_file) # Using 1 to force loading of the file, in case file with same name was loaded before...
else:
print_comment_v("hoc_or_python_file variable is None; exporting what's currently in memory...")
for ion in known_rev_potentials.keys():
set_erev_for_mechanism(ion,known_rev_potentials[ion])
print_comment_v("Loaded NEURON file: %s"%hoc_or_python_file)
h.load_file("mview.hoc")
h('objref mv')
h('mv = new ModelView(0)')
h.load_file("%s/mview_neuroml2.hoc"%(os.path.dirname(__file__)))
h('objref mvnml')
h('mvnml = new ModelViewNeuroML2(mv)')
nml2_level = 2 if includeBiophysicalProperties else 1
h.mvnml.exportNeuroML2(nml2_file_name, nml2_level, int(separateCellFiles))
if validate:
validate_neuroml2(nml2_file_name)
h('mv.destroy()')
示例15: go
def go(self):
lems_file_name = 'LEMS_%s.xml'%(self.reference)
generate_lems_file_for_neuroml(self.reference,
self.neuroml_file,
self.target,
self.sim_time,
self.dt,
lems_file_name = lems_file_name,
target_dir = self.generate_dir)
pynml.print_comment_v("Running a simulation of %s ms with timestep %s ms: %s"%(self.sim_time, self.dt, lems_file_name))
self.already_run = True
start = time.time()
if self.simulator == 'jNeuroML':
results = pynml.run_lems_with_jneuroml(lems_file_name,
nogui=True,
load_saved_data=True,
plot=False,
exec_in_dir = self.generate_dir,
verbose=False)
elif self.simulator == 'jNeuroML_NEURON':
results = pynml.run_lems_with_jneuroml_neuron(lems_file_name,
nogui=True,
load_saved_data=True,
plot=False,
exec_in_dir = self.generate_dir,
verbose=False)
else:
pynml.print_comment_v('Unsupported simulator: %s'%self.simulator)
exit()
secs = time.time()-start
pynml.print_comment_v("Ran simulation in %s in %f seconds (%f mins)\n\n"%(self.simulator, secs, secs/60.0))
self.t = [t*1000 for t in results['t']]
self.volts = {}
for key in results.keys():
if key != 't':
self.volts[key] = [v*1000 for v in results[key]]