.. _nonmem_advan_to_popy:
    
Nonmem Advan1,2,3,4,11,12 to |popy| analytic compartment models
#################################################################

:numref:`table_analytic_ode_conv` shows how to convert each |nonmem| inbuilt ADVAN analytic functions to |popy| equivalents.

See :ref:`$subroutines_advan_anal` for info on |nonmem| :ref:`$subroutines` section. 

Note to use the analytic compartment models in |popy| you should always set |ode_solver| as follows:-

.. code-block:: pyml

    ODE_SOLVER: {ANALYTIC:{}}
    
For more information on |popy| analytic functions see :ref:`cmp_funcs`.
    
.. _table_analytic_ode_conv:

.. list-table:: Nonmem to |popy| Analytic ODEs
    :header-rows: 1

    * - |nonmem|
      - ADVAN Parameters
      - |popy|
      - CMP Parameters
          
    * - :ref:`ADVAN1<advan1>`
      - K
      - :ref:`@iv_one_cmp_k`
      - KE
      
    * - :ref:`ADVAN1 TRANS2<advan1_trans2>`
      - CL/V
      - :ref:`@iv_one_cmp_cl`
      - CL/V
      
    * - :ref:`ADVAN2<advan2>`
      - KA/K
      - :ref:`@dep_one_cmp_k`
      - KA/KE
     
    * - :ref:`ADVAN2 TRANS2<advan2_trans2>`
      - KA/CL/V
      - :ref:`@dep_one_cmp_cl`
      - KA/CL/V
      
    * - :ref:`ADVAN3<advan3>`
      - K/K12/K21
      - :ref:`@iv_two_cmp_k`
      - KE/K12/K21
      
    * - :ref:`ADVAN3 TRANS4<advan3_trans4>` 
      - CL/V1/Q/V2
      - :ref:`@iv_two_cmp_cl`
      - CL/V1/Q/V2
      
    * - :ref:`ADVAN4<advan4>`
      - KA/K/K23/K32
      - :ref:`@dep_two_cmp_k`
      - KA/KE/K12/K21
      
    * - :ref:`ADVAN4 TRANS4<advan4_trans4>`
      - KA/CL/V1/Q/V2
      - :ref:`@dep_two_cmp_cl`
      - KA/CL/V1/Q/V2
      
    * - :ref:`ADVAN11<advan11>`
      - K/K12/K21/K13/K31
      - :ref:`@iv_three_cmp_k`
      - KE/K12/K21/K13/K31
      
    * - :ref:`ADVAN11 TRANS4<advan11_trans4>`
      - CL/V1/Q2/V2/Q3/V3
      - :ref:`@iv_three_cmp_cl`
      - CL/V1/Q2/V2/Q3/V3
      
    * - :ref:`ADVAN12<advan12>`
      - KA/K/K23/K32/K24/K42
      - :ref:`@dep_three_cmp_k`
      - KA/KE/K12/K21/K13/K31
     
    * - :ref:`ADVAN12 TRANS4<advan12_trans4>`
      - KA/CL/V2/Q3/V3/Q4/V4
      - :ref:`@dep_three_cmp_cl`
      - KA/CL/V1/Q2/V2/Q3/V3
      
.. _advan1:
    
ADVAN1
============
    
In |nonmem|:-

.. code-block:: none

    $SUBROUTINES  ADVAN1 
    
With following parameters defined in the |nonmem| $PK section:-

* K = elimination rate
    
Equivalent |popy| |derivatives| section:-

.. code-block:: pyml

    DERIVATIVES: |
        s[CEN] = @iv_one_cmp_k{dose: @bolus{amt:c[AMT]}, KE: m[KE]}
        
The |nonmem| parameters are mapped to |popy| as follows:-

* K -> KE
        
See :ref:`@iv_one_cmp_k`.
        

.. _advan1_trans2:
    
ADVAN1 TRANS2
====================
    
In |nonmem|:-

.. code-block:: none

    $SUBROUTINES  ADVAN1 TRAN2 
    
With following parameters defined in the |nonmem| $PK section:-

* CL = |clear|
* V = |vol|
    
Equivalent |popy| |derivatives| section:-

.. code-block:: pyml

    DERIVATIVES: |
        s[CEN] = @iv_one_cmp_cl{dose: @bolus{amt:c[AMT]}, CL: m[CL], V: m[V]}
        
The |nonmem| parameters are mapped to |popy| as follows:-

* CL -> CL
* V -> V
        
See :ref:`@iv_one_cmp_cl`.
        
.. _advan2:
    
ADVAN2
====================
    
In |nonmem|:-

.. code-block:: none

    $SUBROUTINES  ADVAN2
    
With following parameters defined in the |nonmem| $PK section:-

* KA = absorption rate
* K = elimination rate

Equivalent |popy| |derivatives| section:-

.. code-block:: pyml

    DERIVATIVES: |
        s[DEP,CEN] = @dep_one_cmp_k{dose: @bolus{amt:c[AMT]}, KA: m[KA], KE: m[KE]}
        
The |nonmem| parameters are mapped to |popy| as follows:-

