Wiki source code of Code description
                  Version 5.1 by galluzziandrea on 2021/12/09 14:46
              
      Show last authors
| author | version | line-number | content | 
|---|---|---|---|
| 1 | == Introduction (path and modules): == | ||
| 2 | |||
| 3 | First of all we check the path and import the necessary modules . | ||
| 4 | |||
| 5 | === Check where I am and place myself in the right folder: === | ||
| 6 | |||
| 7 | {{code language="python"}} | ||
| 8 | # Import the os module | ||
| 9 | import os | ||
| 10 | |||
| 11 | #Print the current working directory | ||
| 12 | print("Current working directory: {0}".format(os.getcwd())) | ||
| 13 | |||
| 14 | # Change the current working directory | ||
| 15 | os.chdir('/mnt/user/shared/Slow waves in fading anesthesia/Nest3Python3') | ||
| 16 | |||
| 17 | # Print the current working directory | ||
| 18 | print("Current working directory: {0}".format(os.getcwd())) | ||
| 19 | {{/code}} | ||
| 20 | |||
| 21 | === Import the modules necessary for the simulation: === | ||
| 22 | |||
| 23 | {{code language="python"}} | ||
| 24 | import nest | ||
| 25 | import time | ||
| 26 | from numpy import exp | ||
| 27 | import numpy | ||
| 28 | import math | ||
| 29 | import random | ||
| 30 | import multiprocessing | ||
| 31 | Inizio=time.time() | ||
| 32 | print('tempo di Inizio:',Inizio) | ||
| 33 | {{/code}} | ||
| 34 | |||
| 35 | === === | ||
| 36 | |||
| 37 | === Define necessary classes to import the Initialization Files: === | ||
| 38 | |||
| 39 | |||
| 40 | {{code language="python"}} | ||
| 41 | class ImportIniLIFCA(): | ||
| 42 | #initialize the information to look for in perseo.ini | ||
| 43 | inf=["NeuronType", #still fixed value | ||
| 44 | "DelayDistribType", #still fixed value | ||
| 45 | "SynapticExtractionType", #still fixed value | ||
| 46 | "Life"] | ||
| 47 | |||
| 48 | def __init__(self,files): | ||
| 49 | self.files=files | ||
| 50 | |||
| 51 | def FilesControllo(self): | ||
| 52 | import sys | ||
| 53 | for i in range(0,len(self.files)): | ||
| 54 | if self.FileControllo(self.files[i]): | ||
| 55 | sys.exit(0) | ||
| 56 | |||
| 57 | def FileControllo(self,file1): | ||
| 58 | try: | ||
| 59 | f1=open(file1,"r") | ||
| 60 | f1.close() | ||
| 61 | return 0 | ||
| 62 | except ValueError: | ||
| 63 | print("ValueError") | ||
| 64 | return 1 | ||
| 65 | except IOError as err: | ||
| 66 | print("OS error: {0}".format(err)) | ||
| 67 | return 1 | ||
| 68 | except: | ||
| 69 | print("Unexpected error:", sys.exc_info()[0]) | ||
| 70 | return 1 | ||
| 71 | |||
| 72 | def Estrai_inf(self,stampa=0): | ||
| 73 | |||
| 74 | InfoPerseo=self.EstraiInfoPerseo() #extract info from perseo.ini | ||
| 75 | AppoggioTempM=self.EstraiInfoModuli() #extract info from modules.ini | ||
| 76 | AppoggioTempC=self.EstraiInfoConnectivity() #extract info from connectivity.ini | ||
| 77 | AppoggioTempP=self.EstraiProtocol() #extract info from protocol.ini | ||
| 78 | |||
| 79 | def getKey(item): | ||
| 80 | return item[0] | ||
| 81 | InfoProtocol=AppoggioTempP | ||
| 82 | # I convert the extracted information into a suitable format from tuple to list | ||
| 83 | |||
| 84 | InfoBuildT=[AppoggioTempM[0]] | ||
| 85 | for i in range(0,AppoggioTempM[0]): | ||
| 86 | app1=[int(AppoggioTempM[2][i][0])] | ||
| 87 | app=(app1+list(AppoggioTempM[2][i][3:9])+list(AppoggioTempM[2][i][12])+list(AppoggioTempM[2][i][9:12])) | ||
| 88 | InfoBuildT.append(app) | ||
| 89 | del app | ||
| 90 | |||
| 91 | InfoBuild=[float(InfoBuildT[0])] | ||
| 92 | for i in range(0,int(InfoBuildT[0])): | ||
| 93 | app=[] | ||
| 94 | for j in range(0,11): | ||
| 95 | app.append(float(InfoBuildT[i+1][j])) | ||
| 96 | InfoBuild=InfoBuild+[app] | ||
| 97 | del app | ||
| 98 | |||
| 99 | InfoConnectPop=[AppoggioTempM[0]] | ||
| 100 | for i in range(0,len(AppoggioTempC[1][:])): | ||
| 101 | app=list(AppoggioTempC[1][i]) | ||
| 102 | InfoConnectPop.append(app) | ||
| 103 | del app | ||
| 104 | |||
| 105 | InfoConnectNoise=[AppoggioTempM[0]] | ||
| 106 | for i in range(0,AppoggioTempM[0]): | ||
| 107 | app=list(AppoggioTempM[2][i][1:3]) | ||
| 108 | InfoConnectNoise.append(app) | ||
| 109 | |||
| 110 | |||
| 111 | if stampa==1: #Print on screen of saved data | ||
| 112 | for i,j in enumerate(InfoPerseo): | ||
| 113 | print(self.inf[i],"=",j) | ||
| 114 | print("\n") | ||
| 115 | print("the network consists of ", AppoggioTempM[0], " neuronal population" ) | ||
| 116 | print(AppoggioTempM[1]) | ||
| 117 | for i in range(0,AppoggioTempM[0]): | ||
| 118 | print(AppoggioTempM[2][i]) | ||
| 119 | print("\n") | ||
| 120 | print(AppoggioTempC[0]) | ||
| 121 | for i in range(0,AppoggioTempM[0]**2): | ||
| 122 | print(AppoggioTempC[1][i]) | ||
| 123 | print("\n") | ||
| 124 | for i in InfoProtocol: | ||
| 125 | print("SET_PARAM"+str(i)) | ||
| 126 | |||
| 127 | |||
| 128 | return InfoPerseo,InfoBuild,InfoConnectPop,InfoConnectNoise,InfoProtocol | ||
| 129 | |||
| 130 | def EstraiProtocol(self): | ||
| 131 | import string | ||
| 132 | f1=open(self.files[3],"r") | ||
| 133 | ProtocolList= [] | ||
| 134 | for x in f1.readlines(): | ||
| 135 | y=x.split() | ||
| 136 | if len(y): | ||
| 137 | if x[0]!="#" and y[0]=="SET_PARAM": | ||
| 138 | try: | ||
| 139 | ProtocolList.append([float(y[1]),int(y[2]),float(y[3]),float(y[4])]) | ||
| 140 | except ValueError: | ||
| 141 | pass | ||
| 142 | f1.close() | ||
| 143 | return ProtocolList | ||
| 144 | |||
| 145 | def EstraiInfoPerseo(self): | ||
| 146 | import string | ||
| 147 | f1=open(self.files[0],"r") | ||
| 148 | InfList= [] | ||
| 149 | for x in f1.readlines(): | ||
| 150 | y=x.split() | ||
| 151 | if len(y): | ||
| 152 | if x[0]!="#": | ||
| 153 | for findinf in self.inf: | ||
| 154 | try: | ||
| 155 | temp=y.index(findinf) | ||
| 156 | InfList.append(y[temp+2]) | ||
| 157 | except ValueError: | ||
| 158 | pass | ||
| 159 | f1.close() | ||
| 160 | return InfList | ||
| 161 | |||
| 162 | def EstraiInfoModuli(self): | ||
| 163 | import string | ||
| 164 | f1=open(self.files[2],"r") | ||
| 165 | NumPop=0 | ||
| 166 | for i,x in enumerate(f1.readlines()): | ||
| 167 | y=x.split() | ||
| 168 | if len(y): | ||
| 169 | if x[0]!="#": | ||
| 170 | NumPop=NumPop+1 | ||
| 171 | if i==2: | ||
| 172 | ParamList=[] | ||
| 173 | for j in range(1,14): | ||
| 174 | ParamList.append(y[j]) | ||
| 175 | f1.close() | ||
| 176 | PopsParamList=[] | ||
| 177 | f1=open(self.files[2],"r") | ||
| 178 | x=f1.readlines() | ||
| 179 | for j in range(0,NumPop): | ||
| 180 | appo=x[4+j]; | ||
| 181 | PopsParamList.append(appo.split()) | ||
| 182 | f1.close() | ||
| 183 | return NumPop,ParamList,PopsParamList | ||
| 184 | |||
| 185 | def EstraiInfoConnectivity(self): | ||
| 186 | import string | ||
| 187 | f1=open(self.files[1],"r") | ||
| 188 | PopConParamList=[] | ||
| 189 | for i,x in enumerate(f1.readlines()): | ||
| 190 | y=x.split() | ||
| 191 | if len(y): | ||
| 192 | if x[0]!="#": | ||
| 193 | PopConParamList.append(y) | ||
| 194 | if i==1: | ||
| 195 | ParamList=[] | ||
| 196 | for j in range(1,9): | ||
| 197 | ParamList.append(y[j]) | ||
| 198 | f1.close() | ||
| 199 | return ParamList,PopConParamList | ||
| 200 | {{/code}} | ||
| 201 | |||
| 202 | === Import the initialization files: === | ||
| 203 | |||
| 204 | in this section we... | ||
| 205 | |||
| 206 | {{code language="python"}} | ||
| 207 | Salva=1 | ||
| 208 | file1="perseo35.ini" | ||
| 209 | file2="c_cortsurf_Pot1.43PotStr148v3.ini" | ||
| 210 | file3="m_cortsurf_Pot1.43.ini" | ||
| 211 | file4="ProtocolExploration36.ini" | ||
| 212 | files=[file1,file2,file3,file4] | ||
| 213 | #define the name of the Output file | ||
| 214 | FileName="dati/Rates_Nest_Run_Milano_Test36_13x13_"+str(nest.Rank())+"_Pot1.43PotStr148v3Long3.dat" | ||
| 215 | #check the existence of the files being read | ||
| 216 | ImpFil=ImportIniLIFCA(files); | ||
| 217 | ImpFil.FilesControllo() | ||
| 218 | |||
| 219 | #extract the information of interest from the files.ini and transfer them to the files: | ||
| 220 | #InfoPerseo,InfoBuild,InfoConnectPop,InfoConnectNoise | ||
| 221 | |||
| 222 | stampa=0; #stampa=1 print output simulation data on screen stampa=0 dont | ||
| 223 | InfoPerseo,InfoBuild,InfoConnectPop,InfoConnectNoise,InfoProtocol=ImpFil.Estrai_inf(stampa) | ||
| 224 | |||
| 225 | # InfoPerseo=["NeuronType","DelayDistribType","SynapticExtractionType","Life" ] | ||
| 226 | # InfoBuild=[numero di popolazioni, | ||
| 227 | # [N,C_ext,\nu_ext,\tau,\tetha,H,\tau_arp,NeuronInitType,\alpha_c,\tau_c,g_c], | ||
| 228 | # [.....],[],...] | ||
| 229 | # InfoConnectPop=[numero di popolazioni, | ||
| 230 | # [post,pre,c,Dmin,Dmax,syn typ,J,DJ], | ||
| 231 | # [.....],[],...] | ||
| 232 | # InfoConnectNoise=[numero di popolazioni, | ||
| 233 | # [J_ext,DJ_ext], | ||
| 234 | # [.....],[],...] | ||
| 235 | # InfoProtocol=[[time,population,param_num,value], | ||
| 236 | # [.....],[],...] | ||
| 237 | {{/code}} | ||
| 238 | |||
| 239 | |||
| 240 | |||
| 241 | |||
| 242 | === Results === | ||
| 243 | |||
| 244 | ==== ==== | 
- Introduction (path and modules):- Check where I am and place myself in the right folder:
- Import the modules necessary for the simulation:
- Define necessary classes to import the Initialization Files:
- Import the initialization files:
- Defining general and nest.kernel parameters
- Building the network: neuronal populations , Poisson processes and spike detectors
- Connecting the network nodes: neuronal populations, Poisson processes and spike detectors
- Simulating: neuronal time evolution.
- Results: