================================================
 AutoDock Virtual Screening Tutorial Exercises
================================================

:Author: Lindy Lindstrom
:Contact: lindy@scripps.edu
:File: $Id: NOTES-vstutorial.txt,v 1.2 2004/09/09 18:51:42 lindy Exp $
:Revision: $Revision: 1.2 $

.. contents::


Virtual Screening Tutorial Exercises
============================================

General comments
------------------------------------------------------

use ``pwd`` and ``ls`` often
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you are unfamiliar with the Unix command line and/or navigating
around a hierarchical file system, use the ``pwd`` (print name of
current/working directory) and ``ls`` (list directory contents) shell
commands as much as you need to stay oriented in the file system.
It's always helpful to draw a quick picture.

use ``man`` often
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Use the ``man`` command copiously. Unix has a very useful on-line
manual that you can read with the ``man`` command.
For example, if you can't remember how to use the ``ls`` command to
list a directory contents with file modificaton dates, type ``man ls``.
This will display the on-line manual page which describes the ``ls``
command and allow you quickly learn how do it. ``man -k`` is a useful
option when you can't remember the name of the command you want to read
about. (Look up ``man -k`` in the on-line manual by typing ``man man``).


Exercise 1 - Populating the Ligand directory
------------------------------------------------------
:prerequisites: overview, data organization, data sources
:purpose:	Create a directory of pdb files which provide
                coordinates for the set of ligands.