* KA -> KA
* K -> KE
        
See :ref:`@dep_one_cmp_k`.


.. _advan2_trans2:
    
ADVAN2 TRANS2
====================
    
In |nonmem|:-

.. code-block:: none

    $SUBROUTINES  ADVAN2 TRAN2 
   
With following parameters defined in the |nonmem| $PK section:-

* KA = absorption rate
* CL = |clear|
* V = |vol|
   
Equivalent |popy| |derivatives| section:-

.. code-block:: pyml

    DERIVATIVES: |
        s[DEP,CEN] = @dep_one_cmp_cl{
            dose: @bolus{amt:c[AMT]}, 
            KA: m[KA], CL: m[CL], V: m[V]
        }
        
The |nonmem| parameters are mapped to |popy| as follows:-

* KA -> KA
* CL -> CL
* V -> V
        
See :ref:`@dep_one_cmp_cl`.
        
.. _advan3:
    
ADVAN3
====================
    
In |nonmem|:-

.. code-block:: none

    $SUBROUTINES  ADVAN3
    
With following parameters defined in the |nonmem| $PK section:-

* K = elimination rate from central compartment
* K12 = elimination rate from central to peripheral compartment
* K21 = elimination rate from peripheral to central compartment
    
Equivalent |popy| |derivatives| section:-

.. code-block:: pyml

    DERIVATIVES: |
        s[CEN,PERI] = @iv_two_cmp_k{
            dose: @bolus{amt:c[AMT]}, 
            KE: m[KE], K12: m[K12], K21: m[K21]}
   
The |nonmem| parameters are mapped to |popy| as follows:-

* K -> KE
* K12 -> K12
* K21 -> K21
    
See :ref:`@iv_two_cmp_k`.


.. _advan3_trans4:
    
ADVAN3 TRANS4
====================
    
In |nonmem|:-

.. code-block:: none

    $SUBROUTINES  ADVAN3 TRANS4
    
With following parameters defined in the |nonmem| $PK section:-

* CL = |clear| from central compartment
* V1 = |vol| for central compartment
* Q = |clear| between central and peripheral compartment
* V2 = |vol| for peripheral compartment
    
Equivalent |popy| |derivatives| section:-

.. code-block:: pyml

    DERIVATIVES: |
        s[CEN,PERI] = @iv_two_cmp_cl{
            dose: @bolus{amt:c[AMT]}, 
            CL: m[CL], V1: m[V1], Q: m[Q], V2: m[V2]}

The |nonmem| parameters are mapped to |popy| as follows:-

* CL -> CL
* V1 -> V1
* Q -> Q
* V2 -> V2

See :ref:`@iv_two_cmp_cl`.
            
.. _advan4:
    
ADVAN4
====================
    
In |nonmem|:-

.. code-block:: none

    $SUBROUTINES  ADVAN4
    
With following parameters defined in the |nonmem| $PK section:-

* KA = absorption rate from depot to central compartment
* K = elimination rate from central compartment
* K23 = elimination rate from central to peripheral compartment
* K32 = elimination rate from peripheral to central compartment
    
Equivalent |popy| |derivatives| section:-

.. code-block:: pyml

    DERIVATIVES: |
        s[DEP,CEN,PERI] = @dep_two_cmp_k{
            dose: @bolus{amt:c[AMT]}, 
            KA: m[KA], KE: m[KE], K12: m[K12], K21: m[K21]}
    
The |nonmem| parameters are mapped to |popy| as follows:-

* KA -> KA
* K -> KE
* K23 -> K12
* K32 -> K21
    
Note |popy| uses consistent parameter names between :ref:`@iv_two_cmp_k` (advan3) and :ref:`@dep_two_cmp_k` (advan4), whereas |nonmem| renumbers the parameters.
    
See :ref:`@dep_two_cmp_k`.


.. _advan4_trans4:
    
ADVAN4 TRANS4
====================
    
In |nonmem|:-

.. code-block:: none

    $SUBROUTINES  ADVAN4 TRANS4
    
With following parameters defined in the |nonmem| $PK section:-

* KA = absorption rate from depot to central compartment
* CL = |clear| from central compartment
* V2 = |vol| for central compartment
* Q = |clear| between central and peripheral compartment
* V3 = |vol| for peripheral compartment
    
Equivalent |popy| |derivatives| section:-

.. code-block:: pyml

    DERIVATIVES: |
        s[DEP,CEN,PERI] = @dep_two_cmp_cl{
            dose: @bolus{amt:c[AMT]}, 
            KA: m[KA], CL: m[CL], V1: m[V1], 
            Q: m[Q], V2: m[V2]}

The |nonmem| parameters are mapped to |popy| as follows:-

* KA -> KA
* CL -> CL
* V2 -> V1
* Q -> Q
* V3 -> V2

Note |popy| uses consistent parameter names between :ref:`@iv_two_cmp_cl` (advan3 trans 4) and :ref:`@dep_two_cmp_cl` (advan4 trans4), whereas |nonmem| renumbers the parameters.

See :ref:`@dep_two_cmp_cl`.

.. _advan11:
    
ADVAN11
====================
    
