|
1 | 1 | --- |
2 | | -layout: page |
| 2 | +layout: otherpage |
3 | 3 | title: Basic example |
4 | | -order: 1 |
5 | 4 | --- |
6 | 5 |
|
7 | 6 | A typical usage pattern is to iterate through a trajectory and analyze |
8 | 7 | coordinates for every frame. In the following example the end-to-end |
9 | 8 | distance of a protein and the radius of gyration of the backbone atoms |
10 | 9 | are calculated: |
11 | 10 |
|
12 | | -{% highlight python %} |
13 | | -import MDAnalysis |
14 | | -from MDAnalysis.tests.datafiles import PSF, DCD # test trajectory |
15 | | -import numpy.linalg |
| 11 | +<div class="wide-code"> |
| 12 | + {% highlight python %} |
| 13 | + import MDAnalysis |
| 14 | + from MDAnalysis.tests.datafiles import PSF, DCD # test trajectory |
| 15 | + import numpy.linalg |
16 | 16 |
|
17 | | -u = MDAnalysis.Universe(PSF,DCD) # always start with a Universe |
18 | | -# can access via segid (4AKE) and atom name |
19 | | -# we take the first atom named N and the last atom named C |
20 | | -nterm = u.select_atoms('segid 4AKE and name N')[0] |
21 | | -cterm = u.select_atoms('segid 4AKE and name C')[-1] |
| 17 | + # load trajectory and topology into a Universe |
| 18 | + u = MDAnalysis.Universe(PSF,DCD) |
| 19 | + # from the 4AKE segid, select |
| 20 | + # the first atom named N and the last atom named C |
| 21 | + nterm = u.select_atoms('segid 4AKE and name N')[0] |
| 22 | + cterm = u.select_atoms('segid 4AKE and name C')[-1] |
| 23 | + # select the backbone atoms (AtomGroup) |
| 24 | + bb = u.select_atoms('protein and backbone') |
22 | 25 |
|
23 | | -bb = u.select_atoms('protein and backbone') # a selection (AtomGroup) |
24 | | - |
25 | | -for ts in u.trajectory: # iterate through all frames |
26 | | - r = cterm.position - nterm.position # end-to-end vector from atom positions |
27 | | - d = numpy.linalg.norm(r) # end-to-end distance |
28 | | - rgyr = bb.radius_of_gyration() # method of AtomGroup |
29 | | - print("frame = {0}: d = {1} A, Rgyr = {2} A".format( |
30 | | - ts.frame, d, rgyr)) |
31 | | -{% endhighlight %} |
| 26 | + for ts in u.trajectory: # iterate through all frames |
| 27 | + r = cterm.position - nterm.position # end-to-end vector from atom positions |
| 28 | + d = numpy.linalg.norm(r) # end-to-end distance |
| 29 | + rgyr = bb.radius_of_gyration() # method of AtomGroup |
| 30 | + print("frame = {0}: d = {1} A, Rgyr = {2} A".format( |
| 31 | + ts.frame, d, rgyr)) |
| 32 | + {% endhighlight %} |
| 33 | +</div> |
32 | 34 |
|
33 | 35 | To find out what else you can do, head over to [learning |
34 | 36 | MDAnalysis]({{ site.baseurl }}/pages/learning_MDAnalysis) to have a look |
|
0 commit comments