title: MagPy: A Python toolbox for controlling Magstim transcranial magnetic stimulators.
abstract: To date, transcranial magnetic stimulation (TMS) studies manipulating stimulation parameters have largely used blocked paradigms. However, altering these parameters on a trial-by-trial basis in Magstim stimulators is complicated by the need to send regular (1Hz) commands to the stimulator. Additionally, effecting such control interferes with the ability to send TMS pulses or simultaneously present stimuli with high-temporal precision.
  
  
  
  This manuscript presents the MagPy toolbox, a Python software package that provides full control over Magstim stimulators via the serial port. It is able to maintain this control with no impact on concurrent processing, such as stimulus delivery. In addition, a specially-designed "QuickFire" serial cable is specified that allows MagPy to trigger TMS pulses with very low-latency.
  
  
  
  In a series of experimental simulations, MagPy was able to maintain uninterrupted remote control over the connected Magstim stimulator across all testing sessions. In addition, having MagPy enabled had no effect on stimulus timing - all stimuli were presented for precisely the duration specified. Finally, using the QuickFire cable, MagPy was able to elicit TMS pulses with sub-millisecond latencies.
  
  
  
  The MagPy toolbox allows for experiments that require manipulating stimulation parameters from trial to trial. Furthermore, it can achieve this in contexts that require tight control over timing, such as those seeking to combine TMS with fMRI or EEG.
  
  
  
  Together, the MagPy toolbox and QuickFire serial cable provide an effective means for controlling Magstim stimulators during experiments while ensuring high-precision timing.
authors.affiliation: School of Psychology, University of Sydney, Australia. Electronic address: nicolas.mcnair@sydney.edu.au.
authors.forename: Nicolas A
authors.initials: NA
authors.lastname: McNair
mesh_terms: D003198:Computer Simulation; D012984:Software; D013997:Time Factors; D050781:Transcranial Magnetic Stimulation / Q000295:instrumentation* / Q000379:methods*
keywords: Magstim; Python; Serial communication; TMS; Timing; Toolbox