1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
.. _write-tutorial:
.. currentmodule:: prody
Writing Tutorials
=================
.. contents::
:local:
This is a short guide for writing ProDy tutorials that are published as part
of online documentation pages, and also as individual downloadable PDF files.
Tutorial Setup
--------------
First go to :file:`doc` folder in ProDy package and generate necessary files
for your tutorial using :program:`start-tutorial.sh` script::
$ cd doc
$ ./start-tutorial.sh
Enter tutorial title: ENM Analysis using ProDy
Enter a short title: ENM Analysis
Enter author name: First Last
Tutorial folders and files are prepared, see tutorials/enm_analysis
This will generate following folder and files::
$ cd tutorials/enm_analysis/
$ ls -lgo
-rw-r--r-- 1 328 Apr 30 16:48 conf.py
-rw-r--r-- 1 395 Apr 30 16:48 index.rst
-rw-r--r-- 1 882 Apr 30 16:48 intro.rst
-rw-r--r-- 1 1466 Apr 30 16:48 Makefile
lrwxrwxrwx 1 13 Apr 30 16:48 _static -> ../../_static
Note that short title will be used as filename and part of the URL of the
online documentation pages.
If tutorial logo/image that you want to use is different from ProDy logo,
update the following line in :file:`conf.py`::
tutorial_logo = u'enm.png' # default is ProDy logo
tutorial_prody_version = u'' # default is latest ProDy version
Also, note ProDy version if the tutorial is developed for a specific release.
Style and Organization
----------------------
ProDy documentation and tutorials are written using `reStructuredText`_,
an easy-to-read/write file format. See `reStructuredText Primer`_ for a
quick introduction.
reStructuredText is stored in plain-text files with :file:`.rst` extension,
and converted to HTML and PDF pages using `Sphinx`_.
.. _reStructuredText: http://docutils.sourceforge.net/rst.html
.. _reStructuredText Primer: http://sphinx-doc.org/rest.html
.. _Sphinx: http://sphinx-doc.org/
:file:`index.rst` and :file:`intro.rst` files are automatically generated.
:file:`index.rst` file should include title and table of contents of the
tutorial. Table of contents is just a list of :file:`.rst` files that are
part of the tutorial. They be listed in the order that they should appear
in the final PDF file::
.. _enm-analysis:
.. use "enm-analysis" to refer to this file, i.e. :ref:`enm-analysis`
*******************************************************************************
ENM Analysis using ProDy
*******************************************************************************
.. add .rst files to `toctree` in the order that you want them
.. toctree::
:glob:
:maxdepth: 2
intro
Add more :file:`.rst` files as needed. See other tutorials in
:file:`doc/tutorials` folder as examples.
Input/Output Files
------------------
All files needed to follow the tutorial should be stored in
:file:`tutorial_name_files` folder. There is usually no need to provide
PDB files, as ProDy automatically downloads them when needed. Optionally,
output files can also be provided.
.. note::
Small input and output files that contain textual information may
be included in the :program:`git` repository, but please avoid including
large files in particular those that contain binary data.
Including Code
--------------
Python code in tutorials should be included using `IPython Sphinx directive`_.
In the beginning of each :file:`.rst` file, you should make necessary imports
as follows::
.. ipython:: python
from prody import *
from matplotlib.pylab import *
ion()
This will convert to the following:
.. ipython:: python
from prody import *
from matplotlib.pylab import *
ion()
Then you can add the code for the tutorial::
.. ipython:: python
pdb = parsePDB('1p38')
.. ipython:: python
pdb = parsePDB('1p38')
.. _IPython Sphinx Directive: http://ipython.org/ipython-doc/dev/development/ipython_directive.html
Including Figures
-----------------
IPython directive should also be used for including figures::
.. ipython:: python
@savefig tutorial_name_figure_name.png width=4in
plot(range(10))
@savefig tutorial_name_figure_two.png width=4in
plot(range(100)); # used ; to suppress output
``@savefig`` decorator was used to save the figure.
.. note::
Figure names needs to be unique within the tutorial and should be prefixed
with the tutorial name.
Note that in the second :func:`~matplotlib.pyplot.plot` call, we used a
semicolon to suppress the output of the function.
If you want to make modifications to the figure, save it after the last
modification::
.. ipython:: python
plot(range(10));
grid();
xlabel('X-axis')
@savefig tutorial_name_figure_three.png width=4in
ylabel('Y-axis')
Testing Code
------------
If there is any particular code output that you want to test, you can use
``@doctest`` decorator as follows::
.. ipython::
@doctest
In [1]: 2 + 2
Out[1]: 4
.. ipython::
@doctest
In [1]: 2 + 2
Out[1]: 4
Failing to produce the correct output will prevent building the documentation.
Publishing Tutorial
-------------------
To see how your :file:`.rst` files convert to HTML format, use the following
command::
$ make html
You will find HTML files in :file:`_build/html` folder.
Once your tutorial is complete and looks good in HTML (no code execution
problems), following commands can be used to generate a PDF file and
tutorial file achieves::
$ make pdf
$ make files
ProDy online documentation will contain these files as well as tutorial pages
in HTML format.
|