.. _configure_editor:

Configure Editor
################

|popy| is script driven, so it is very important to have a suitable editor installed on your system. 

We recommended that you use |npp| to edit |popy| text files. 

.. note:: 

    It is especially important that you follow the advice in :ref:`configure_notepadpp_tabs`. 

.. _notepadpp:

|npp|
===========

|npp| is a text editor that uses tabs and context highlighting, both of which are helpful when editing |popy| script files.

.. _install_notepadpp:

Install |npp|
--------------

Download the installer from https://notepad-plus-plus.org/download/ and run it.

If you install the 64-bit binary installer the default install directory is ``C:\Program Files\Notepad++``
but you may install |npp| at another location.

.. _configure_notepadpp_tabs:

Configure |npp| Tabs for Indentation
-------------------------------------

|popy| is written in |python|, and |python| does |not| like tabs for indentation. It is essential that you set this from within Notepad++:-

.. code-block::

    Settings->Preferences->Indentation->Indent Using: Space character(s)
 
The default tab size is 4, which is a sensible choice.

Note this means that when you hit the tab key you will get 4 space characters instead of a tab character. To check that this is the case do:-

.. code-block:: none

    View->Show Symbol->Show Space and Tab
 
Then |npp| will give you a faint orange dot for a space character and an arrow for a tab.  You are advised to delete any tabs you have in your \*.pyml files. 

Note that it is still possible to introduce tabs into your text file accidentally using cut and paste.

|python| using spaces instead of the more conventional curly brackets is an endearing, perhaps controversial, language feature. (See https://jayconrod.com/posts/101/how-python-parses-white-space
for a fairly balanced discussion of the pros and cons of white spacing.)

However |popy| uses |python|, so it is white space for us.

Configure |npp| Colouring
----------------------------

It is highly advisable to load in the PoPy xml syntax highlighting file. You do this by opening |npp| and doing:-

.. code-block::  

    Language->User Defined Language->Define your language...
    Import...
 
Then selecting the ``c:\PoPy\conf\notepadplusplus_popy.xml`` file.
 
You should then be able to open any \*.pyml file and see the variables coloured like this:-

.. code-block:: pyml                     

    DERIVATIVES: |
        # s[DEPOT,CENTRAL,PERI] = @dep_two_cmp_cl{dose:@bolus{amt:c[AMT]}}
        d[DEPOT] = @bolus{amt:c[AMT]} - m[KA]*s[DEPOT]
        d[CENTRAL] = (
            m[KA]*s[DEPOT] - s[CENTRAL]*m[CL]/m[V1] 
            - s[CENTRAL]*m[Q]/m[V1]  + s[PERI]*m[Q]/m[V2]
        )
        d[PERI] = s[CENTRAL]*m[Q]/m[V1] - s[PERI]*m[Q]/m[V2]
    PREDICTIONS: |
        p[DV_CENTRAL] = s[CENTRAL]/m[V1]
        var = m[ANOISE]**2 + m[PNOISE]**2 * p[DV_CENTRAL]**2
        c[DV_CENTRAL] ~ norm(p[DV_CENTRAL], var)
        
As opposed to the default (plain) |npp| text display, like this:-

.. code-block:: none

    DERIVATIVES: |
        # s[DEPOT,CENTRAL,PERI] = @dep_two_cmp_cl{dose:@bolus{amt:c[AMT]}}
        d[DEPOT] = @bolus{amt:c[AMT]} - m[KA]*s[DEPOT]
        d[CENTRAL] = (
            m[KA]*s[DEPOT] - s[CENTRAL]*m[CL]/m[V1] 
            - s[CENTRAL]*m[Q]/m[V1]  + s[PERI]*m[Q]/m[V2]
        )
        d[PERI] = s[CENTRAL]*m[Q]/m[V1] - s[PERI]*m[Q]/m[V2]
    PREDICTIONS: |
        p[DV_CENTRAL] = s[CENTRAL]/m[V1]
        var = m[ANOISE]**2 + m[PNOISE]**2 * p[DV_CENTRAL]**2
        c[DV_CENTRAL] ~ norm(p[DV_CENTRAL], var)

Note that it might be necessary to restart |npp| to get the colouring file to work.

We find that the variable colouring, makes model editing easier and less error prone. For example, if you misspell a section header e.g "DERVIATIVES", then you will notice because the section header will not appear in bold.

The colouring file also just makes |pkpd| models look nicer. 

.. only:: browser

    .. editor_next_steps:

    Next Steps
    ============

    Now you have your editor setup correctly take a look at :ref:`simple_fit_example`.



