diff --git a/core/hoc/ElectrodeManager.hoc b/core/hoc/ElectrodeManager.hoc deleted file mode 100644 index d3d9ff07..00000000 --- a/core/hoc/ElectrodeManager.hoc +++ /dev/null @@ -1,138 +0,0 @@ -/** - * @file ElectrodeManager.hoc - * @brief - * @author reimann - * @date 2010-12-30 - * @remark Copyright © BBP/EPFL 2005-2011; All rights reserved. Do not distribute without further notice. - */ - -begintemplate ElectrodeManager - -objref xPosVec, yPosVec, zPosVec, electrodeName, electrodeList, electrodePath - -public getElectrode, init, clear, count, getName - -/*! - * Initiate the manager. - * Input: $o1: a String object giving the path to the Electrodes directory - * $o2: the map of all parsed Electrode blocks - */ -proc init() { local i, vNum, pX, pY, pZ localobj parsedElectrodes, pathString, tempElectrode, nil //, currName, currMap - xPosVec = new Vector() - yPosVec = new Vector() - zPosVec = new Vector() - electrodeName = new List() - electrodeList = new List() - - electrodePath = $o1 - parsedElectrodes = $o2 - - if(electrodePath == nil || parsedElectrodes == nil){ - //print "No ElectrodesPath or no Electrodes specified. Extracellular class of stimuli will be unavailable!" - return - } - - for( i = 0; i < parsedElectrodes.count(); i = i+1){ - //GET FILENAME - pathString = new String() - //currName = parsedElectrodes.key(i) - //currMap = parsedElectrodes.o(i) - if(parsedElectrodes.o(i).get("File") == nil){ - print "No filename given for Electrode ", parsedElectrodes.key(i).s, "cannot parse anything!" - continue - } - sprint(pathString.s,"%s/%s",electrodePath.s,parsedElectrodes.o(i).get("File").s) - - //GET LOCATION - pX = 0 - pY = 0 - pZ = 0 - if(parsedElectrodes.o(i).get("x") != nil){ - sscanf(parsedElectrodes.o(i).get("x").s,"%i",&pX) - } - if(parsedElectrodes.o(i).get("y") != nil){ - sscanf(parsedElectrodes.o(i).get("y").s,"%i",&pY) - } - if(parsedElectrodes.o(i).get("z") != nil){ - sscanf(parsedElectrodes.o(i).get("z").s,"%i",&pZ) - } - - //GET VERSION AND FINALLY THE OBJECT - vNum = -1 - if(parsedElectrodes.o(i).get("Version") != nil){ - sscanf(parsedElectrodes.o(i).get("Version").s,"%i",&vNum) - } - if(vNum==5){ - tempElectrode = new lookupTableV2(pathString.s) - if(vNum != tempElectrode.vInfo()){ - print "LookupTable version numbers dont match: ", pathString.s - continue - } - }else if(vNum<5){ - print "LookupTable version number < 5 no longer supported: ", pathString.s - continue - }else { - print "LookupTable unknown version number encountered: ", pathString.s - continue - } - - //ADD INFORMATION TO THE LISTS - xPosVec.append(pX) - yPosVec.append(pY) - zPosVec.append(pZ) - electrodeName.append(parsedElectrodes.key(i)) - electrodeList.append(tempElectrode) - } -} - -/*! - * Get an Electrode object from the manager. Lookup either by name: - * $s1: Name of the Electrode object (as specified in its Electrode { block) - * Or by position: - * $1: x-coord of the Electrode object - * $2: y-coord of the Electrode object - * $3: z-coord of the Electrode object - * Or by index: - * $1: Index of the Electrode object - * Returns the first Electrode object found within 5 micron (in each direction) of the specified coordinates - */ - -obfunc getElectrode(){ local i localobj tElec - if(numarg() == 1){ - if(argtype(1) == 2){ - for(i = 0; i < electrodeName.count(); i=i+1){ - if(strcmp($s1,electrodeName.o(i).s)==0){ - return electrodeList.o(i) - } - } - } else { - return electrodeList.o($1) - } - } else if(numarg() == 3){ //TODO: Need a better concept of how to handle the lookup by location. For now something simple - for(i = 0; i < electrodeName.count(); i=i+1){ - if((abs(xPosVec.x(i)-$1)<5) && (abs(yPosVec.x(i)-$2)<5) && (abs(zPosVec.x(i)-$3)<5)){ - return electrodeList.o(i) - } - } - } - return tElec -} - -obfunc getName(){ - return electrodeName.o($1) -} - -func count(){ - return electrodeList.count() -} - -proc clear(){ localobj nil - xPosVec.resize(0) - yPosVec.resize(0) - zPosVec.resize(0) - electrodeList.remove_all() - electrodeName.remove_all() -} - - -endtemplate ElectrodeManager diff --git a/core/hoc/neurodamus.hoc b/core/hoc/neurodamus.hoc index cd8fbbf4..92a83527 100644 --- a/core/hoc/neurodamus.hoc +++ b/core/hoc/neurodamus.hoc @@ -9,7 +9,6 @@ // Neurodamus - Do not change order {load_file("RNGSettings.hoc")} -{load_file("ElectrodeManager.hoc")} {load_file("StimulusManager.hoc")} {load_file("Cell.hoc")} {load_file("TDistFunc.hoc")} diff --git a/core/mod/coreneuron_modlist.txt b/core/mod/coreneuron_modlist.txt index e55bb284..5aadbd42 100644 --- a/core/mod/coreneuron_modlist.txt +++ b/core/mod/coreneuron_modlist.txt @@ -1,7 +1,6 @@ ALU.mod CoreNEURONArtificialCell.mod HDF5reader.mod -lookupTableV2.mod netstim_inhpoisson.mod SonataReportHelper.mod SonataReports.mod diff --git a/core/mod/lookupTableV2.mod b/core/mod/lookupTableV2.mod deleted file mode 100755 index 00bf6dfa..00000000 --- a/core/mod/lookupTableV2.mod +++ /dev/null @@ -1,313 +0,0 @@ -COMMENT -/** - * @file lookupTableV2.mod - * @brief - * @author reimann - * @date 2010-12-30 - * @remark Copyright © BBP/EPFL 2005-2011; All rights reserved. Do not distribute without further notice. - */ -ENDCOMMENT - -VERBATIM -#ifndef CORENEURON_BUILD -#include -#include -#include -#include - -typedef struct{ - float **axon; - float **apicals; - float **basals; - int *axonsSz; - int *apicalsSz; - int *basalsSz; - float soma; - unsigned int axonSz; - unsigned int apicalSz; - unsigned int basalSz; -} sectionEntry; - -typedef struct{ - int **gids; - sectionEntry **secData; - float **factors; - int numToRead; - int *tableSizes; - char vInfo; - float *xPos; - float *yPos; - float *zPos; -}tableStruct; - -float swapForFloat(int iAmAFloat){ - float factor; - unsigned char *inPoint = (unsigned char *) &iAmAFloat; - unsigned char *outPoint = (unsigned char *) &factor; - iAmAFloat = (int)htonl(iAmAFloat); - int k; - for(k = 0; k < 4; ++k) - outPoint[k]=inPoint[k]; - return factor; -}; - -void readAndSwapInt(int *readInto, int number, FILE *file){ - int i = 0; - fread(readInto,sizeof(int),number,file); - for(i = 0; i < number; ++i){ - readInto[i] = (int)htonl(readInto[i]); - } -}; -void readAndSwapFloat(float *readInto, int number, FILE *file){ - int i = 0; - int tempReadArray[number]; - fread(&tempReadArray,sizeof(int),number,file); - for(i = 0; i < number; ++i){ - readInto[i] = swapForFloat(tempReadArray[i]); - } -}; -#endif // CORENEURON_BUILD -ENDVERBATIM - -NEURON { - ARTIFICIAL_CELL lookupTableV2 - POINTER ptr -} - -ASSIGNED{ - ptr -} - -CONSTRUCTOR{ - VERBATIM -#ifndef CORENEURON_BUILD - //printf("Building lookup table...\n"); - if(sizeof(float)!=4 || sizeof(int)!=4){ - printf("sizeof does not match. Need to specify data type sizes more explicitly\n"); - return; - } - tableStruct** tempTable = (tableStruct**)(&(_p_ptr)); - tableStruct* tbl = 0; - tbl = (tableStruct*)hoc_Emalloc(sizeof(tableStruct)); - tbl->numToRead = 0; - if(ifarg(1)&&hoc_is_str_arg(1)){ - char tableName[128]; - sprintf(tableName,"%s",gargstr(1)); - FILE *file; - //printf("Opening file: %s\n",tableName); - if((file = fopen(tableName, "r"))==NULL) { - //printf("FAILURE!\n"); - //tbl->numToRead=0; - *tempTable = tbl; - return; - } - float retVal = 0; - //int numToRead; - int i,j,k; - int gidNum; - char header[128] = {0x0}; - char readChar = 0x1; - i=0; - int iAmAFloat; - while(readChar!=0xA){ - fread(&readChar,1,1,file); - header[i++]=readChar; - } - if(strncmp(header,"ExtracellularElectrodeLookupTable",33)!=0){ - *tempTable = tbl; - printf("Header does not match: \n"); - printf("%s", header); - return; - } - fread(&(tbl->vInfo),sizeof(char),1,file); - char circuitPath[512]; - readChar = 0x1; - i=0; - while(readChar!=0xA){ - fread(&readChar,1,1,file); - circuitPath[i++]=readChar; - } - //printf(circuitPath); - fread(&(tbl->numToRead),sizeof(int),1,file); - tbl->numToRead = (int)htonl(tbl->numToRead); - //printf("number: %d\n",tbl->numToRead); - tbl->gids = (int**)hoc_Emalloc((tbl->numToRead)*sizeof(int *)); - tbl->factors = (float**)hoc_Emalloc((tbl->numToRead)*sizeof(float *)); - tbl->secData = (sectionEntry**)hoc_Emalloc((tbl->numToRead)*sizeof(sectionEntry *)); - tbl->tableSizes = (int*)hoc_Emalloc((tbl->numToRead)*sizeof(int)); - tbl->xPos = (float*)hoc_Emalloc((tbl->numToRead)*sizeof(float)); - tbl->yPos = (float*)hoc_Emalloc((tbl->numToRead)*sizeof(float)); - tbl->zPos = (float*)hoc_Emalloc((tbl->numToRead)*sizeof(float)); - //printf("gids: %d; factors: %d; tableSizes: %d\n",tbl->gids,tbl->factors,tbl->tableSizes); - for(i = 0; i < tbl->numToRead; ++i){ - fread((&iAmAFloat),sizeof(float),1,file); - tbl->xPos[i] = swapForFloat(iAmAFloat); - fread((&iAmAFloat),sizeof(float),1,file); - tbl->yPos[i] = swapForFloat(iAmAFloat); - fread((&iAmAFloat),sizeof(float),1,file); - tbl->zPos[i] = swapForFloat(iAmAFloat); - int tableSize; - fread((&tableSize),sizeof(int),1,file); - tableSize = (int)htonl(tableSize); - //printf("tableSize: %d",tableSize); - (tbl->tableSizes)[i]=tableSize; - (tbl->gids)[i] = (int*)hoc_Emalloc(tableSize*sizeof(int)); - (tbl->factors)[i] = (float*)hoc_Emalloc(tableSize*sizeof(float)); - (tbl->secData)[i] = (sectionEntry*)hoc_Emalloc(tableSize*sizeof(sectionEntry)); - if((tbl->gids)[i]==0 || (tbl->factors)[i]==0 || (tbl->secData)[i]==0){ - printf("Problem allocating memory for factor tables\n"); - return; - } - int index; - float factor; - //unsigned char *inPoint = (unsigned char *) &iAmAFloat; - //unsigned char *outPoint = (unsigned char *) &factor; - unsigned int somaSize, axonSize, dendriteSize, apicalSize; - for (j = 0; j < tableSize; ++j){ - fread(&index,4,1,file); - (tbl->gids)[i][j]=(int)htonl(index); - //TODO: byte swapping only needed on little endian systems. - fread((&iAmAFloat),sizeof(iAmAFloat),1,file); //Need to read the float as an int before byte swapping, otherwise the float register might try to "repair" it... - //iAmAFloat = (int)htonl(iAmAFloat); - //for(k = 0; k < 4; ++k) - // outPoint[k]=inPoint[k]; - (tbl->factors)[i][j]=swapForFloat(iAmAFloat); - fread(&somaSize,4,1,file); - somaSize = (unsigned int)htonl(somaSize); - fread(&axonSize,4,1,file); - axonSize = (unsigned int)htonl(axonSize); - (tbl->secData)[i][j].axonSz = axonSize; - fread(&dendriteSize,4,1,file); - dendriteSize = (unsigned int)htonl(dendriteSize); - (tbl->secData)[i][j].basalSz = dendriteSize; - fread(&apicalSize,4,1,file); - apicalSize = (unsigned int)htonl(apicalSize); - (tbl->secData)[i][j].apicalSz = apicalSize; - if(somaSize!=1){ - printf("Need exactly one value for the soma. Got %d",somaSize); - return; - } - - (tbl->secData)[i][j].axonsSz = (int*)hoc_Emalloc(axonSize*sizeof(int)); - (tbl->secData)[i][j].axon = (float**)hoc_Emalloc(axonSize*sizeof(float*)); - (tbl->secData)[i][j].basalsSz = (int*)hoc_Emalloc(dendriteSize*sizeof(int)); - (tbl->secData)[i][j].basals = (float**)hoc_Emalloc(dendriteSize*sizeof(float*)); - (tbl->secData)[i][j].apicalsSz = (int*)hoc_Emalloc(apicalSize*sizeof(int)); - (tbl->secData)[i][j].apicals = (float**)hoc_Emalloc(apicalSize*sizeof(float*)); - - fread(&somaSize,4,1,file); - somaSize = (unsigned int)htonl(somaSize); - if(somaSize!=1){ - printf("Need exactly one value for the soma. Got %d",somaSize); - return; - } - readAndSwapInt((tbl->secData)[i][j].axonsSz,axonSize,file); - readAndSwapInt((tbl->secData)[i][j].basalsSz,dendriteSize,file); - readAndSwapInt((tbl->secData)[i][j].apicalsSz,apicalSize,file); - - fread((&iAmAFloat),sizeof(iAmAFloat),1,file); - (tbl->secData)[i][j].soma = swapForFloat(iAmAFloat); - for(k = 0; k < axonSize; ++k){ - (tbl->secData)[i][j].axon[k] = (float*)hoc_Emalloc((tbl->secData)[i][j].axonsSz[k]*sizeof(float)); - readAndSwapFloat((tbl->secData)[i][j].axon[k],(tbl->secData)[i][j].axonsSz[k],file); - } - for(k = 0; k < dendriteSize; ++k){ - (tbl->secData)[i][j].basals[k] = (float*)hoc_Emalloc((tbl->secData)[i][j].basalsSz[k]*sizeof(float)); - readAndSwapFloat((tbl->secData)[i][j].basals[k],(tbl->secData)[i][j].basalsSz[k],file); - } - for(k = 0; k < apicalSize; ++k){ - (tbl->secData)[i][j].apicals[k] = (float*)hoc_Emalloc((tbl->secData)[i][j].apicalsSz[k]*sizeof(float)); - readAndSwapFloat((tbl->secData)[i][j].apicals[k],(tbl->secData)[i][j].apicalsSz[k],file); - } - } - } - } - *tempTable = tbl; -#endif // CORENEURON_BUILD - ENDVERBATIM -} - -FUNCTION vInfo(){ - VERBATIM -#ifndef CORENEURON_BUILD - tableStruct **tempData = (tableStruct**)(&_p_ptr); - tableStruct *tbl = (tableStruct*) *tempData; - return tbl->vInfo; -#endif // CORENEURON_BUILD - ENDVERBATIM -} - -FUNCTION getValueForGid(){ - VERBATIM -#ifndef CORENEURON_BUILD - tableStruct **tempData = (tableStruct**)(&_p_ptr); - tableStruct *tbl = (tableStruct*) *tempData; - if((tbl->numToRead)==0) - return 1; - float retVal = 0; - int i,j; - if(ifarg(1)){ - int targetGid = (int) *getarg(1); - for(i = 0; i < (tbl->numToRead); ++i){ - for (j = 0; j < (tbl->tableSizes)[i]; ++j){ - if((tbl->gids)[i][j]==targetGid){ - retVal+=(tbl->factors)[i][j]; - break; //Break inner loop. (In the latest specification a gid can only be mentioned once per table.) - } - } - } - } - return retVal; -#endif // CORENEURON_BUILD - ENDVERBATIM -} - -FUNCTION getValueForSection(){ - VERBATIM -#ifndef CORENEURON_BUILD - tableStruct **tempData = (tableStruct**)(&_p_ptr); - tableStruct *tbl = (tableStruct*) *tempData; - if((tbl->numToRead)==0) - return 1; - float retVal = 0; - int i,j; - if(ifarg(4)){ - int targetGid = (int) *getarg(1); - int targetType = (int) *getarg(2); - int targetSec = (int) *getarg(3); - int usedCompIndex; - float compDist = (float) *getarg(4); - for(i = 0; i < (tbl->numToRead); ++i){ //TODO: Argh, use a map or something! - for (j = 0; j < (tbl->tableSizes)[i]; ++j){ - if((tbl->gids)[i][j]==targetGid){ //or directly sort it by gid - sectionEntry tEntry = (tbl->secData)[i][j]; - if(targetType == 3) - if(targetSec Non-existing name: %s" % elec_id) - return self._electrodes[elec_id] - - def find_near(self, x, y, z): - """Retrieves an electrode object given a position. - - Returns: the first Electrode object found within 5 micron (in each direction), - or None if not found - """ - all_dist = numpy.absolute(self._pos - (x, y, z)) - for elec, dist in zip(self._electrodes, all_dist): - if (dist < 5).all(): - return elec - return None - - def get_name(self, i): - return self._names[i] - - def get_position(self, i): - return self._pos[i] - - def __len__(self): - return self._count diff --git a/neurodamus/node.py b/neurodamus/node.py index 35e33a89..3d28e620 100644 --- a/neurodamus/node.py +++ b/neurodamus/node.py @@ -302,7 +302,6 @@ def __init__(self, config_file, options=None): self._stim_list = None self._report_list = None self._stim_manager = None - self._elec_manager = None self._sim_ready = False self._jumpstarters = [] self._cell_state_dump_t = None @@ -317,7 +316,6 @@ def __init__(self, config_file, options=None): circuits = property(lambda self: self._circuits) target_manager = property(lambda self: self._target_manager) stim_manager = property(lambda self: self._stim_manager) - elec_manager = property(lambda self: self._elec_manager) stims = property(lambda self: self._stim_list) reports = property(lambda self: self._report_list) @@ -644,11 +642,8 @@ def enable_stimulus(self): log_stage("Stimulus Apply.") - # Setup of Electrode objects part of enable stimulus - self._enable_electrodes() - # for each stimulus defined in the config file, request the stimmanager to instantiate - self._stim_manager = StimulusManager(self._target_manager, self._elec_manager) + self._stim_manager = StimulusManager(self._target_manager, None) # build a dictionary of stims for faster lookup : useful when applying 10k+ stims # while we are at it, check if any stims are using extracellular @@ -685,22 +680,6 @@ def enable_stimulus(self): logging.info(" * [STIM] %s: %s (%s) -> %s", name, stim_name, stim_pattern, target_spec) self._stim_manager.interpret(target_spec, stim) - # - - def _enable_electrodes(self): - if SimConfig.use_coreneuron: - # Coreneuron doesnt support electrodes - return False - electrode_path = self._run_conf.get("ElectrodesPath") - if electrode_path is not None: - logging.info("ElectrodeManager using electrodes from %s", electrode_path) - else: - logging.info("No electrodes path. Extracellular class of stimuli will be unavailable") - - self._elec_manager = Nd.ElectrodeManager( - electrode_path and Nd.String(electrode_path), - SimConfig.get_simulation_hoc_section("parsedElectrodes") - ) - # - @mpi_no_errors def enable_replay(self): @@ -876,10 +855,6 @@ def enable_reports(self): self._reports_init(pop_offsets_alias) - # electrode manager is no longer needed. free the memory - if self._elec_manager is not None: - self._elec_manager.clear() - # def _report_build_params(self, rep_name, rep_conf, target, pop_offsets_alias_pop): sim_end = self._run_conf["Duration"] @@ -924,8 +899,6 @@ def _report_build_params(self, rep_name, rep_conf, target, pop_offsets_alias_pop logging.error("Invalid report dt %f < %f simulation dt", rep_dt, Nd.dt) return None - electrode = self._elec_manager.getElectrode(rep_conf["Electrode"]) \ - if SimConfig.use_neuron and "Electrode" in rep_conf else None rep_target = TargetSpec(rep_conf["Target"]) population_name = (rep_target.population or self._target_spec.population or self._default_population) @@ -942,7 +915,7 @@ def _report_build_params(self, rep_name, rep_conf, target, pop_offsets_alias_pop start_time, end_time, SimConfig.output_root, - electrode, + None, Nd.String(rep_conf["Scaling"]) if "Scaling" in rep_conf else None, rep_conf.get("ISC", "") )