Keywords: viewmol

# 14 Programming Your Own Input Filter

VIEWMOL can be easily adapted to read outputs of other programs or other file formats. All you have to do is to write a new input filter which extracts the data from the corresponding file. These input filters are stand-alone programs and can be written in every programming language you want. Examples in C and awk are included.

The input filter has to read the following data from the output file and write them to its standard output in the format described below. This format follows the file format of TURBOMOLE very closely. A few sections had to be extended to allow data which is currently not supported by TURBOMOLE (e. g. unit cells).

- the cartesian coordinates and atom symbols (required)
  Write to standard output in the following format:

        $coord factor
         x1   y1   z1   symbol1   xyz
         x2   y2   z2   symbol2   xyz
         ...

  `factor` is the conversion factor the coordinates have to be multiplied with to convert them to Ångstrøms. Any combination of x, y, and z at the end of the line (optional) indicates that the corresponding atom has been kept fixed in that direction during a geometry optimization. Consequently, VIEWMOL will not draw the forces acting on this atom in the fixed direction.
- the title (optional)
  Write to standard output in the following format:

        $title
        title

- the wave numbers and intensities (optional)
  Write to standard output in the following format:

        $vibrational spectrum
         symmetry1  wavenumber1  IR-intensity1  Raman-intensity1
         symmetry2  wavenumber2  IR-intensity2  Raman-intensity2
         ...

  `symmetry` is the symmetry label for the vibrational mode, `wavenumber` is its wave number and `IR-intensity` and `Raman-intensity` are its IR and Raman intensity, respectively. If the symmetry labels for the vibrational modes are unknown they should be set to a default (e. g. A1).
- normal coordinates (optional)
  Write to standard output in the following format:

        $vibrational normal modes
         i1   i2  nm(1,1)  nm(2,1)  nm(3,1)  nm(4,1)  nm(5,1)
         i1   i2  nm(6,1)  ...      nm(3*natom,1)
         i1   i2  nm(1,2)  nm(2,2)  nm(3,2)  nm(4,2)  nm(5,2)
         i1   i2  nm(6,2)  ...      nm(3*natom,2)
         ...
         i1   i2  nm(1,nmodes)      ...               nm(5,nmodes)
         i1   i2  nm(6,nmodes) ...  nm(3*natom,nmodes)

  `i1` and `i2` are integers which are skipped during reading. `nm(i,j)` are the normal mode coefficients. They have to be provided ordered by cartesian coordinates (all x components of the first atom first, then all y components of the first atom etc.).
- optimization history or MD trajectory (optional)
  Write to standard output in the following format:

        $grad factor
          cycle = nc SCF energy = E_nc |dE/dxyz| = gradnorm_nc
          [unitcell a b c alpha beta gamma]
          [unitcell vectors
           xa ya za
           xb yb zb
           xc yc zc]
          x1  y1  z1   symbol1
          x2  y2  z2   symbol2
          ...
          xn  yn  zn   symboln
          gx1 gy1 gz1
          gx2 gy2 gz2
          ...
          gxn gyn gzn
          cycle = nc+1 SCF energy = E_nc+1 |dE/dxyz| = gradnorm_nc+1
          ...

  `factor` is the conversion factor the coordinates have to be multiplied with to convert them to Ångstrøms. `nc` is a counter for the cycle, `E_nc` is the energy for the configuration of cycle nc, and `gradnorm_nc` is the gradient norm of cycle nc. The line starting with `unitcell` is optional and can be used to specify the current unit cell, e. g. during a constant pressure MD run. Unit cells can be specified either by providing the lengths of the edges and the angles between them or by providing the three vectors which span the unit cell. The `x`, `y`, and `z` are the cartesian coordinates for each atom, `symbol` is the atomic symbol. The `gx`, `gy`, and `gz` are the gradients for each atom. This structure can be repeated for as many cycles as necessary.
- MO energies and coefficients (optional)
  Write to standard output in the following format for closed shell systems:

        $scfmo [symmetrized] [gaussian]
             n symmetry_label_n eigenvalue=MO_E_n nsaos=norb
        moc(n,1) moc(n,2) moc(n,3) moc(n,4)
        moc(n,5) ...      moc(n,norb)
             n+1 symmetry_label_n+1 eigenvalue=MO_E_n+1 nsaos=norb
        ...

  or for open shell systems:

        $uhfmo_alpha [symmetrized] [gaussian]
             n symmetry_label_n eigenvalue=MO_E_n nsaos=norb
        moc(n,1) moc(n,2) moc(n,3) moc(n,4)
        moc(n,5) ...      moc(n,norb)
             n+1 symmetry_label_n+1 eigenvalue=MO_E_n+1 nsaos=norb
        ...

        $uhfmo_beta [symmetrized] [gaussian]
             n symmetry_label_n eigenvalue=MO_E_n nsaos=norb
        moc(n,1) moc(n,2) moc(n,3) moc(n,4)
        moc(n,5) ...      moc(n,norb)
             n+1 symmetry_label_n+1 eigenvalue=MO_E_n+1 nsaos=norb
        ...

  The string `symmetrized` is optional and can be used to notify VIEWMOL of the fact that the MO coefficients are with respect to symmetrized AOs rather than with respect to AOs. VIEWMOL needs moloch from the TURBOMOLE package to handle symmetrized AOs. If moloch is not installed and symmetrized AOs are input, MOs and electron densities cannot be drawn. The string `gaussian` is also optional and notifies VIEWMOL that the MO coefficients are normalized and ordered GAUSSIAN style. `n` is a counter counting the MOs, `symmetry_label_n` is the symmetry label for MO n, `MO_E_n` is the MO energy for MO n, and `norb` is the total number of orbitals. The `moc(n,i)` are the MO coefficients for MO n.
