# Using an External Matrix¶

This example shows how to use matrices from external software in `ANM` or `GNM` analysis of protein dynamics.

## Parse Hessian¶

We start by importing everything from the ProDy package:

```In : from prody import *

In : from matplotlib.pylab import *

In : ion()  # turn interactive mode on
```

The input file that contains the Hessian matrix has the following format (`oanm_hes.txt`):

```1       1    9.958948135375977e+00
1       2   -3.788214445114136e+00
1       3    6.236155629158020e-01
1       4   -7.820609807968140e-01
1       5    1.050322428345680e-01
1       6   -3.992616236209869e-01
1       7   -7.818332314491272e-01
1       8   -1.989762037992477e-01
1       9   -3.619094789028168e-01
1      10   -5.224789977073669e-01
...
```

`parseSparseMatrix()` can be used for parsing the above file:

```In : hessian = parseSparseMatrix('oanm_hes.txt', symmetric=True)

In : hessian.shape
Out: (1053, 1053)
```

## ANM calculations¶

Rest of the calculations can be performed as follows:

```In : anm = ANM('Using external Hessian')

In : anm.setHessian(hessian)

In : anm.calcModes()

In : anm
Out: <ANM: Using external Hessian (20 modes; 351 nodes)>
```

## Parse Kirchhoff¶

The input file that contains the Kirchhoff matrix has the following format (`ognm_kirchhoff.txt`):

``` 3316
1       1       5.00
1       2      -1.00
1       3      -1.00
1       4      -1.00
1      91      -1.00
1     343      -1.00
2       2      10.00
2       3      -1.00
2       4      -1.00
...
```
```In : kirchhoff = parseSparseMatrix('ognm_kirchhoff.txt',
....:                               symmetric=True, skiprows=1)
....:

In : kirchhoff.shape
Out: (351, 351)
```

## GNM calculations¶

Rest of the GNM calculations can be performed as follows:

```In : gnm = GNM('Using external Kirchhoff')

In : gnm.setKirchhoff(kirchhoff)

In : gnm.calcModes()

In : gnm
Out: <GNM: Using external Kirchhoff (20 modes; 351 nodes)>
```