nicolasmcnair / magpy

A Python toolbox for controlling Magstim TMS stimulators via serial communication
GNU General Public License v3.0
19 stars 4 forks source link

Using MagPy for continuous theta burst protocols. #12

Open Richard-2481 opened 4 months ago

Richard-2481 commented 4 months ago

Hi there,

First of all, this is an amazing library. Thank you so much for creating it!

I am running an experiment where I would like to deliver continuous theta burst stimulation (cTBS) for 5 seconds to participants using my lab's Magstim Rapid2.

cTBS is three pulses at 50Hz delivered at 5Hz intervals. i.e., pulse > 20ms > pulse > 20ms > pulse > 160ms > repeat.

This is easily doable using the machine's GUI using the following settings: Repetitive mode: Burst Setup Power <= 50% Frequency = 50Hz Burst Frequency = 5Hz Number of Pulses = 3 Number of Bursts = 25 Cycle Time > 5.0s Number of Cycles = 1

Currently I am facing two issues in achieving this via serial connection using the library.

Issue 1: I cannot instruct the machine to deliver three pulses at 50Hz.

When entering the parameters for a single burst, myMagstim.rTMSMode(True) myMagstim.setFrequency(50) myMagstim.setNPulses(3)

This means setDuration is calculated to 0.06. There is a minimum value of 0.1 and a value below this reverts the parameters back to single pulse mode. So executing this protocol results in a single pulse rather than three at 50Hz.

The only way I can keep the machine in rTMSMode is by setting the duration to the minimum value of 0.1. myMagstim.rTMSMode(True) myMagstim.setFrequency(50) myMagstim.setDuration(0.1)

This however calculates setNPulses to 5. So when I execute this protocol, I get 5 pulses at 50Hz.

Issue 2: The enforced 500ms delay between trains.

Even if I could solve issue 1, I can't deliver another burst of three pulses at 50Hz for another 440ms due to the enforced delay between trains.

Currently, the closest I can get to a standard cTBS protocol is 5 x 50Hz pulses delivered at 2Hz.

Is there a way I can modify the library, or manually send my own ASCII instructions to create a protocol that will deliver standard cTBS as is possible using the machine's GUI?

nicolasmcnair commented 4 months ago

Thanks for finding this! I will try and fix the set duration issue as soon as I can find some time. In terms of using MagPy to control TBS - with the current remote control documentation I have, it is not possible to set the number of bursts or burst frequency. I'll try reaching out to Magstim and see if they have updated the documentation regarding this.

Richard-2481 commented 4 months ago

Thanks for your quick reply! I have found a workaround by using serial communication to set the power, enable remote control, and enable single pulse mode, and then use TTL signals via a parallel port for triggering. This lets me fire any patterns I want by simply adjusting my TTL trigger timing in python.