title: python: interrupt odeint when a condition is met
body: <p>I am using odeint function from scipy.integrate package:</p>
  
  <pre><code>r0 = np.array([1,2,3,4])
  t=np.linspace(0,1,20)
  def drdt(r,t):
      return r # or whatever else
  r = odeint(drdt,r0,t)
  </code></pre>
  
  <p>r0 is a numpy array that contains the initial positions of a certain number of points.
  At the end of the script, as expected, I get the positions of the points at the 20 timestep.</p>
  
  <p>Now I would like to stop the odeint solver when a condition on r is met. In particular I would like to stop odeint when 2 of these points are closer than a certain threshold, make some changes on the r vector, and continue the odeint solver with the new initial positions.
  Is there a way to implement this?</p>
  
  <p>A possible solution I have been thinking is to run the odeint to the end, and just later check if the condition was met, but this is of course not very efficient.</p>
  
  <p>Thank you all for the help,
  Nicola</p>