# diffusion testing
IM = InternalModel()
IM.add_node('a') # no degradation

IM2 = InternalModel()
IM2.add_node('a','linear',params=[0.5])
IM2.add_node('b','linear',params=[1])
eid = IM2.add_edge('b','b','hill_activ',params=[1,1,2])
IM2.add_edge('a',eid,'lin_activ',is_mod=True,mod_type='mult',params=[5])

cell1 = Cell([0])
cell2 = Cell([1])
cell3 = Cell([3])

sim = Simulation()
sim.add_cell(cell1)
sim.add_cell(cell2)
sim.add_cell(cell3)

im_id = sim.add_internal_model(IM)
im_id2 = sim.add_internal_model(IM2)

connections = np.array([[True,True,False],[True,True,True],[False,True,True]])

sim.set_internal_model([0,1],im_id)
sim.set_internal_model([2],im_id2)
sim.add_interaction('a','a','diffusion',connections,params=[1])

sim.set_initial_conditions([0],{'a':0})
sim.set_initial_conditions([1],{'a':6})
sim.set_initial_conditions([2],{'a':0,'b':1})
# mystery species m things
# u -> m
IM.add_edge('u','m','hill_activ',params=[1.0/Tm,4e-6,6])
# m -| yan
IM.add_edge('m',uy_edge,'hill_inactiv',is_mod=True,mod_type='mult',params=[1.0,1.0,0.7,3])

# need to make some cells 
# the 1d case is easy:
# in our 'lattice', all the cells are distance 1 apart
NCells = 60
cells = [Cell([x]) for x in np.linspace(1,NCells,NCells)]

# add these cells to the simulation
sim = Simulation()
for i in xrange(NCells):
    sim.add_cell(cells[i])

im_id = sim.add_internal_model(IM)

# set all cells to have the same internal model
sim.set_internal_model(range(NCells),im_id)

# set boundary conditions before setting intercellular interactions
sim.set_boundary_conditions([0],'ref_on')

# cells adjacent to one another are connected
# for diffusion we include main diagonal
# equivalent to 3 wide diagonal
diff_connections = (np.eye(NCells,k=-1) + np.eye(NCells,k=0) + np.eye(NCells,k=1)) > 0

# add diffusion to h and u
from Simulation import *
import matplotlib.pyplot as plt

# exclusive bistability test:
# two nodes inhibiting one another

IM = InternalModel()
IM.add_node('a','linear',[0.2])
IM.add_node('b','linear',[0.2])
IM.add_edge('a','b','hill_inactiv',params=[2.0,2.0,2.0,2])
IM.add_edge('b','a','hill_inactiv',params=[2.0,2.0,2.0,2])

cell = Cell()
sim = Simulation()
sim.add_cell(cell)
im_id = sim.add_internal_model(IM)

sim.set_internal_model([0],im_id)
sim.set_initial_conditions([0],{'a':5.0,'b':4.0})

t = np.linspace(0,100,1000)
cdata = sim.simulate(t)

plt.plot(t,cdata[0])
plt.legend(['a','b'])
plt.show()