# ANM Calculations¶

Required imports:

```In : from prody import *

In : from pylab import *

In : ion()
```

## Atom Selection¶

First, we parse p38 structure `p38.pdb`:

```In : p38 = parsePDB('conformational_sampling_files/p38.pdb')

In : p38
Out: <AtomGroup: p38 (5658 atoms)>
```

Let’s take a look at the structure:

```In : showProtein(p38);

In : legend();
``` Note that this structure has hydrogen atoms which were added using PSFGEN that comes with NAMD:

```In : p38.numAtoms('hydrogen')
Out: 2824
```

We will perform ANM calculations for 351 Cα atoms of the structure:

```In : p38_ca = p38.ca

In : p38_ca
Out: <Selection: 'ca' from p38 (351 atoms)>
```

## ANM Calculation¶

First, let’s instantiate an `ANM` object:

```In : p38_anm = ANM('p38 ca')

In : p38_anm
Out: <ANM: p38 ca (0 modes; 0 nodes)>
```

Now, we can build Hessian matrix, simply by calling `ANM.buildHessian()` method:

```In : p38_anm.buildHessian(p38_ca)

In : p38_anm
Out: <ANM: p38 ca (0 modes; 351 nodes)>
```

We see that `ANM` object contains 351 nodes, which correspond to the Cα atoms.

We will calculate only top ranking three ANM modes, since we are going to use only that many in sampling:

```In : p38_anm.calcModes(n_modes=3)

In : p38_anm
Out: <ANM: p38 ca (3 modes; 351 nodes)>
```

## Analysis & Plotting¶

Let’s plot mobility of residues along ANM modes:

```In : showSqFlucts(p38_anm);
``` We can also calculate collectivity of these modes as follows:

```In : for mode in p38_anm:
....:     print('{}\tcollectivity: {}'.format(str(mode), calcCollectivity(mode)))
....:
Mode 1 from ANM p38 ca	collectivity: 0.618084923455
Mode 2 from ANM p38 ca	collectivity: 0.585153336557
Mode 3 from ANM p38 ca	collectivity: 0.634434845453
```

## Visualization¶

You can visualize ANM modes using Normal Mode Wizard. You need to write an `.nmd` file using `writeNMD()` and open it using VMD:

```In : writeNMD('p38_anm.nmd', p38_anm, p38_ca)
Out: 'p38_anm.nmd'
```

For visualization, you can use `viewNMDinVMD()`, i.e. `viewNMDinVMD('p38_anm.nmd')`

## Extend Model¶

We want to use the ANM model to sample all atoms conformations of p38 MAPK, but we have a coarse-grained model. We will use `extendModel()` function for this purpose:

```In : p38_anm_ext, p38_all = extendModel(p38_anm, p38_ca, p38, norm=True)

In : p38_anm_ext
Out: <NMA: Extended ANM p38 ca (3 modes; 5658 atoms)>

In : p38_all
Out: <AtomMap: AtomGroup p38 from p38 (5658 atoms)>
```

Note `p38_anm_ext` is an `NMA` model, which has similar features to an `ANM` object. This extended model still has 3 modes, but 5668 atoms as opposed to 351 nodes in the original `ANM` model.

Let’s plot mobility of residues again to help understand what extending a model does:

```In : showSqFlucts(p38_anm_ext);
``` As you see, the shape of the mobility plot is identical. In the extended model, each atom moves in the same direction as the Cα atoms of the residue to which they belong. The mobility profile is scaled down, however, due to renormalization of the mode vectors.

## Save Results¶

Now let’s save the original and extended model, and atoms:

```In : saveAtoms(p38)
Out: 'p38.ag.npz'

In : saveModel(p38_anm)
Out: 'p38_ca.anm.npz'

In : saveModel(p38_anm_ext, 'p38_ext')
Out: 'p38_ext.nma.npz'
```

## More Examples¶

We have performed a quick ANM calculation and extended the resulting model to all atoms of of the structure. You can see more examples on this in Elastic Network Models tutorial.