In |nonmem|:-

.. code-block:: none

    $SUBROUTINES  ADVAN11
    
With following parameters defined in the |nonmem| $PK section:-

* K = elimination rate from central compartment
* K12 = elimination rate from central to first peripheral compartment
* K21 = elimination rate from first peripheral to central compartment
* K13 = elimination rate from central to second peripheral compartment
* K31 = elimination rate from second peripheral to central compartment
    
Equivalent |popy| |derivatives| section:-

.. code-block:: pyml

    DERIVATIVES: |
        s[CEN,PERI1,PERI2] = @iv_three_cmp_k{
            dose: @bolus{amt:c[AMT]}, 
            KE: m[KE], K12: m[K12], K21: m[K21], 
            K13: m[K13], K31: m[K31]}
    
The |nonmem| parameters are mapped to |popy| as follows:-

* K -> KE
* K12 -> K12
* K21 -> K21
* K13 -> K13
* K31 -> K31
    
See :ref:`@iv_three_cmp_k`.

.. _advan11_trans4:
    
ADVAN11 TRANS4
====================
    
In |nonmem|:-

.. code-block:: none

    $SUBROUTINES  ADVAN11 TRANS4
    
With following parameters defined in the |nonmem| $PK section:-

* CL = |clear| from central compartment
* V1 = |vol| for central compartment
* Q2 = |clear| between central and first peripheral compartment
* V2 = |vol| for first peripheral compartment
* Q3 = |clear| between central and first peripheral compartment
* V3 = |vol| for second peripheral compartment
    
Equivalent |popy| |derivatives| section:-

.. code-block:: pyml

    DERIVATIVES: |
        s[CEN,PERI1,PERI2] = @iv_three_cmp_cl{
            dose: @bolus{amt:c[AMT]}, 
            CL: m[CL], V1: m[V1], Q2: m[Q2], 
            V2: m[V2], Q3: m[Q3], V3: m[V3]}
    
The |nonmem| parameters are mapped to |popy| as follows:-

* CL -> CL
* V1 -> V1
* Q2 -> Q2
* V2 -> V2
* Q3 -> Q3
* V3 -> V3

See :ref:`@iv_three_cmp_cl`.

.. _advan12:
    
ADVAN12
====================
    
In |nonmem|:-

.. code-block:: none

    $SUBROUTINES  ADVAN12
    
With following parameters defined in the |nonmem| $PK section:-

* KA = absorption rate from depot to central compartment
* K = elimination rate from central compartment
* K23 = elimination rate from central to first peripheral compartment
* K32 = elimination rate from first peripheral to central compartment
* K24 = elimination rate from central to second peripheral compartment
* K42 = elimination rate from second peripheral to central compartment
    
Equivalent |popy| |derivatives| section:-

.. code-block:: pyml

    DERIVATIVES: |
        s[DEP,CEN,PERI1,PERI2] = @dep_three_cmp_k{
            dose: @bolus{amt:c[AMT]}, 
            KA: m[KA], KE: m[KE], 
            K12: m[K12], K21: m[K21], 
            K13: m[K13], K31: m[K31]}
    
The |nonmem| parameters are mapped to |popy| as follows:-
    
* KA -> KA
* K -> KE
* K23 -> K12
* K32 -> K21
* K24 -> K13
* K42 -> K31
    
    
Note |popy| uses consistent parameter names between :ref:`@iv_three_cmp_k` (advan11) and :ref:`@dep_three_cmp_k` (advan12), whereas |nonmem| renumbers the parameters.
    
See :ref:`@dep_three_cmp_k`.


.. _advan12_trans4:
    
ADVAN12 TRANS4
====================
    
In |nonmem|:-

.. code-block:: none

    $SUBROUTINES  ADVAN12 TRANS4
    
With following parameters defined in the |nonmem| $PK section:-

* KA = absorption rate from depot to central compartment
* CL = |clear| from central compartment
* V2 = |vol| for central compartment
* Q3 = |clear| between central and first peripheral compartment
* V3 = |vol| for first peripheral compartment
* Q4 = |clear| between central and first peripheral compartment
* V4 = |vol| for second peripheral compartment
    
Equivalent |popy| |derivatives| section:-

.. code-block:: pyml

    DERIVATIVES: |
        s[DEP,CEN,PERI1,PERI2] = @dep_three_cmp_cl{
            dose: @bolus{amt:c[AMT]}, 
            KA: m[KA], 
            CL: m[CL], V1: m[V1], 
            Q2: m[Q2], V2: m[V2], 
            Q3: m[Q3], V3: m[V3]}
    
The |nonmem| parameters are mapped to |popy| as follows:-
    
* KA -> KA
* CL -> CL
* V2 -> V1
* Q3 -> Q2
* V3 -> V2
* Q4 -> Q3
* V4 -> V3
    
Note |popy| uses consistent parameter names between :ref:`@iv_three_cmp_cl` (advan11 trans 4) and :ref:`@dep_three_cmp_cl` (advan12 trans4), whereas |nonmem| renumbers the parameters.
    
See :ref:`@dep_three_cmp_cl`.
