#
# File:   MorrisLecar_cont.py
# Author: Warren Weckesser, www.warrenweckesser.net
#

from matplotlib.font_manager import FontProperties
import MorrisLecar
import PyDSTool

# Use the function created by VFGEN to define the 'args' object for
# the Morris-Lecar system.
ds = MorrisLecar.args()
# Set ics to (1.5,0).  This is not an equilibrium point, but
# with these values, the PyCont code will find one.
ds.ics = {'v':1.5, 'w':0.0}

ode = PyDSTool.Generator.Vode_ODEsystem(ds)

cont = PyDSTool.ContClass(ode)

print "Setting up for one parameter continuation of an equilibrium point."
PCargs = PyDSTool.args(name='EQ1',type='EP-C')
PCargs.freepars = ['ic']
PCargs.StepSize = 1e-3
PCargs.MaxNumPoints = 200
PCargs.MaxStepSize = 0.2
PCargs.LocBifPoints = ['LP','H','BP']

print "Computing the curve."
cont.newCurve(PCargs)
cont['EQ1'].forward()

print "Setting up for two parameter continuation of the Hopf point."
PCargs = PyDSTool.args(name='Hopf1', type='H-C2')
PCargs.initpoint = 'EQ1:H1'
PCargs.freepars = ['ic','gca']
PCargs.MaxStepSize = 1.0
PCargs.LocBifPoints = ['GH','BT','ZH']
PCargs.MaxNumPoints = 350

print "Computing the curve."
cont.newCurve(PCargs)
cont['Hopf1'].forward()
cont['Hopf1'].MaxNumPoints = 75
cont['Hopf1'].backward()

print "Setting up for two parameter continuation of the first limit point."
PCargs = PyDSTool.args(name='SN1', type='LP-C')
PCargs.initpoint = 'EQ1:LP1'
PCargs.freepars = ['ic','gca']
PCargs.MaxStepSize = 1.0
PCargs.LocBifPoints = ['CP','BT','ZH']
PCargs.MaxNumPoints = 100

print "Computing the curve."
cont.newCurve(PCargs)
cont['SN1'].forward()
cont['SN1'].backward()

print "Generating the plot in MorrisLecar_cont.png."
cont['Hopf1'].display(('ic','gca'))
cont['SN1'].display(('ic','gca'))
cont.plot.fig1.toggleAll('off',bytype='P')
axis([20, 200, 3, 9])
title('Morris-Lecar Bifurcation Diagram')
savefig('MorrisLecar_cont.png',dpi=64)
# show()