:input:		``diversity.sdf``
:output:	``Ligands/*.pdb``
:software:	babel

Preamble
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* what is babel
* what is sdf
* other sources of data
* data organization

Step-by-step
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Create the directory in which all your Virtual Screening Tutorial
   activities will take  place. This should be done in the ``VSTutorial``
   directory::

     setenv VSTROOT `pwd`
     mkdir VirtualScreening

2. Create two subdirectories: one for the ligands (called ``Ligands``)
   and and another for some extra, helpful, miscellaneous files
   (called ``etc``)::

     cd VirtualScreening
     mkdir Ligands
     mkdir etc

   Also, copy the list of ligands that you will be
   using in this tutorial to the ``etc`` directory::
   
     cp ../ligand.list etc

3. Change directory to the ``Ligands`` subdirectory and take a look
   at the list of ligands::

     cd Ligands
     foreach f (`cat ../etc/ligand.list`)
     foreach? echo $f
     foreach? end

   (Typically, you would simply ``cat`` or ``more`` a file to view its
   contents, but here we wish introduce the ``foreach`` shell command).

4. Convert the ``.sdf`` file to a collection of pdb files::

     foreach f (`cat ../etc/ligand.list`)
     foreach? echo $f
     foreach? babel -isdf ../../diversity.sdf "$f"-"$f" -opdb diversity"$f".pdb
     foreach? end
     
5. Let's confirm that the ``foreach`` loop and ``babel`` did what we expected.
   List the pdb files. ``wc`` (word count) is useful for counting. Check
   that the number of pdb files matches the number of ligands in the
   ``ligand.list`` file::

     ls *.pdb
     ls *.pdb | wc -l
     wc -l ../etc/ligand.list

6. Finally, let's add a positive control to the list of ligands.
   Copy ``ind.pdb`` down from the tutorial files::

     cp ../../ind.pdb .



Exercise 2 - Processing the Ligands
------------------------------------------------------
:prerequisites: directory structure
:purpose:	Generate a directory of AutoDock-formatted (pdbq) files
                representing the set of ligands to be docked.
:input:		``Ligands/*.pdb`` or ``Ligands/*.mol2``
:output:	``Ligands/*.pdbq`` and ``ligand.list``
:software:	``prepare_ligand.py``


Preamble
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* The pdbq file format adds charges to atoms and specifies rotatable bonds.


Step-by-step
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Step-by-step instructions for the exercise (i.e. what to type).

1. The ``prepare_ligand.py`` script takes as input a pdb or mol2 file
   (specified on the command line with the ``-l`` switch) and writes
   a pdbq file with charges, root, and rotatable bonds defined. The ``-d``
   switch specifies the filename of a python dictionary that describes
   the atome types and other attributes of the set of input files processed.
   This information will be used in the next exercise::

     cd $VSTROOT/VirtualScreening/Ligands

     foreach f (`ls *.pdb`)
     foreach? echo $f
     foreach? ../../prepare_ligand.py -l $f -o "$f"q -d ../etc/ligand_dict.py
     foreach? end

Puzzle: write a ``foreach`` loop which prints the numbers from zero to
ninety-nine.


Exercise 3 - Determining the covering set of Atom Types
--------------------------------------------------------
:prerequisites: atom-types, Grid Parameter Files, Map files, autogrid3,
:purpose:	Determine what map files are necessary to describe
                the receptor to the set of ligands.
:input:		``Ligands/*.pdbq``
:output:	``etc/ligand_dict.py``
:software:	``examine_ligand_dict.py``

Preamble
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* How does autodock3 represent the receptor. 
* One grid map for each atom-type in the ligand (or set of ligands).

Step-by-step
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Step-by-step instructions for the exercise (i.e. what to type).

1. The ``examine_ligand_dict.py`` scripts reads the ``ligand_dict.py`` written
   in Exercise 2 and writes a summary describing the set of ligands to stdout.
   Here, we save the output in a file named ``summary.txt``::

     cd $VSTROOT/VirtualScreening/etc
     cp ../../examine_ligand_dict.py .
     examine_ligand_dict.py > summary.txt
     more summary.txt

Postscript
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Note which atom types are used.


Exercise 4 - Preparing the Receptor
------------------------------------------------------
:prerequisites: pdbqs, AutoDockTools
:purpose:	Create the receptor.pdbqs file required by autogrid3 by
                adding polar Hydrogens and assigning charges to the
                receptor pdb file.
:input:		``x1hpv.pdb``
:output:	``x1hpv.pdbqs``
:software:	AutoDockTools

Preamble
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* The ``Receptor`` directory is where we process the receptor once and
  only once. All the ligands will refer to this single receptor.
* AutoDockTools should be familar to you from the AutoDockTools tutorial.


Step-by-step
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Step-by-step instructions for the exercise (i.e. what to type).

1. Create a directory called ``Receptor`` and populate it with the
   supplied ``x1hpv.pdb`` file.
   ::

     cd $VSTROOT/VirtualScreening
     mkdir Receptor
     cp ../x1hpv.pdb Receptor
     cd Receptor

2. Use ``adt23`` to add Hydrogens, charges, and solvent parameters to the
   receptor. Write ``x1hpv.pdbqs``
   ::

     adt23

   * ADT -> Grid -> Macromolecule -> Read ->  select ``x1hpv.pdb``
   * click on ``Open``
   * When processing is complete, type in  ``x1hpv.pdbqs`` to write
     the file.



Exercise 5 - Preparing the Grid Parameter File(s)
------------------------------------------------------
:prerequisites: atom-types, Grid Parameter Files, Map files, autogrid3,
:purpose:	Create input files for one or more ``autogrid3`` calculations.
:input:		``1hpv.pdbqs``, ``1hpv.gpf``
:output:	``1hpv.gpf``, ``1hpv.gpf2``
:software:	AutoDockTools, ``examine_ligand_dict.py``, ``ligand_dict.py``

Preamble
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Grid parameters
* definition of grid location and extent, grid spacing, etc
* Atom-types, maps

Step-by-step
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Step-by-step instructions for the exercise (i.e. what to type).

2. Use ``adt23`` to write the Grid Parameter Files (gpf):

   * Grid -> Get Values from a GPF ->  select ``../../x1hpv.gpf``
   * Grid -> Set Map Types directly ->  type in  ``ACHNOS``
   * Grid -> Write GPF ->  type in ``x1hpv_1.gpf`` in Receptor subdirectory.
   * Grid -> Set Map Types directly ->  type in ``cbF``
   * Grid -> Write GPF ->  type in ``x1hpv_2.gpf`` in Receptor subdirectory.


Exercise 6 - Writing the Grid Maps
------------------------------------------------------
:prerequisites: directory structure, symbolic links, atom-types,
                6-atom-type limit, autogrid3
:purpose:	Use ``autogrid3`` to generate all the map files which
                describe the receptor to autodock3.
:input:		``x1hpv.pdbqs``, ``x1hpv.gpf``, 
:output:	``x1hpv*map*``
:software:	``autogrid3``, ``initADT23.csh``

Preamble
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* We'll work in the ``Receptor`` subdirectory and create symbolic links later.

Step-by-step
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Step-by-step instructions for the exercise (i.e. what to type).

1. Use ``autogrid3`` to create the grid map files::

     cd $VSTROOT/VirtualScreening/Receptor
     autogrid3 -p x1hpv_1.gpf -l x1hpv_1.glg
     autogrid3 -p x1hpv_2.gpf -l x1hpv_2.glg


Postscript & Segue
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
At this point, let's look at where we are in the process:
We've described the ligands (Exercises 1 & 2) and the receptor
(Exercises 4,5,6). Before we go on and make larger and larger
resource and time commitments to the virtual screening experiment,
let's make sure in the next exercise that the input files are valid.


Exercise 7 - Protocal Validation with Positive Control
--------------------------------------------------------------------
:prerequisites: symbolic links, AutoDock input and output files
:purpose:	Test and validate protocal on positive control before
                committing resources to the entire ligand library.
:input:		``x1hpv.*.map``, ``posctrl.pdbq``, 
:output:	``posctrl_x1hpv.dpf``, ``posctrl_x1hpv.dlg``
:software:	``prepare_dpf.py``, ``autodock3``, ``AutoDockTools``

Preamble
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* @@ review Docking Parameter Files
* @@ prepare_dpf.py used for the first time here
* @@ <ligand>_receptor naming convention
* @@ this is also a rehearsal for the ``foreach`` loop to come, so
  @@ take note of each step in the process
* @@ unix: ``ln -s``

Step-by-step
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Step-by-step instructions for the exercise (i.e. what to type).

1. Create a directory called ``ind_x1hpv`` in the ``etc`` directory::

     cd $VSTROOT/VirtualScreening/etc
     mkdir ind_x1hpv
     cd ind_x1hpv

2. Populate this directory with the docking input files::

     cp ../../Ligands/ind.pdbq .
     ln -s ../../Receptor/x1hpv.pdbqs .
     ln -s ../../Receptor/x1hpv*map* .
     ls -l

3. Create the Docking Parameter File with modified parameters modified to shorten
   the autodock3 run time by restricting the search::

     ../../../prepare_dpf.py -l ind.pdbq -r x1hpv.pdbqs -p ga_num_evals=25000 -p ga_run=2
     more ind_x1hpv.dpf

4. Run ``autodock3`` and examine the output::

     autodock3 -p ind_x1hpv.dpf -l ind_x1hpv.dlg
     tail ind_x1hpv.dlg

   We're primarily concerned that the docking completed successfully.
   The specific results are not important here. What's important is that
   the protocol used so far should produce reasonable input to ``autodock3``.


Postscript & Segue
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Now that we know that the protocol produces valid input files that
``autodock3`` can read, let's create the input files for each of the
ligands from Exercises 1 & 2.


Exercise 8 - Preparing the Docking Directories and Parameter Files
------------------------------------------------------------------
:prerequisites: Naming convention
:purpose:	Create directories and dpf files for each ligand.
:input:		``*.pdbq``
:output:	``<ligand>_x1hpv/<ligand>_x1hpv.dpf``
:software:	``foreach``, ``prepare_dpf.py``

Preamble
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* @@ directory structure
* @@ unix: basename, set <explanation 2>
* @@ Don't forget the ``cd ..`` at the end of this ``foreach`` loop !!

Step-by-step
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Step-by-step instructions for the exercise (i.e. what to type).

1. Create the ``Dockings`` directory::

     cd $VSTROOT/VirtualScreening
     mkdir Dockings
     cd Dockings

2. Create a subdirectory named ``<ligand>_x1hpv`` and populate it
   with the docking input files: a) the ``pdbq`` from the ``Ligands`` directory
   will be copied directly; b) the maps will be lined to the ``Receptor``
   directory; and, c) the ``dpf`` file will be create using ``prepare_dpf.py``
   ::

     foreach f (`ls ../Ligands/*.pdbq`)
     foreach? set name = `basename $f .pdbq`
     foreach? echo $name
     foreach? mkdir "$name"_x1hpv
     foreach? cd "$name"_x1hpv
     foreach? cp ../"$f" .
     foreach? ln -s ../../Receptor/x1hpv.pdbqs .
     foreach? ln -s ../../Receptor/x1hpv*map* .
     foreach? ../../../prepare_dpf.py -l `basename $f` -r x1hpv.pdbqs \
     ? -p ga_num_evals=1750000 \
     ? -p ga_pop_size=150 \
     ? -p ga_run=20 \
     ? -p rmstol=2.0
     foreach? cd ..
     foreach? end


Postscript & Segue
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The input files are all assembled!! @@


Exercise 9 - Launching the jobs
------------------------------------------------------
:prerequisites: Docking Log File (dlg), ``autodock3``
:purpose:	Run ``autodock3``.
:input:		``<ligand>_x1hpv/<ligand>_x1hpv.dpf``
:output:	``<ligand>_x1hpv/<ligand>_x1hpv.dlg``
:software:	``foreach``, ``autodock3``

Preamble
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* @@ computational resources: 
* @@ here we copy canned results

Step-by-step
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Step-by-step instructions for the exercise (i.e. what to type).

1. Create a file with a list of the dockings to run::

     cd $VSTROOT/VirtualScreening/Dockings
     ls > ../etc/docking.list

2. For the purposes of this tutorial, instead of running ``autodock3`` as
   you normally would) simply copy the results of a docking that we've
   done for you previously.
   ::

     foreach d (`cat ../etc/docking.list`)
     foreach? echo $d
     foreach? cd $d
     foreach? echo "autodock3 -p $d.dpf -l $d.dlg"
     foreach? cp ../../../Results/dlgs/"$d".dlg .
     foreach? cd ..
     foreach? end


Postscript & Segue
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Now the output files now exist @@


Exercise 10 - Analysing the Results
------------------------------------------------------
:prerequisites: <concepts students should know before the exercise>
:purpose:       Extract overview of results from all the dlg files.
:input:		``*.dlg`` files
:output:	sorted list of dockings.
:software:	``grep``, ``sort``, ``awk``, ``sed``

Preamble
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* <explanation 1>
* <explanation 2> One line for each cluster

* Suggestion: Edit a docking log file (dlg) in your favorite
  editor and search for the "^USER    Estimated Free Energy"
  line and cut and paste.

* Suggestion: Open and editor and type in the complex line in step 1 below.
  When you finally get it perfect, Cut and Paste it into the foreach?
  prompt.
  


Step-by-step
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Step-by-step instructions for the exercise (i.e. what to type).



1. Extract the Free Energy and Docked Energy from the dlg files.
   From the docking log files, use ``grep`` to extract the lines
   containing the binding energy and docked energy of each complex.
   Use ``sed`` and ``awk`` to process these lines into the final output::

     cd $VSTROOT/VirtualScreening/Dockings
     foreach d (`ls`)
     foreach? echo $d
     foreach? egrep "^USER    Estimated Free Energy of Binding|^USER    Final Docked Energy" $d/$d.dlg | sed "N;s/\n//" | awk  -v n=$d 'BEGIN {N=n} { print N"  "$8"  "$15}' > $d/$d.energies
     foreach? end

   Take a look at one of the results of what you just did::

     more diversity1988/diversity1988_x1hpv.energies

2. Save the best energy from each docking in a single file in
   the ``etc`` directory called ``all_energies.list``::
     
     touch ../etc/all_energies.list
     foreach d ( `ls` )
     foreach? echo $d
     foreach? head -1 $d/$d.energies >> ../etc/all_energies.list
     foreach? end

3. Sort the ``all_energies.list`` file to find your best docking::

     cd ../etc
     sort -k3n all_energies.list > all_energies.sort
     more all_energies.sort



Postscript & Segue
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Alternatively, the egrep regular expression could be modified to
match every single docked conformation, not just the cluster seeds.
Can you modify the expression appropriately? 



Exercise 11 - Examine Top dockings
------------------------------------------------------
:prerequisites: <concepts students should know before the exercise>
:purpose:	<purpose>
:input:		sorted list of dockings
:output:	<``ouput files``>
:software:	``AutoDockTools``

Preamble
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* <explanation 1>
* <explanation 2>

Step-by-step
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Step-by-step instructions for the exercise (i.e. what to type).


0. Start ADT::

     cd ../Dockings
     adt23
 
1. Setup viewer::

     * File->Preferences->Set Commands to be Applied on Objects
         - select  colorByAtomType
         - click on '>>'
         - click on 'OK'
     * File->Load Module
           -select hbondCommands
           -click on Load Module
           -select msmsCommands
           -click on Load Module
           -click on Dismiss

2.  Setup receptor.

     * Read in the file::

         File->Read Molecule
         -click on "PDB files (*.pdb)"
         -select "AutoDock files (pdbqs) (*.pdbqs)
         -select "x1hpv.pdbqs"

     * Set center of rotation::

         -click on PCOM level: Atom
         -click on down arrow at right of "PCOM printNodeNames"
         -select "centerOnNodes"
         -draw a box around the water residue

       (Box should be YELLOW if PCOM level is Atom).

     * Display msms surface::

         Compute->MSMS->Compute MSMS
             -click on OK
         
         Color->by Atom Type
             -click on MSMS-MOL
             -click on OK

      * Make molecular surface transparent using the DejaVu GUI::

         * Macros->DejaVuMac->showHideDejaVuGUI
             -click on + root
             -click on + x1hpv
             -select MSMS-MOL
             -click on Material: Front
             -change Opacity to .7
             -click on Material: None
             -select -root as current object in viewer

       * Close the DejaVu GUI::

           * Macros->DejaVuMac->showHideDejaVuGUI

       * ADJUST the view::

           * SHIFT-middlebutton to zoom in on water


3. FOR EACH DOCKING TO BE EVALUATED: (using diversity0619-x1hpv.dlg as example)
   1. Analyze->Docking Logs->Read Docking Log

      - select diversity0619_x1hpv.dlg
      - click on Open
      - click on OK

   2. Analyze->Clusterings->Show Clustering

     - write a printable version of histogram:
       - click on Edit->Write
       - enter "diversity0619_x1hpv.ps"
       - click on Save

     - to visualize lowest energy docked conformation
       -type d in the viewer to turn off depth-cueing
       -click on lowest energy bin in the histogram which opens
       -click on right arrow to set ligand to 1_1 conformation

     - assess
       - is the ligand in a pocket?
       - is each atom of the ligand in chemically favorable location

     - Build Hydrogen bonds
       - Hydrogen Bonds->Build->Set Parms + Build
       - click on Specify two sets:
       - click on (top) Molecule List
       - click on x1hpv
       - click on (lower) Clear Form #if this is not the first dlg read
       - click on (lower) Molecule List
       - click on diversity0619
       - click on Ok

      - Record number of hbonds formed

      - Visualize them

        - Hydrogen Bonds->Display->As Lines
        - display Distance(1.741) or Energy (-5.931)

   3. Clean-up for next docking log

       - click on Close on 'diversity0619' widget
       - click on File->Exit on 'diversity0619:rms = 2.0 clustering' histogram
       - Analyze->Docking Logs->Delete Docking Log


About this file
================
To convert this file from restructured text to html, use the ``html.py``
script from python's docutils project as follows::

  html.py -stg NOTES-virtual-screening.txt NOTES-virtual-screening.html

The ``-stg`` flags direct the translator to add the footer seen below.

..
   Local Variables:
   mode: rst
   indent-tabs-mode: nil
   sentence-end-double-space: t
   fill-column: 70
   End:
