Page 2 of 2

Re: Driving synaptic event using vecStim

Posted: Thu Feb 14, 2019 6:52 am
by rlindroos
* the setup works fine in regular neuron

Re: Driving synaptic event using vecStim

Posted: Thu Feb 14, 2019 8:53 am
by hines
look at nrn/src/nrnoc/netstim.mod for an analogy. You need to replace POINTER with BBCOREPOINTER and introduce
bbcore_write and bbcore_read implementations. Anything containing the string BBCORE is of interest.
I should update vecstim.mod to make it compatible with CoreNEURON.

Re: Driving synaptic event using vecStim

Posted: Mon Feb 18, 2019 2:36 am
by zyc
I tried to introduce "bbcore_write" and "bbcore_read" from netstim.mod into our vecstim.mod, but got some errors when compiling the mechanism file with CoreNEURON. The following shows modified code, did I do anything wrong?

Thanks!

Code: Select all


NEURON {
	THREADSAFE
	ARTIFICIAL_CELL VecStim
	BBCOREPOINTER ptr
}


ASSIGNED {
	index
	etime (ms)
	ptr
}

VERBATIM
#if NRNBBCORE /* running in CoreNEURON */

#define IFNEWSTYLE(arg) arg

#else /* running in NEURON */

/*
   1 means noiseFromRandom was called when _ran_compat was previously 0 .
   2 means noiseFromRandom123 was called when _ran_compart was previously 0.
*/
static int _ran_compat; /* specifies the noise style for all instances */
#define IFNEWSTYLE(arg) if(_ran_compat == 2) { arg }

#endif /* running in NEURON */
ENDVERBATIM

...... (INITIAL block, NET_RECEIVE block etc.)

VERBATIM
#include "nrnran123.h"

#if !NRNBBCORE
/* backward compatibility */
double nrn_random_pick(void* r);
void* nrn_random_arg(int argpos);
int nrn_random_isran123(void* r, uint32_t* id1, uint32_t* id2, uint32_t* id3);
#endif
ENDVERBATIM

VERBATIM
static void bbcore_write(double* x, int* d, int* xx, int *offset, _threadargsproto_) {
	/* error if using the legacy scop_exprand */
	if (!_p_ptr) {
		fprintf(stderr, "NetStim: cannot use the legacy scop_negexp generator for the random stream.\n");
		assert(0);
	}
	if (d) {
		uint32_t* di = ((uint32_t*)d) + *offset;
		if (_ran_compat == 1) {
			void** pv = (void**)(&_p_ptr);
			/* error if not using Random123 generator */
			if (!nrn_random_isran123(*pv, di, di+1, di+2)) {
				fprintf(stderr, "NetStim: Random123 generator is required\n");
				assert(0);
			}
		}else{
			nrnran123_State** pv = (nrnran123_State**)(&_p_ptr);
			nrnran123_getids3(*pv, di, di+1, di+2);
		}
		/*printf("Netstim bbcore_write %d %d %d\n", di[0], di[1], di[3]);*/
	}
	*offset += 3;
}
static void bbcore_read(double* x, int* d, int* xx, int* offset, _threadargsproto_) {
	assert(!_p_ptr);
	if (noise) {
		uint32_t* di = ((uint32_t*)d) + *offset;
		nrnran123_State** pv = (nrnran123_State**)(&_p_ptr);
		*pv = nrnran123_newstream3(di[0], di[1], di[2]);
	}else{
		return;
	}
	*offset += 3;
}
ENDVERBATIM


Re: Driving synaptic event using vecStim

Posted: Mon Feb 18, 2019 11:16 am
by ted
hines wrote: Thu Feb 14, 2019 8:53 amI should update vecstim.mod to make it compatible with CoreNEURON.
The file distributed with NEURON is called vecevent.mod, even though it defines the properties of an ARTIFICIAL_CELL class called VecStim. Among my own files, I find something called vecstim.mod from 2002, the source code for which differed from vecevent.mod, and which became deprecated by 2008 if not earlier. Looking to the future, wouldn't it be best to abandon vecstim.mod and base new development on vecevent.mod? zyc, are you so far along in your own code development that you are now stuck with vecstim.mod?

Re: Driving synaptic event using vecStim

Posted: Mon Feb 18, 2019 11:47 am
by hines
i've updated vecevent.mod (VecStim)
Just need to test with coreneuron.
When it is working I'll push to the github repository and mention that here.

Re: Driving synaptic event using vecStim

Posted: Mon Feb 18, 2019 12:08 pm
by hines
vecevent.mod has been updated to be compatible with CoreNEURON. See
https://github.com/neuronsimulator/nrn/ ... 64f9402219

This kind of VERBATIM code is quite painful. I need to consider an NMODL syntax for easily describing the use of Random variables and Vectors in
mod files that automatically generate the bbcore_write and bbcore_read functions.

Re: Driving synaptic event using vecStim

Posted: Wed Feb 20, 2019 1:17 am
by zyc
It works, thank you so much.