## Determining the Adjacency Matrix for a Model

### What Is an Adjacency Matrix?

An adjacency matrix is a square matrix that provides information on reactants and products of reactions in a model. It lets you easily determine:

• The reactants and products in a specific reaction in a model

• The reactions that a specific species is part of, and whether the species is a reactant or product in that reaction

An adjacency matrix is an N-by-N matrix, where N equals the total number of species and reactions in a model. Each row corresponds to a species or reaction, and each column corresponds to a species or reaction.

The matrix indicates which species and reactions are involved as reactants and products:

• Reactants are represented in the matrix with a 1 at the appropriate location (row of species, column of reaction). Reactants appear above the diagonal.

• Products are represented in the matrix with a 1 at the appropriate location (row of reaction, column of species). Products appear below the diagonal.

• All other locations in the matrix contain a 0.

For example, if a model object contains one reaction equal to A + B -> C and the Name property of the reaction is R1, the adjacency matrix is:

A    B    C   R1
A    0    0    0   1
B    0    0    0   1
C    0    0    0   0
R1   0    0    1   0

### Retrieving an Adjacency Matrix for a Model

Retrieve an adjacency matrix for a model by passing the model object as an input argument to the getadjacencymatrix method.

1. Read in m1, a model object, using sbmlimport:

m1 = sbmlimport('lotka.xml');
2. Get the adjacency matrix for m1:

M =

(5,1)        1
(5,2)        1
(6,3)        1
(7,4)        1
(1,5)        1
(2,5)        1
(2,6)        1
(3,6)        1
(3,7)        1

'x'
'y1'
'y2'
'z'
'Reaction1'
'Reaction2'
'Reaction3'
3. Convert the adjacency matrix from a sparse matrix to a full matrix to more easily see the relationships between species and reactions:

M_full = full(M)
M_full =

0     0     0     0     1     0     0
0     0     0     0     1     1     0
0     0     0     0     0     1     1
0     0     0     0     0     0     0
1     1     0     0     0     0     0
0     0     1     0     0     0     0
0     0     0     1     0     0     0