Keywords: developer_man

Next: 8 File Formats Up: User's Guide for the Previous: 6 The routines of Contents

# 7 Suggestion for developers

If you plan to add something to the `PHonon` package follow these simple rules:

- All quantities that do not require the perturbed wavefunctions, are calculated in setup or by calling a separate routine in `phq_init`.

- The quantities that require the perturbed wavefunctions due to an electric field are calculated by a separate routine after `solve_e` in the routine `phescf`.

- The quantities that require the perturbed wavefunctions due to an atomic displacement are accumulated by calling a separate routine in phqscf after `solve_linter`. NB: the perturbed wavefunctions are saved in a file that is rewritten at each new `irrep`.

- After calculating a quantity, it has to be saved in the directory `outdir` in an `.xml` file, by adding it to the list of variables in the routine `write_tensors` (preferable), or by writing a routine similar to `write_tensors` that writes a separate file. The same quantity must be read by `read_tensors` or by writing a separate routine.

- If you introduce the calculation of a new quantity in the phonon code and save it in the `.xml` file, please add also the associated flags that control the calculation: `lquantity` is read in input and tells `ph.x` that that quantity must be calculated, `done_quantity` tells `ph.x` that that quantity was available in the `.xml` files and should not be recalculated, `comp_quantity` can be introduced if the quantity depends on q or on the frequency and tells `ph.x` that that quantity must be calculated in this run. The image controller can divide the work among images by setting the array `comp_quantity`. At each q point and at each frequency the quantity must be saved in the `.xml` file. Please update the image controller to add the additional work that the calculation of your quantity involves and make a single image calculate it or divide the work among different images.

- Please, try to avoid opening files inside routines. Files must be opened in `openfilq` and closed in `close_phq`.

- Global variables must be allocated in `allocate_phq`, directly in the routine, or by calling a separate routine that allocates all your new variables. The same variables must be deallocated in `deallocate_phq`, by a separate routine or by adding them to the list of variables. Note that at each new q point these variables are deallocated and reallocated.

- Variables that control the grid should not be deallocated at each new q point must be allocated in `allocate_grid_variables` and deallocated in `destroy_status_run`. A few arrays that must be read from input are allocated in `phq_readin` after reading their size and deallocated in `destroy_status_run`.

- Preferably global variables are calculated by in a single routine and used by the other routines. In particular routines are not allowed to modify:
  - The variables calculated by `pw.x`.
  - The modes.
  - The variables that describe the symmetry of the small group of q.
  - The variables that describe the response of the ultrasoft quantities (e.g. `int1`, `int2`, ..., `alphasum`, `becsum`, `dpqq`, etc.).
  If you need to modify these quantities, please allocate new variables and copy the variables of the phonon on them.

- If you want to establish a new recover point, add the appropriate `rec_code` in the list above. The point in which the code stopped is saved in `prefix.phsave/status_run.xml`.

If you are searching for some interesting project to contribute to the `PHonon` package, please read the header of `phonon.f90` and implement some feature that is not yet ready. Ideally all quantities should be at level [10], presently level [5] is still experimental and some quantities are at level [1].

Next: 8 File Formats Up: User's Guide for the Previous: 6 The routines of Contents