# 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 [1]: from prody import *

In [2]: from matplotlib.pylab import *

In [3]: 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 [4]: hessian = parseSparseMatrix('oanm_hes.txt', symmetric=True)

In [5]: hessian.shape
Out[5]: (1053, 1053)
```

## ANM calculations¶

Rest of the calculations can be performed as follows:

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

In [7]: anm.setHessian(hessian)

In [8]: anm.calcModes()

In [9]: anm
Out[9]: <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 [10]: kirchhoff = parseSparseMatrix('ognm_kirchhoff.txt',
....:                               symmetric=True, skiprows=1)
....:

In [11]: kirchhoff.shape
Out[11]: (351, 351)
```

## GNM calculations¶

Rest of the GNM calculations can be performed as follows:

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

In [13]: gnm.setKirchhoff(kirchhoff)

In [14]: gnm.calcModes()

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