next up previous
Next: Certain FORTRAN 90 concepts Up: Long Write-Up Previous: Long Write-Up

Problem

AUTO_DERIV is a software module facilitating the analytical computation of the first and second partial derivatives of, in principle, an arbitrarily complex,[*] continuous mathematical function of any number of independent variables. The mathematical function should be expressed as one or more FORTRAN procedures. It should be clarified that the package computes the numerical values of the derivatives at any given set of the independent variables and it does not deliver their analytical expressions.

Our motivation for developing AUTO_DERIV was the need to integrate and analyze classical trajectories in Molecular Dynamics simulations [1] by using realistic potential functions [2]. This requires the solution of Hamilton equations, and thus, the computation of the gradient of the Hamiltonian function, $\mathcal{H}(q_i, p_i)$, of the problem. qi are the generalized coordinates and pi their conjugate momenta for a system of n degrees of freedom. In mechanical systems, $\mathcal{H}$ is comprised of the kinetic energy, T--having a straightforward dependence on pi, and possibly, qi--and the potential energy V, which, as usual in our field, is a function of qi fitted to ab initio electronic structure calculations and/or empirical data, thus, lacking analytic expressions for the derivatives.

Some times, the location of a special type of trajectories, such as periodic orbits, and the computation of their stability properties (Lyapunov exponents), require the integration of the variational equations, and thus, the Hessian of the Hamiltonian function [3]. Hence, the need for an easy and accurate way of computing the first and second partial derivatives of multidimensional functions is a prerequisite in Molecular Dynamics simulations. Naturally, the need of accurate to machine precision derivatives instead of approximate ones arises in many fields of chemistry [4], mathematics, physics and engineering.

The potential functions and, therefore the Hamiltonians we use, are coded in FORTRAN and, thus, the language we chose to implement this tool was the one described in [5,6], commonly known as FORTRAN 90 (F90). By this standard, certain features and language constructs were introduced in FORTRAN, providing, among others, primitive support for value-oriented programming. Using derived types, function and operator overloading, and the encapsulation mechanism of modules, we constructed a concrete class which ``instructs'' the compiler how to apply the chain rule of differentiation to any mathematical function comprised of elementary, intrinsic FORTRAN 90 functions and to interpret appropriately all operators in order to compute the derivatives.

Commercial and Open Source symbolic algebra packages exist, which can evaluate derivatives of any order of relatively straightforward functions, or, rather, complex expressions of elementary functions and, even, encode them in a variety of programming languages [7,8,9]. They can not, however--to the best of our knowledge--input a complex FORTRAN 90, or, even a FORTRAN 77, piece of code implementing a mathematical function and compute the derivatives; at least, we are not aware of any publicly available software that does not require translation from FORTRAN to another programming language and a significant amount of modifications to the user code in order to accomplish the differentiation (with the partial exception of ADIFOR).

ADIFOR[10] is a, free for educational and non-profit research, tool for automatic differentiation, which, according to the user guide: ``accepts Fortran 77 source code (with a few common extensions) and the user's specification of dependent and independent variables, and generates an augmented derivative code that computes the partial derivatives of all of the specified dependent variables with respect to all of the specified independent variables in addition to the original result''. It can also report arithmetic exceptions. The main drawbacks of this package is that it does not accept F90/95 codes and that it computes only first derivatives making cumbersome the derivation of higher ones.


next up previous
Next: Certain FORTRAN 90 concepts Up: Long Write-Up Previous: Long Write-Up
Stavros Farantos
1999-12-11