def writeTreatments(self, sSim): lj = self.lJust1 trtList = sSim.network.chemSyns self.treatmentFile = "treatments.hoc" trtFileName = os.path.join(self.nrnDirPath, self.nrnDirName, self.treatmentFile) print "TRTFilename: ", trtFileName with open(trtFileName, "w") as tf: tf.write("// create stim objects\n") iClamps = sSim.treatemts.currentInjList nIC = len(iClamps) if nIC == 0: return tf.write("objref stim[" + str(nIC) + "]\n\n") for i in range(len(iClamps)): ic = iClamps[i] stimID = "stim[" + str(i) + "]" tf.write((ic.neuronName + " " + stimID).ljust(lj) + "= new IClamp(0.5)\n") # convert seconds to miliseconds st = float(ic.start) * 1000.0 stop = float(ic.stop) * 1000.0 # duration of the IClamp dur = stop - st tf.write( util.formatedObjectVar(stimID, "del") + "= " + str(st).ljust(lj) + "// (ms)\n") tf.write( util.formatedObjectVar(stimID, "dur") + "= " + str(dur).ljust(lj) + "// (ms)\n") # in SNNAP magnitude of current inject is in nA mag = float(ic.magnitude) tf.write( util.formatedObjectVar(stimID, "amp") + "= " + str(mag).ljust(lj) + "// (nA)\n\n") return
def write_InActF_timeConstant(self, file, vdgObj, ivd): lj = self.lJust1 inactfType = ivd.BType if inactfType == "2": #file.write(util.formatedObjectVar(vdgObj, "B_IV")+ "= "+ ivd.B_IV+ "\n") tBType = ivd.tBType file.write(util.formatedObjectVar(vdgObj, "tB_type")+ "= "+ tBType+ "\n") # convert seconds to ms tB_tx = float(ivd.tB_tx) * 1000.0 file.write(util.formatedObjectVar(vdgObj, "tB_tx")+ "= "+ str(tB_tx).ljust(lj)+ "// (ms)\n") if tBType in ['2', '3']: # convert seconds to ms tB_tn = float(ivd.tB_tn) * 1000.0 file.write(util.formatedObjectVar(vdgObj, "tB_tn")+ "= "+ str(tB_tn).ljust(lj)+ "// (ms)\n") file.write(util.formatedObjectVar(vdgObj, "tB_h1")+ "= "+ (ivd.tB_h1).ljust(lj)+ "// (mV)\n") file.write(util.formatedObjectVar(vdgObj, "tB_s1")+ "= "+ (ivd.tB_s1).ljust(lj)+ "// (mV)\n") file.write(util.formatedObjectVar(vdgObj, "tB_p1")+ "= "+ ivd.tB_p1+ "\n\n") if tBType in ['3']: file.write(util.formatedObjectVar(vdgObj, "tB_h2")+ "= "+ (ivd.tB_h2).ljust(lj)+ "// (mV)\n") file.write(util.formatedObjectVar(vdgObj, "tB_s2")+ "= "+ (ivd.tB_s2).ljust(lj)+ "// (mV)\n") file.write(util.formatedObjectVar(vdgObj, "tB_p2")+ "= "+ ivd.tB_p2+ "\n\n") elif tBType != '1': print "WARNING: Time constant forms other than 1, 2, or 3 are not supported yet!!!" # write steady state ssBType = ivd.ssBType file.write(util.formatedObjectVar(vdgObj, "ssB_type")+ "= "+ ssBType+ "\n") file.write(util.formatedObjectVar(vdgObj, "ssB_h")+ "= "+ (ivd.ssB_h).ljust(lj)+ "// (mV)\n") file.write(util.formatedObjectVar(vdgObj, "ssB_s")+ "= "+ (ivd.ssB_s).ljust(lj)+ "// (mV)\n") file.write(util.formatedObjectVar(vdgObj, "ssB_p")+ "= "+ ivd.ssB_p+ "\n") if ssBType == '2': file.write(util.formatedObjectVar(vdgObj, "ssB_Bn")+ "= "+ ivd.ssB_Bn+ "\n")
def write_InActF_rateConstant(self, file, vdgObj, ivd): lj = self.lJust1 inactfType = ivd.hType if inactfType == "2": file.write(util.formatedObjectVar(vdgObj, "h_L")+ "= 0.001\n") if inactfType == "3": h_L = float(ivd.h_L) / 1000.0 file.write(util.formatedObjectVar(vdgObj, "h_L")+ "= "+str(h_L)+"\n") #file.write(util.formatedObjectVar(vdgObj, "h_L")+ "= "+ ivd.h_L+ "\n") ahType = ivd.ahType file.write(util.formatedObjectVar(vdgObj, "ah_type")+ "= "+ ivd.ahType+ "\n") file.write(util.formatedObjectVar(vdgObj, "ah_A")+ "= "+ ivd.ah_A + "\n") if ahType != '1': file.write(util.formatedObjectVar(vdgObj, "ah_B")+ "= "+ (ivd.ah_B).ljust(lj)+ "// (mV)\n") if ahType != '4' and ahType != '8' and ahType != '9': file.write(util.formatedObjectVar(vdgObj, "ah_C")+ "= "+ (ivd.ah_C).ljust(lj)+ "// (mV)\n") if ahType != '5' and ahType != '6' and ahType != '7': file.write(util.formatedObjectVar(vdgObj, "ah_D")+ "= "+ (ivd.ah_D).ljust(lj)+ "// (mV)\n") bhType = ivd.bhType file.write("\n") file.write(util.formatedObjectVar(vdgObj, "bh_type")+ "= "+ bhType+ "\n") file.write(util.formatedObjectVar(vdgObj, "bh_A")+ "= "+ ivd.bh_A+ "\n") if bhType != '1': file.write(util.formatedObjectVar(vdgObj, "bh_B")+ "= "+ (ivd.bh_B).ljust(lj)+ "// (mV)\n") if bhType != '4' and bhType != '8' and bhType != '9': file.write(util.formatedObjectVar(vdgObj, "bh_C")+ "= "+ (ivd.bh_C).ljust(lj)+ "// (mV)\n") if bhType != '5' and bhType != '6' and bhType != '7': file.write(util.formatedObjectVar(vdgObj, "bh_D")+ "= "+ (ivd.bh_D).ljust(lj)+ "// (mV)\n") file.write("\n")
def write_ActF_rateConstant(self, file, vdgObj, ivd): # in SNNAP time derivatives are also in seconds. to convert them to Neuron time derivatives # must be divided by 1000.0 lj = self.lJust1 afType = ivd.mType if afType == "2": file.write(util.formatedObjectVar(vdgObj, "m_L")+ "= 0.001\n") if afType == "3": #m_L = float(ivd.m_L) / 3000.0 * 3.23 m_L = float(ivd.m_L) /1000.0 file.write(util.formatedObjectVar(vdgObj, "m_L")+ "= "+ str(m_L)+"\n") #file.write(util.formatedObjectVar(vdgObj, "m_L")+ "= "+ ivd.m_L+ "\n") amType = ivd.amType file.write(util.formatedObjectVar(vdgObj, "am_type")+ "= "+ ivd.amType+ "\n") file.write(util.formatedObjectVar(vdgObj, "am_A")+ "= "+ ivd.am_A+ "\n") if amType != '1': file.write(util.formatedObjectVar(vdgObj, "am_B")+ "= "+ (ivd.am_B).ljust(lj)+ "// (mV)\n") if amType != '4' and amType != '8' and amType != '9': file.write(util.formatedObjectVar(vdgObj, "am_C")+ "= "+ (ivd.am_C).ljust(lj)+ "// (mV)\n") if amType != '5' and amType != '6' and amType != '7': file.write(util.formatedObjectVar(vdgObj, "am_D")+ "= "+ (ivd.am_D).ljust(lj)+ "// (mV)\n") bmType = ivd.bmType file.write("\n") file.write(util.formatedObjectVar(vdgObj, "bm_type")+ "= "+ bmType+ "\n") file.write(util.formatedObjectVar(vdgObj, "bm_A")+ "= "+ ivd.bm_A+ "\n") if bmType != '1': file.write(util.formatedObjectVar(vdgObj, "bm_B")+ "= "+ (ivd.bm_B).ljust(lj)+ "// (mV)\n") if bmType != '4' and bmType != '8' and bmType != '9': file.write(util.formatedObjectVar(vdgObj, "bm_C")+ "= "+ (ivd.bm_C).ljust(lj)+ "// (mV)\n") if bmType != '5' and bmType != '6' and bmType != '7': file.write(util.formatedObjectVar(vdgObj, "bm_D")+ "= "+ (ivd.bm_D).ljust(lj)+ "// (mV)\n") file.write("\n")
def writeNeurons(self, sSim): """ write neuron data into files """ lj = self.lJust1 for nName in sSim.network.neurons.keys(): nf_local = "create_"+nName+".hoc" nFileName = os.path.join(self.nrnDirPath,self.nrnDirName,nf_local) nrn = sSim.network.neurons[nName] with open(nFileName, "w") as nf: # append file name to the neuron filelist self.neutonFiles.append(nf_local) nf.write("create "+ nName+"\n") nf.write(nName + " {\n") nf.write("\tnseg = 1\t\t// single compartment\n") nf.write("\tdiam = 1\t\t// (um)\n") nf.write("\tL = 3.1831e7\t\t// (um)\n") nf.write("\t// total area = pi*diam*L = 1e8 um2 = 1 cm2\n\n") # write membrane capacitance if nrn.memAreaType == "0" or nrn.memAreaType == "": # membrane capacitance is in uF cm = float(nrn.cm) nf.write("\tcm = "+ str(cm).ljust(lj)+"// (uF/cm2)\n") else: print "WARNING: memAreas other than \"0\" are not supported yet!!!" # insert leak current vdgs = nrn.vdgs if self.useNrnPas: for vdgName in vdgs.keys(): ivdType = vdgs[vdgName].ivdType if ivdType == '5': nf.write("\tinsert pas\n") nf.write("\te_pas = "******"// (mV)\n") g = float(vdgs[vdgName].g) # in SNNAP cm is given in uS, # convert conductance from uS to S if not using mem_area if nrn.memAreaType == '0' or nrn.memAreaType == "": g = float(vdgs[vdgName].g) * 1.0e-6 nf.write("\tg_pas = "******"// (S/cm2)\n") nf.write("}\n\n") # write inital Vm nf.write(nName+".v(0.5) = " + str(nrn.vmInit).ljust(lj) +" // (mV)\n\n") # insert VDGs for vdgName in vdgs.keys(): ivdType = vdgs[vdgName].ivdType aType = vdgs[vdgName].AType bType = vdgs[vdgName].BType mType = vdgs[vdgName].mType hType = vdgs[vdgName].hType if nrn.memAreaType == '0'or nrn.memAreaType == "": # in SNNAP, if not using memArea conductance is given in uS try: g = float(vdgs[vdgName].g) except: print "WARNING!: could not convert "+vdgName+ " conductance of neuron " + nName print "Exited unexpectedly!" sys.exit(-1) if not self.useNrnPas: if ivdType == '5': nf.write("// passive current\n") vdgObjName = nName+"_pas" nf.write("objref "+vdgObjName+ "\n") nf.write(nName+" "+vdgObjName+ " = new snnap_ionic_pas_ivd5(0.5)\n") nf.write(util.formatedObjectVar(vdgObjName, "e")+ "= "+(vdgs[vdgName].E).ljust(lj) + "// (mV)\n") nf.write(util.formatedObjectVar(vdgObjName, "gmax") + "= " + str(g).ljust(lj) + "// (uS)\n\n\n") continue # create object reference for this vdg vdgObjName = nName+"_"+vdgName nf.write("objref "+vdgObjName+ "\n") if ivdType == '1' or ivdType == '3': nf.write("//_A"+aType+"_B"+bType+"\n") nf.write(nName+" "+vdgObjName+ " = new snnap_ionic_tc_ivd"+ivdType+"(0.5)\n") nf.write(util.formatedObjectVar(vdgObjName, "e")+ "= "+(vdgs[vdgName].E).ljust(lj) + "// (mV)\n") nf.write(util.formatedObjectVar(vdgObjName, "gmax") + "= " + str(g).ljust(lj) + "// (uS)\n") nf.write(util.formatedObjectVar(vdgObjName, "p")+ "= "+vdgs[vdgName].P + "\n\n") self.write_ActF_timeConstant(nf, vdgObjName, vdgs[vdgName]) if ivdType == '1': self.write_InActF_timeConstant(nf, vdgObjName, vdgs[vdgName]) if ivdType == '2' or ivdType == '4': nf.write("//_m"+mType+"_h"+hType+"\n") nf.write(nName+" "+vdgObjName+ " = new snnap_ionic_rc_ivd"+ivdType+"(0.5)\n") nf.write(util.formatedObjectVar(vdgObjName, "e")+ "= "+(vdgs[vdgName].E).ljust(lj) + "// (mV)\n") nf.write(util.formatedObjectVar(vdgObjName, "gmax") + "= " + str(g).ljust(lj) + "// (uS)\n") nf.write(util.formatedObjectVar(vdgObjName, "p")+ "= "+vdgs[vdgName].P + "\n\n") self.write_ActF_rateConstant(nf, vdgObjName, vdgs[vdgName]) if ivdType == '2': self.write_InActF_rateConstant(nf, vdgObjName, vdgs[vdgName]) nf.write("\n")
def writeChemSyns(self, sSim): lj = self.lJust1 csList = sSim.network.chemSyns neurons = sSim.network.neurons i = 0 for cs in csList: csf_local = "cs_"+cs.preSyn+"_to_" + cs.postSyn + "_" + cs.synType +".hoc" csFileName = os.path.join(self.nrnDirPath,self.nrnDirName,csf_local) with open(csFileName, "w") as csf: # append file name to the chemical synapse filelist self.chemSynFiles.append(csf_local) AtType = cs.ATType XtType = cs.XtType csf.write("// presyn: "+ cs.preSyn+ " postSyn: " + cs.postSyn+"\n") csf.write("//cs_ fATType:"+ cs.fATType+ " ATType:" + AtType +" XtType:"+ XtType+"\n\n") csf.write("threshold".ljust(lj)+ "= "+neurons[cs.preSyn].treshold.ljust(lj)+ "// (mV)\n") csf.write("delay".ljust(lj)+"= "+ "0.0".ljust(lj)+ "// (ms)\n") csf.write("weight".ljust(lj)+ "= "+"1".ljust(lj)+ "\n\n") #csf.write(("objref cs_"+str(i)).ljust()+"\n") csObjName = "cs_"+str(i) csf.write("objref "+ csObjName +"\n") if AtType == '1' or AtType == '2': csf.write(cs.postSyn+" "+ csObjName +" = new snnap_cs2_At12(0.5)\n\n") if AtType == '3' or AtType == '4': if XtType == '1': csf.write(cs.postSyn+" "+ csObjName +" = new snnap_cs2_At34_Xt1(0.5)\n\n") elif XtType == '3': csf.write(cs.postSyn+" "+ csObjName +" = new snnap_cs2_At34_Xt3(0.5)\n\n") else: print "WARNING: Xt types other than \"1\" or \"3\" are not supported yet!!!" if AtType == '5': if XtType == '1': csf.write(cs.postSyn+" "+ csObjName +" = new snnap_cs2_At5_Xt_1(0.5)\n\n") elif XtType == '3': csf.write(cs.postSyn+" "+ csObjName +" = new snnap_cs2_At5_Xt_3(0.5)\n\n") else: print "WARNING: Xt types other than \"1\" or \"3\" are not supported yet!!!" csf.write(util.formatedObjectVar(csObjName, "e")+"= "+ cs.E.ljust(lj) + "// (mV)\n") # in SNNAP synaptic conductance is in uS g = float(cs.g) csf.write(util.formatedObjectVar(csObjName, "g")+"= "+ str(g).ljust(lj) + "// (uS)\n") # convert spike duration to ms spDur = float(neurons[cs.preSyn].spikeDur) *1000 csf.write(util.formatedObjectVar(csObjName, "dur")+"= "+ str(spDur).ljust(lj) + "// (ms)\n\n") if cs.fATType in ['3', '5', '6']: csf.write(util.formatedObjectVar(csObjName, "fAt_a")+"= "+ cs.fAT_a + "\n") if cs.fATType in ['3', '4', '5']: csf.write(util.formatedObjectVar(csObjName, "fAt_b")+"= "+ cs.fAT_b + "\n") csf.write(util.formatedObjectVar(csObjName, "Ics_type")+"= "+ cs.iCSType + "\n") csf.write(util.formatedObjectVar(csObjName, "fAt_type")+"= "+ cs.fATType + "\n") csf.write(util.formatedObjectVar(csObjName, "At_type")+"= "+ cs.ATType + "\n") if AtType in ['3', '4', '5']: csf.write(util.formatedObjectVar(csObjName, "Xt_type")+"= "+ cs.XtType + "\n\n") if cs.ATType in ['1', '3', '4']: # convert seconds to milliseconds At_u1 = float(cs.At_u1) *1000.0 csf.write(util.formatedObjectVar(csObjName, "taucs1")+"= "+ str(At_u1).ljust(lj) + "// (ms)\n") if cs.ATType in ['2', '4']: # convert seconds to milliseconds At_u2 = float(cs.At_u2) *1000.0 csf.write(util.formatedObjectVar(csObjName, "taucs2")+"= "+ str(At_u2).ljust(lj) + "// (ms)\n") if cs.XtType == "3" or cs.XtType == "4": # convert seconds to milliseconds PSM_ud = float(cs.PSM_ud) *1000.0 PSM_ur = float(cs.PSM_ur) *1000.0 csf.write(util.formatedObjectVar(csObjName, "tauXt1")+"= "+ str(PSM_ud).ljust(lj) + "// (ms)\n") csf.write(util.formatedObjectVar(csObjName, "tauXt2")+"= "+ str(PSM_ur).ljust(lj) + "// (ms)\n") # setup netCon object csncObjName = "cs_nc"+str(i) csf.write("\nobjref "+ csncObjName +"\n") csf.write(cs.preSyn+" "+ csncObjName +" = new NetCon(&v(0.5), "+ csObjName+ ", threshold, delay, weight)\n\n") i = i+1 return
def write_ActF_timeConstant(self, file, vdgObj, ivd): lj = self.lJust1 afType = ivd.AType if afType == "2": #file.write(util.formatedObjectVar(vdgObj, "A_IV")+ "= "+ ivd.A_IV+ "\n") tAType = ivd.tAType file.write(util.formatedObjectVar(vdgObj, "tA_type")+ "= "+ tAType+ "\n") # convert seconds to ms tA_tx = float(ivd.tA_tx) * 1000.0 file.write(util.formatedObjectVar(vdgObj, "tA_tx") + "= "+ str(tA_tx).ljust(lj)+ "// (ms)\n") if tAType in ['2', '3', '6']: file.write(util.formatedObjectVar(vdgObj, "tA_h1") + "= "+ (ivd.tA_h1).ljust(lj)+ "// (mV)\n") file.write(util.formatedObjectVar(vdgObj, "tA_s1") + "= "+ (ivd.tA_s1).ljust(lj)+ "// (mV)\n") if tAType != '6': # convert seconds to ms tA_tn = float(ivd.tA_tn) * 1000.0 file.write(util.formatedObjectVar(vdgObj, "tA_tn") + "= "+ str(tA_tn).ljust(lj)+ "// (ms)\n") file.write(util.formatedObjectVar(vdgObj, "tA_p1") + "= "+ (ivd.tA_p1).ljust(lj)+ "\n\n") if tAType in ['3', '6']: file.write(util.formatedObjectVar(vdgObj, "tA_h2") + "= "+ (ivd.tA_h2).ljust(lj)+ "// (mV)\n") file.write(util.formatedObjectVar(vdgObj, "tA_s2") + "= "+ (ivd.tA_s2).ljust(lj)+ "// (mV)\n") if tAType != '6': file.write(util.formatedObjectVar(vdgObj, "tA_p2") + "= "+ (ivd.tA_p2).ljust(lj)+ "\n\n") elif tAType != '1': print "WARNING: Time constant forms other than 1, 2, 3 or 6 are not supported yet!!!" # write steady state ssAType = ivd.ssAType file.write(util.formatedObjectVar(vdgObj, "ssA_type") + "= "+ ssAType+ "\n") file.write(util.formatedObjectVar(vdgObj, "ssA_h") + "= "+ (ivd.ssA_h).ljust(lj)+ "// (mV)\n") file.write(util.formatedObjectVar(vdgObj, "ssA_s") + "= "+ (ivd.ssA_s).ljust(lj)+ "// (mV)\n") file.write(util.formatedObjectVar(vdgObj, "ssA_p") + "= "+ ivd.ssA_p+ "\n") if ssAType == '2': file.write(util.formatedObjectVar(vdgObj, "ssA_An") + "= "+ ivd.ssA_An+ "\n") file.write("\n")