- basis functions and occupation numbers (optional)
  Write to standard output in the following format:

        $atoms
        atom_symbol1 list_of_indices1 \
          basis=basis_set_name1
        atom_symbol2 list_of_indices2 \
          basis=basis_set_name2
        ...
        $basis
        *
        basis_set_name1
        *
          number_of_primitives  angular_momentum
          exponent1   coefficient1
          exponent2   coefficient2
          ...
          exponentn   coefficientn
          number_of_primitives  angular_momentum
          ...
        *
        basis_set_name2
        *
          ...
        *
        $closed shells
          symmetry_label    list_of_indices   (2)
        $alpha shells
          symmetry_label    list_of_indices   (1)
        $beta shells
          symmetry_label    list_of_indices   (1)
        $pople   [6d/10f/15g]

  `atom_symbol` is the atom symbol of an element and `list_of_indices` contains the indices of all atoms of the particular element according to the list of coordinates read in under `$coord`. The list can be either comma separated and/or contain hyphens for indicating ranges (e. g. c 1,3,7-10 is a valid descriptor). `Basis_set_name` can be an arbitrary string describing a particular basis set. It is only used to find the corresponding basis set in the list read under `basis`. This list simply states the name for a basis set and then lists the primitive functions which make up a contracted Gaussians starting with the number of primitives in that particular contracted Gaussian and its angular momentum (s, p, d, f, ...). Than the exponents and contraction coefficients are listed line by line. This is repeated for all contracted Gaussians of that particular basis set. `$closed shells`, `$alpha shells`, and `$beta shells` are used to tell VIEWMOL which MOs are occupied with how many electrons. `symmetry_label` is the symmetry label for a number of MOs and `list_of_indices` is a list of integers stating which of the MOs of that particular symmetry are occupied by either one or two electron(s). This list can be either comma-separated or contain hyphens to indicate ranges of MOs. Note: `$closed shells`, `$alpha shells`, and `$beta shells` have to appear after `$scfmo` in the output written by the input filter. `$pople` is used to indicate that d, f, or g functions have 6, 10, or 15 components instead of 5, 7, or 9. Note: This data group has to appear after the `$coord` or `$grad` in the output. Otherwise VIEWMOL will fail.
- grid files
  Write to standard output in the following form:

        $grid #n
        origin x y z
        vector1 x y z
        vector2 x y z
        vector3 x y z
        grid1 start s delta d points np
        grid2 start s delta d points np
        grid3 start s delta d points np
        type ty
        title for this grid
        t
        plotdata
        d(1,1,1) d(1,1,2) d(1,1,n) ... d(1,2,1)
        ... d(1,n,n) d(2,1,1) ... d(n,n,n)

  here `n` is an integer identifying the grid. `origin` is used to specify the x, y, and z coordinates of the origin of the grid. `vector1`, `vector2`, and `vector3` are used to specify the three vectors spanning the grid. `grid1`, `grid2`, and `grid3` are used to specify the starting point, `s`, the step size, `d`, and the number of points, `np`, on each of the three vectors spanning the grid. `ty` can be either `mo` or `density` specifying whether the data represents a molecular orbital or a density. `t` is a string giving the grid a title which is used in the wave function dialog to allow the user to select the grid. Finally, `d(i,j,k)` are the values for the property at each grid point.
- the unit cell (optional)
  Write to standard output in one of the following forms:

        $unitcell    a    b    c   alpha   beta   gamma

  or

        $unitcell vectors
        xa ya za
        xb yb zb
        xc yc zc

  where each row contains the components of one of the three vectors spanning the unit cell (this is also known as the Bravais matrix).
- errors occuring during file processing (optional)
  Write to standard output in the following form:

        $error errorLabel severity additionalInformation

  `errorLabel` is an arbitrary one word label which refers to an error message in the resources. `severity` is a label for the severity of the error. Set it to 0 if the program can continue despite this error. Set it to 1 if the program must stop. `additionalInformation` is any additional information you want to be displayed in the error message (e. g. the name of a file which was not found). Currently, the following errorLabels are in use: `noFile`, `notConverged`, `unsupportedVersion`, `wrongFiletype`, `noCoordinates`, `noEnergy`, and `unknownErrorMessage`. If your input filter wants to return an error because it is missing coordinates in the input file ``dummy.inp" you can have it writing the following line to standard output:

        $error missingCoordinates 1 dummy.inp

  Then you have to specify a resource for the error message in
  `$HOME/.Xdefaults`:

        Viewmol.missingCoordinates: The file %s does not contain any coordinates.

  With these two lines in place any encounter of no coordinates in an input file will lead to the display of the error dialog in the Figure. There is no need to recompile VIEWMOL to achieve this.

The last line of the data written to standard output by the input filter must be `$end`.

Figure 17: The error dialog produced by the sample error message

The input filter can be installed by adding a line to the `viewmolrc` file.