8
Computer Physics Communications 185 (2014) 294–301 Contents lists available at ScienceDirect Computer Physics Communications journal homepage: www.elsevier.com/locate/cpc POTLIB2Math:A Mathematica interface to the potential energy surface library for chemical systems Aaron M. Tagliaboschi, Jeremy B. Maddox Department of Chemistry, Western Kentucky University, Bowling Green, KY 42101-1079, USA article info Article history: Received 12 June 2013 Accepted 14 August 2013 Available online 28 August 2013 Keywords: Potential energy surface Chemical reaction POTLIB Mathematica abstract The theoretical description of molecular dynamics proceeds from the specification of an appropriate Born–Oppenheimer potential energy surface (PES) or surfaces. For many chemical systems, such surfaces are incorporated within a repository of standardized FORTRAN codes known as POTLIB. The present work describes a Mathematica package that uses a MathLink interface to interactively call POTLIB subroutines from within a Mathematica session. This allows for rapid prototyping and deployment of new algorithms and is useful for both pedagogical and research applications in chemical physics. We present basic usage of the package functions and several simple applications for illustration. Program summary Program title: POTLIB2Math Catalogue identifier: AEQJ_v1_0 Program summary URL: http://cpc.cs.qub.ac.uk/summaries/AEQJ_v1_0.html Program obtainable from: CPC Program Library, Queen’s University, Belfast, N. Ireland Licensing provisions: Standard CPC licence, http://cpc.cs.qub.ac.uk/licence/licence.html No. of lines in distributed program, including test data, etc.: 63859 No. of bytes in distributed program, including test data, etc.: 1481706 Distribution format: tar.gz Programming language: C, FORTRAN, and Mathematica. Computer: Developed and tested on GNU/Linux PC, Macintosh, and Windows PC platforms running Mathematica version 8 or higher. Operating system: Tested on MacOSX, SUSE Linux, and WindowsXP/7/8. RAM: Varies depending on user-defined applications. Classification: 16.8. External routines: GNU make, gcc, gfortran, Mathematica, and MathLink DeveloperKit Subprograms used: Cat Id Title Reference ADPJ_v1_0 POTLIB 2001 CPC 144(2002)169 Nature of problem: POTLIB [1, 2] is a collection of FORTRAN subprograms that calculate potential energy surfaces and gradients for various chemical systems as a function of molecular geometry. The objective of this work is to develop an interface that allows users to interactively execute POTLIB subprograms from within a Mathematica session. Solution method: POTLIB2Math is a fully-documented Mathematica package that uses a MathLink interface for passing data between Mathematica and POTLIB subprograms. GNU make and C/FORTRAN compilers are used to automate building the executables on various platforms. This paper and its associated computer program are available via the Computer Physics Communication homepage on ScienceDirect (http://www.sciencedirect.com/ science/journal/00104655). Corresponding author. Tel.: +1 270 745 8725. E-mail address: [email protected] (J.B. Maddox). URL: http://people.wku.edu/jeremy.maddox (J.B. Maddox). 0010-4655/$ – see front matter © 2013 Elsevier B.V. All rights reserved. http://dx.doi.org/10.1016/j.cpc.2013.08.011

POTLIB2Math: A Mathematica interface to the potential energy surface library for chemical systems

Embed Size (px)

Citation preview

Page 1: POTLIB2Math: A Mathematica interface to the potential energy surface library for chemical systems

Computer Physics Communications 185 (2014) 294–301

Contents lists available at ScienceDirect

Computer Physics Communications

journal homepage: www.elsevier.com/locate/cpc

POTLIB2Math: A Mathematica interface to the potential energysurface library for chemical systems✩

Aaron M. Tagliaboschi, Jeremy B. Maddox ∗

Department of Chemistry, Western Kentucky University, Bowling Green, KY 42101-1079, USA

a r t i c l e i n f o

Article history:Received 12 June 2013Accepted 14 August 2013Available online 28 August 2013

Keywords:Potential energy surfaceChemical reactionPOTLIBMathematica

a b s t r a c t

The theoretical description of molecular dynamics proceeds from the specification of an appropriateBorn–Oppenheimer potential energy surface (PES) or surfaces. For many chemical systems, such surfacesare incorporatedwithin a repository of standardizedFORTRAN codes known asPOTLIB. The presentworkdescribes aMathematica package that uses aMathLink interface to interactively call POTLIB subroutinesfrom within aMathematica session. This allows for rapid prototyping and deployment of new algorithmsand is useful for both pedagogical and research applications in chemical physics. We present basic usageof the package functions and several simple applications for illustration.

Program summary

Program title: POTLIB2MathCatalogue identifier: AEQJ_v1_0Program summary URL: http://cpc.cs.qub.ac.uk/summaries/AEQJ_v1_0.htmlProgram obtainable from: CPC Program Library, Queen’s University, Belfast, N. IrelandLicensing provisions: Standard CPC licence, http://cpc.cs.qub.ac.uk/licence/licence.htmlNo. of lines in distributed program, including test data, etc.: 63859No. of bytes in distributed program, including test data, etc.: 1481706Distribution format: tar.gzProgramming language: C, FORTRAN, and Mathematica.Computer: Developed and tested on GNU/Linux PC, Macintosh, and Windows PC platforms runningMathematica version 8 or higher.Operating system: Tested on MacOSX, SUSE Linux, and WindowsXP/7/8.RAM: Varies depending on user-defined applications.Classification: 16.8.External routines: GNU make, gcc, gfortran, Mathematica, and MathLink DeveloperKitSubprograms used:Cat Id Title ReferenceADPJ_v1_0 POTLIB 2001 CPC 144(2002)169

Nature of problem:POTLIB [1, 2] is a collection of FORTRAN subprograms that calculate potential energy surfaces andgradients for various chemical systems as a function of molecular geometry. The objective of this workis to develop an interface that allows users to interactively execute POTLIB subprograms from within aMathematica session.Solution method:POTLIB2Math is a fully-documented Mathematica package that uses a MathLink interface for passingdata between Mathematica and POTLIB subprograms. GNU make and C/FORTRAN compilers are used toautomate building the executables on various platforms.

✩ This paper and its associated computer program are available via the Computer Physics Communication homepage on ScienceDirect (http://www.sciencedirect.com/science/journal/00104655).∗ Corresponding author. Tel.: +1 270 745 8725.

E-mail address: [email protected] (J.B. Maddox).URL: http://people.wku.edu/jeremy.maddox (J.B. Maddox).

0010-4655/$ – see front matter© 2013 Elsevier B.V. All rights reserved.http://dx.doi.org/10.1016/j.cpc.2013.08.011

Page 2: POTLIB2Math: A Mathematica interface to the potential energy surface library for chemical systems

A.M. Tagliaboschi, J.B. Maddox / Computer Physics Communications 185 (2014) 294–301 295

Running time:The examples included in the distribution file take just a few minutes to run.References:

[1] R.J. Duchovic, Y.L. Volobuev, G.C. Lynch, A.W. Jasper, D.G. Truhlar, T.C. Allison, A.F.Wagner, B.C. Garrett,J. Espinosa-García, and J.C. Corchado, POTLIB, http://comp.chem.umn.edu/potlib.

[2] R.J. Duchovic, Y.L. Volobuev, G.C. Lynch, D.G. Truhlar, T.C. Allison, A.F. Wagner, B.C. Garrett, and J.C.Corchado, Comput. Phys. Comm. 144, 169–187 (2002). Comput. Phys. Comm. 156, 319–322(E) (2004).

© 2013 Elsevier B.V. All rights reserved.

1. Introduction

A crucial step in the study of molecular dynamics involvesspecification of the Born–Oppenheimer potential energy surface(PES) or surfaces that describe the interactions among atoms inthe chemical system of interest. Over the course of many decades,various groups have developed PES models for specific chemicalproblems [1]. In recent times, these are constructed using high-accuracy electronic structure calculations in combination withnumerical fitting [2]. Such work has resulted in a wide array ofuseful codes that calculate potential energies and energy gradientsas a function of molecular geometry.

In the early-2000s, a concerted effort was made to establish alibrary of FORTRAN-based PES subprograms using a standardizedexecution protocol. This collection is referred to as POTLIB2001and is available from the CPC Program Library [3]. A larger reposi-tory of PES programs is also currently available via the internet [4]and includes the original set of POTLIB2001 subroutines. Here-after, we shall refer to POTLIB2001 as simply POTLIB; however,it is implied that we are referring to the subset of PES subprogramsthat conform to the 2001 standardized interface.

In addition to PES subprograms, POTLIB also includes severalinterface codes for external applications that use potential ener-gies and energy gradients as input. For example, the VENUS96 [5]program can be usedwithPOTLIB subprograms to initialize, prop-agate, and analyze ensembles of the molecular dynamics trajecto-ries [6]. Likewise, interface codes are available for the ABCRATE [7]and POLYRATE [8] programs that calculate kinetic rate constantsusing generalized transition state theory methods [9].

The present work describes a new interface package calledPOTLIB2Math that links POTLIB subprograms with Mathemat-ica [10]. The latter is a commercially available high-level pro-gramming language distributed byWolframResearch andprovidesextensive plotting capabilities and numerical analysis tools.POTLIB2Math is somewhat different from typical applicationsin that no specific additional calculations are performed. Rather,the package is used to interactively execute POTLIB subprogramsfrom within a Mathematica session, thus allowing a user to designtheir own applications.We are hopeful that this will provide a con-venient development platform for students, researchers, and en-thusiasts of chemical physics.

The next section discusses the general structure and installationrequirements of the POTLIB2Math package. Sections 3 and 4provide basic usage and illustrative applications of the package’sprimary functions, and Section 5 concludes with a brief summary.

2. Program description

2.1. General description

POTLIB2Math is a fully-documented Mathematica packagethat usesMathLinkprotocols to interfaceMathematica and POTLIB

subprograms. The package consists of two primary components:(1) a POTLIB interface involving C and FORTRAN code forexecuting PES subroutines; and (2) a Mathematica package file forcalling the interface.

During installation, individual PES subprograms from a localPOTLIB repository are compiled and linked with the interfacecode resulting in a single executable for each PES subprogram.This is a fairly automated process, facilitated by GNU make, thatrequires setting a few system-specific variables in a configurationfile. After the POTLIB binaries are built, the package is then copiedinto a local Mathematica installation. PES subprograms may thenbe loaded during a Mathematica session and interactively calledwith different user-supplied molecular geometries. Furthermore,multiple PES subprograms can be loaded simultaneously allowingfor convenient comparative analysis of different potential models.

2.2. Installation and execution requirements

Detailed installation instructions may be found within thepackage file POTLIB2Math/INSTALL. Below we address thesoftware requirements needed to compile the package. However,once the package is built, it can be transferred to other computersthat use the same operating system. A local installation ofMathematica and the compiled POTLIB2Math package are theonly requirements for execution.

A standard Linux-type shell environment is required to buildthe package. In addition to the standard commands, this shouldsupport rsync, which is used to synchronize source code betweenPOTLIB and POTLIB2Math. Such tools are typically included aspart of the operating system on most GNU/Linux and MacOSXplatforms. A terminal emulator, such as Cygwin, can be used forWindows-based systems.

A local repository of POTLIB source code is required forinstallation. The POTLIB2Math directory tree can be stored underthe POTLIB2001/Section_1/Applications subdirectory.

GNU make, gcc, and gfortran (or equivalent) are alsorequired. GNU/Linux distributions and Cygwin typically comewitha package manager from which the GNU tools can be obtained.For MacOSX they are available as add-ons for the XCode developerapplication. Installation proceeds from a Makefile, stored underPOTLIB2Math/Interface, that is manually configured byediting several system-dependent variable settings in the fileconf.inc. Configuration file templates for GNU/Linux, MacOSX,and Windows/Cygwin are included within the package.

Finally, a recent version of Mathematica must be installed forboth installation and execution. For installation, the MathLinkDeveloperKit, which includes the pre-compiler mprep and system-dependentMathLink libraries, is also required.

2.3. POTLIB interface

The source code for the POTLIB interface is containedwithin the subdirectory POTLIB2Math/Interface/src. The

Page 3: POTLIB2Math: A Mathematica interface to the potential energy surface library for chemical systems

296 A.M. Tagliaboschi, J.B. Maddox / Computer Physics Communications 185 (2014) 294–301

Fig. 1. Screen-shot of the POTLIB2Math documentation menu, which is accessedfrom within Mathematica’s Documentation Center. Hyper-links point to individualreference pages and tutorials for working with the package.

files pot.c and pot.h provide simple wrapper functions sothat the subroutines PREPOT and POT, which are common to allPOTLIB subprograms, may be executed via MathLink. The filepotlib.h defines parameters, data structures, and function dec-larations used to access POTLIB common blocks and subrou-tines. The heart of the interface code is contained within the filepotlib2math.c, which calls MathLink functions that pass databack and forth betweenMathematica and POTLIB subprograms. Arelated file pot.tm is a MathLink template file containing decla-rations for the package’s primary functions. During compilation,this file is interpreted by the MathLink’s pre-compiler mprep togenerate a source code file pot.tm.c. This code is then com-piled and linked with all the other object files to build a set ofPES executables. As per the guidelines established in Ref. [3], theset of files tester.h, tester.c, and testerprint.f are usedto test the interface without directly invokingMathematica. Lastly,utility.f is a POTLIB source file containing a set of commonsubroutines used by all PES subprograms.

2.4. Package file

Various components of the interface are defined within thepackage file POTLIB2Math/POTLIB2Math.m. This code includesusage declarations, option definitions, syntax structure, warningmessages, parameters, and function definitions used on theMathematica-side of the interface. The package functions and theiroptions are described in a series of detailed reference pages andtutorials. These are storedwithin the subdirectoryPOTLIB2Math/Documentation; however, they are designed to be accessed fromwithinMathematica’s Documentation Center, as shown in Fig. 1.

3. Basic usage

3.1. Loading the package

The POTLIB2Math package is loaded like any other externalMathematica package and must be done so prior to calling itsfunctions or loading POTLIB subprograms:

In[1]:= << POTLIB2Math‘

This prepends a new context "POTLIB2Math‘" to Mathematica’s$ContextPath variable:

In[2]:= $ContextPathOut[2]= {"POTLIB2Math‘", ...}

Hereafter,we shall use... to symbolize truncated input or output.Loading the package also appends a pair of directories to the$Pathvariable:

In[3]:= $PathOut[3]= {..., ".../POTLIB2Math/Interface/src_potlib/",".../POTLIB2Math/Interface/bin/"}

which allows various files and executable PES subprograms to beeasily found when needed.

3.2. InstallPOTLIB

The InstallPOTLIB function is used to both find and loadPOTLIB subprograms. A list of subprogram names is generated bycalling InstallPOTLIBwith no arguments:

In[4]:= InstallPOTLIB[]Out[4]= {"brh2dim3c", "brh2leps", ...}

The first few letters of a subprogram’s name generally indi-cate the chemical system to which it corresponds. For example,the brh2dim3c subprogram [11,12] and the brh2leps subpro-gram [13] listed in the output above start with brh2 and cor-respond to the bromine dihydrogen system. Each subprograminvolves a uniquemodel and/or parametrization, and there are dif-ferent models available for some chemical systems.

An individual PES subprogram is loaded intoMathematica usingInstallPOTLIB with the subprogram’s name expressed as astring enclosed in double quotes as the first argument:In[5]:= link = InstallPOTLIB["brh2dim3c", NDER -> 1]Out[5]= LinkObject[".../brh2dim3c.x", 79, 4]

This returns a Mathematica LinkObject associated with therunning subprogram. Most package functions require an activeLinkObject as their first argument; therefore, it is advantageousto set a new symbol equal to the resulting output, e.g., link in theexample above. Using unique symbols as handles allows multiplePES subprograms to be installed and used simultaneously.

POTLIB subprograms utilize several common blocks to per-form various tasks. When a given subprogram is first loaded,InstallPOTLIB sets the USRICM common block, which storesuser-selected input data. These values can be configured using theoptions listed in Table 1. The example above includes the optionspecification NDER->1, which sets the derivative control flag to 1so that energy gradients will be calculated. Detailed explanationsfor each option are available within the package’s documentationand some of the examples presented in this communication willinvoke these.

InstallPOTLIB uses a pair of internal (private context)functions to initialize a POTLIB subprogram. The functionWriteUSRICM checks through the user-selected options andpasseswell-formeddata to theUSRICM commonblock. Anomalous

Page 4: POTLIB2Math: A Mathematica interface to the potential energy surface library for chemical systems

A.M. Tagliaboschi, J.B. Maddox / Computer Physics Communications 185 (2014) 294–301 297

Table 1Options for InstallPOTLIB and optional arguments for the set of ReadXXXXCMfunctions. Note that InstallPOTLIB and ReadUSRICM have the same optionnames. InstallPOTLIB uses rule-based option assignments (i.e., opt ->val ).ReadXXXXCM functions use keyword arguments.

InstallPOTLIB Input/output descriptionReadUSRICM

CART Cartesian coordinates (user-selected)ANUZERO Zero of potential energy (user-selected)NULBL Atomic ordering (user-selected)NFLAG Integer control flagsNASURF Potential energy surface control flagsNDER Integer derivative control flag

ReadINFOCM Output description

CARTNU Cartesian coords. (developer-selected)INDEXES Atomic numbers (developer-selected)IRCTNT Reactant index (developer-selected)NATOMS Total number of atomsICARTR Coordinate conversion flagMDER Maximum derivative orderMSURF Maximum energy excited state indexREF Bibliographic reference(s)

ReadUSROCM Output description

PENGYGS Ground state potential energyPENGYES Excited state potential energiesPENGYIJ Off-diagonal potential energiesDGSCART Ground state potential energy gradientDESCART Excited state potential energy gradientsDIJCART Off-diagonal potential energy gradients

input triggers an errormessage and cleanly terminates the subpro-gram. After the USRICM common block is properly set, the func-tion PREPOT is automatically called to initialize the subprogramfor calculations. Users familiar with FORTRAN-based applicationsof POTLIB subprograms are likely accustomed to calling PREPOTdirectly. However, because PREPOT should only be called once perapplication, its use in the POTLIB2Math package is restricted.

3.3. POT

Potential energy calculations are manually executed with thePOT function using an active LinkObject as a single argument:

In[6]:= POT[link]Out[6]= 0

which returns a value of zero for a successful exit. The outputof the potential energy calculation is stored in the POTLIBsubprogram’s USROCM common block. Functions for manuallyretrieving commonblock data are described in the next subsection.Driver functions for predefined calculations that directly returndata are described later.

3.4. ReadINFOCM, ReadUSIRCM, and ReadUSROCM

Three functions are used to retrieve data from the com-mon blocks of a POTLIB subprogram. Each requires an activeLinkObject as the first argument, and the optional argumentslisted in Table 1 restrict the information returned.

General parameters and reference information are storedin the INFOCM common block, and the ReadINFOCM functionextracts this data. For example, the values of NATOMS (numberof atoms) and INDEXES (atomic numbers) are retrieved from thebrh2dim3c subprogram as follows:

In[7]:= ReadINFOCM[link, NATOMS, INDEXES]Out[7]= {3, {35, 1, 1}}

User-selected input data is stored in the USRICM commonblock and ReadUSRICM is useful for verifying this data. The next

example returns the current value for the Cartesian coordinatesand checks the derivative control flag:

In[8]:= ReadUSRICM[link, CART, NDER]Out[8]= {{{0., 0., 0.}, {0., 0., 0.},{0., 0., 0.}}, 1}

where we see that the default value for CART places all threeatoms at the origin, and that the derivative control flag (i.e., NDER)is currently set to 1. If we had used the CART->val optionfor InstallPOTLIB in In[5], then Out[8] would return datavalues specified by val .

ReadUSROCM is used to retrieve output data from the USROCMcommon block. Here, we check the values of PENGYGS (groundstate energy) and DGSCART (ground state Cartesian gradient):

In[9]:= ReadUSROCM[link, PENGYGS, DGSCART]Out[9]= {Indeterminate, {{NaN‘, NaN‘, NaN‘},{NaN‘, NaN‘, NaN‘}, {NaN‘, NaN‘, NaN‘}}}

These somewhat alarming results are due to the fact that thebromine and hydrogen atoms are currently located at the origin,which is quite unphysical.

3.5. WriteCART

Users will want to frequently change the Cartesian coordinatesover the course of working with a subprogram. One way toaccomplish this is with the WriteCART function, which takes thesubprogram’s LinkObject and a set of newCartesian coordinatesas the first and second arguments, respectively:

In[10]:= X0 = {{1., 0., 0.}, {0., 0., 0.},{-1., 0., 0.}};

In[11]:= WriteCART[link, X0]Out[11]= 0In[12]:= ReadUSRICM[link, CART]Out[12]= {{1., 0., 0.}, {0., 0., 0.},

{-1., 0., 0.}}

The first line sets a list of coordinates X0 that places the Bratom at position (1, 0, 0) and the two H atoms at (0, 0, 0) and(−1, 0, 0), where the default unit of length is Bohr. WriteCARTreturns a value of zero for a successful exit, and ReadUSRICMverifies the change of coordinates. Next, we issue a call to POT andReadUSROCM:

In[13]:= POT[link];In[14]:= ReadUSROCM[link, PENGYGS, DGSCART]Out[14]= {1.24362, {{-1.93956, 0., 0.},{1.27864, 0., 0.}, {0.660919, 0., 0.}}}

which returns the ground state energy (Hartree) and energygradient (Hartree/Bohr) evaluated at the configuration X0.

3.6. CalcPENGYGS and CalcUSROCM

The preceding examples have illustrated manual manipulationof a POTLIB subprogram. However, POTLIB2Math also providesa pair of predefined calculations that expedite input/outputprotocols for common calculations. Both functions require aLinkObject and a set of Cartesian coordinates as arguments.CalcPENGYGS is used to update the Cartesian coordinates,execute a potential energy calculation, and retrieve the groundstate potential energy:

In[15]:= CalcPENGYGS[link, X0]Out[15]= 1.24362

CalcUSROCM is similar to CalcPENGYGS; however, it retrievesthe entire USROCM common block:

Page 5: POTLIB2Math: A Mathematica interface to the potential energy surface library for chemical systems

298 A.M. Tagliaboschi, J.B. Maddox / Computer Physics Communications 185 (2014) 294–301

In[16]:= data = CalcUSROCM[link, X0]Out[16]= {1.24362, {}, {}, {{-1.93956, 0., 0.},{1.27864, 0., 0.}, {0.660919, 0., 0.}}, {}, {}}

where we have set the resulting output equal to a new symboldata. USROCM data is structured as follows: (1) PENGYGS, theground state potential energy; (2) PENGYES, a list of excited statepotential energies, (3) PENGYIJ, a list of off-diagonal potentialenergy matrix elements; (4) DGSCART, the Cartesian gradientof the ground state potential energy; (5) DESCART, a list ofCartesian gradients for the excited state potential energies; and(6) DIJCART, a list of Cartesian gradients for the unique off-diagonal potential energymatrix elements. Excited state quantitiesare not calculated by this particular subprogram, and so thesequantities are returned as empty lists (i.e., {}).

Different elements of the CalcUSROCM output can be quicklyextracted using the short-hand syntax for Mathematica’s Partfunction. For example:

In[17]:= data[[4, {1, 2}, 1]]Out[17]= {-1.93956, 1.27864}

selects only the x-components of the Cartesian gradient for the firstand second atoms.

3.7. UninstallPOTLIB

A list of actively running subprograms is generated using theUninstallPOTLIB command with no arguments:

In[18]:= UninstallPOTLIB[]Out[18]= {LinkObject[.../brh2dim3c.x", 79, 4]}

This is useful for identifying PES subprograms over the course ofa Mathematica session. An individual subprogram is terminatedusing UninstallPOTLIB with the corresponding LinkObjectas a single argument:

In[19]:= UninstallPOTLIB[link]Out[19]= ".../brh2dim3c.x"

which closes the subprogram and clears several internal symbolsthat were created when the subprogram was first installed.

4. Applications

In this section we explore a few representative applicationsfacilitated by the POTLIB2Math package. By design, we have keptthese as simple as possible; however, more complex and moreinteresting applications can easily be imagined.

4.1. Comparing potential energy curves

The first application simply involves comparing diatomicpotential energy curves for several hydrogen halide species.Consequently, it also serves to illustrateworkingwithmultiple PESsubprograms simultaneously.

Diatomic potential energy curves can be derived from theasymptotic regions of an appropriately chosen triatomic PES. Inparticular, we shall use the hf2eleps [14], clhbreleps [15],brh2leps [13], ih2eleps [16] subprograms for the HF2, ClHBr,BrH2, and IH2 chemical systems, respectively. These were chosenbecause each triatomic molecule corresponds to an HX species inone asymptote and also because each subprogram involves a sim-ilar potential model, i.e., the London–Eyring–Polanyi–Sato (LEPS)model [17] or the related extended LEPS model [14].

The following worker function is defined in order to install agiven subprogram and automatically configure the zero of poten-tial energy to be located at the completely dissociated triatomicsystem:

In[20]:= SetZero[name_] :=Module[{link, Xdis, E0},link = InstallPOTLIB[name,

NFLAG -> {1 -> 2, 2 -> 6}];Xdis = 10.^6*{{-1., 0., 0.}, {0., 0., 0.},

{1., 0., 0.}};E0 = CalcPENGYGS[link, Xdis];UninstallPOTLIB[link];link = InstallPOTLIB[name, ANUZERO -> E0,

NFLAG -> {1 -> 2, 2 -> 6}];Return[link];];

The function first installs a subprogram name and sets the NFLAGoption to change the units of distance and energy from Bohr andHartree to Å and kJ/mol, respectively (see the package’s internaldocumentation for details). The potential energy E0 is calculatedfor a dissociated configuration Xdis, which positions the threeatoms very far from one another along the x-axis. The subprogramis then terminated and restartedwhile setting the zero of potentialenergy to E0 using the ANUZERO option. Finally, the LinkObjectfor the configured subprogram is returned as output. The followingblock of code then installs the set of triatomic PES subprograms andassigns a unique handle for each LinkObject:

In[21]:= link1 = SetZero["hf2eleps"];In[22]:= link2 = SetZero["clhbreleps"];In[23]:= link3 = SetZero["brh2leps"];In[24]:= link4 = SetZero["ih2eleps"];

Next, we introduce a function to convert from diatomicbond length (our desired coordinate) to the triatomic Cartesiancoordinates used by the PES subprograms:

In[25]:= R2X[r_] := {{0., 0., 0.}, {r, 0., 0.},{10.^6, 10.^6, 10.^6}};

where the first atom is positioned at the origin, the secondatom is located at some variable distance r along the x-axis, andthe third atom is placed very far away. Using this coordinatetransformation, we can then simply plot the various potentialcurves usingMathematica’s Plot function:

In[26]:= Plot[{CalcPENGYGS[link1, R2X[r]],CalcPENGYGS[link2, R2X[r]],CalcPENGYGS[link3, R2X[r]],CalcPENGYGS[link4, R2X[r]]}

, {r, .5, 3},...];

where we have omitted various plotting options. The graphicaloutput shown in Fig. 2 provides a useful conceptual tool forrationalizing periodic trends in chemical bonding, i.e., atom size,bond strength/length, and relative acidity.

The last command in this example:

In[27]:= UninstallPOTLIB /@ UninstallPOTLIB[];

illustrates a convenient short-cut for terminating all activesubprograms.

4.2. Pedagogical approximations

Next, we consider an application that determines modelparameters for the harmonic and Morse oscillator approximationsof H2. The model potential functions are defined by

VHO(r) =12k(r − re)2 (1)

VMorse(r) = De1 − e−β(r−re)

2(2)

Page 6: POTLIB2Math: A Mathematica interface to the potential energy surface library for chemical systems

A.M. Tagliaboschi, J.B. Maddox / Computer Physics Communications 185 (2014) 294–301 299

Fig. 2. Comparison of diatomic potential energy curves for several hydrogen halidespecies. This is a useful diagram for rationalizing relative acidities, i.e., HF with itsshort bond length and large well depth is considered a weak acid; HCl, HBr, HI areconsidered to be strong acids.

where r is a bond length coordinate, re is the equilibrium bondlength, De is the well depth, k is the force constant, and β =√k/(2De) is the Morse oscillator shape parameter.We begin by installing the h3dmbe subprogram for triatomic

hydrogen [18]:In[28]:= link = InstallPOTLIB["h3dmbe", NDER -> 1];

Note that we have set the derivative control flag in anticipation ofthe application described in the next subsection, which involvesforce calculations. For now, we define a function that calculatespotential directly from bond length:In[29]:= VR[r_] := CalcPENGYGS[link, R2X[r]];

By default, the h3dmbe subprogram sets the zero of potential at aconfiguration corresponding to an isolated H atom and H2 diatomat the equilibrium bond length. Therefore, the well depth is givenby evaluating the diatomic potential energy function at a largevalue of bond length:In[30]:= De = VR[10.^6]Out[30]= 0.174474

Mathematica’s NMinimize function is used to locate theminimumalong the diatomic potential energy curve and define theequilibrium bond length:In[31]:= soln = NMinimize[{VR[r], r > 0}, r]Out[31]= {1.81159*10^-10, {r -> 1.401}}In[32]:= re = r /. soln[[2]]Out[32]= 1.401

A simple finite difference formula is used to numerically computethe force constant and define the shape parameter:In[33]:= dr = .0001;In[34]:= ke = (VR[re - dr] - 2*VR[re]

+ VR[re + dr])/dr^2Out[34]= 0.364301In[35]:= Be = Sqrt[0.5*ke/De]Out[35]= 1.02176

The following functions define the harmonic andMorse oscilla-tor potential curves:In[36]:= VHO[r_] := .5*ke*(r - re)^2;In[37]:= VMorse[r_] := De*(1 - Exp[-Be*(r - re)])^2;

which can be visually compared using the Plot function:In[38]:= Plot[{VR[r], VHO[r], VMorse[r]},{r, .1, 8.},...];

The graphical output is shown in Fig. 3 and provides a useful ped-agogical illustration of the strengths and weaknesses of approx-imate potential energy models. Further exercises might involvecalculating and analyzing vibrational eigenstates or examining thefirst excited state potential energy curve.

Fig. 3. Comparison of the h3dmbe potential (diatomic asymptote) with theharmonic and Morse oscillator models.

4.3. Phase space trajectories

A slightly more advanced application involves calculatingclassical phase space trajectories. Here, we also work with H2 andutilize code from the previous subsection. The present example,however, also requires the reduced diatom mass:

In[39]:= mH = 1837.36;In[40]:= MU = mH/2;

and the classical force with respect to bond length:

In[41]:= FR[r_] :=

-CalcUSROCM[link, R2X[r]][[4, 2, 1]] /; NumberQ[r]

Note that the force function uses the CalcUSROCM, which returnsthe entire USROCM common block. The fourth element is the Carte-sian gradient for the triatomic system. Given the definition of R2X,we only need the x-component of the second atom, which for thecase of a homonuclear diatom is equivalent to the force in terms ofbond length. Another important point here relates to the additionalcondition for the bond length argument (i.e., /; NumberQ[r]).POTLIB2Math functions cannot be evaluated with symbolic in-put, and the extra condition prevents certain Mathematica func-tions, e.g., NDSolve, from attempting symbolic evaluations.

The following code uses Mathematica’s FindRoot commandto determine the bond length at which the repulsive part of thepotential equals the dissociation energy:

In[42]:= Rin = R /. FindRoot[VR[R] == De, {R, .1}]Out[42]= 0.776022

In the context of classical dynamics, this defines the shortest stablebond length for the diatomic system.

A set of classical phase space trajectories is generated by nu-merically solving Newton’s equation of motion, F(R(t)) = µ R(t),for different initial conditions of position R(0) and velocity R(0):

In[43]:= eq = FR[R[t]] == MU*R’’[t];In[44]:= tmx = 1000.;In[45]:= traj = {};In[46]:= Do[

ic = R[0.] == ri && R’[0.] == 0.;soln = NDSolveValue[eq && ic, R, {t, 0., tmx}];traj = Append[traj, {soln[t], MU*soln’[t]}];, {ri, .4, 1.4, .05}];

The first line of code defines the equation of motion and the sec-ond line introduces a parameter for themaximum integration time.Each iteration in the Do loop uses Mathematica’s NDSolveValuefunction to integrate the equations of motion from t = 0 to 1000a.u., starting with a different initial position and zero initial ve-locity. The solution is returned as an InterpolatingFunction

Page 7: POTLIB2Math: A Mathematica interface to the potential energy surface library for chemical systems

300 A.M. Tagliaboschi, J.B. Maddox / Computer Physics Communications 185 (2014) 294–301

Fig. 4. Classical phase space trajectories for H2 . The vertical dashed line separatesbound and unbound trajectories.

object corresponding to the desired trajectory, i.e., position (bondlength) versus time, and the position andmomentum functions fordifferent trajectories are collected in the list traj.

A phase space plot of momentum versus position for the dif-ferent trajectories is generatedusingMathematica’sParametric-Plot function:

In[47]:= ParametricPlot[traj, {t, 0., tmx},...];

The graphical output is shown in Fig. 4, where the vertical dashedline indicates the minimum initial bond length that separates un-bound and bound trajectories. Additional exercises might involvesetting up different ensembles of trajectories that explicitly samplea thermal phase space distribution function and computing varioustime-correlation functions.

4.4. Minimum energy paths

As a final application, we illustrate the calculation of a mini-mum energy reaction path for collinear H3 using the h3dmbe sub-program. It is productive to express the code in terms of a generictriatomic systemA+B−C; hence,we introduce a set of interatomicmass parameters:

mAB = mA + mB (3)mBC = mB + mC (4)mABC = mA + mB + mC. (5)

For a collinear molecule oriented along the x-axis, we have a pairof bond length coordinates:

RAB = xB − xA (6)RBC = xC − xB (7)

with the following inverse transformation:

xA = −1

mABC(mBCRAB + mCRBC) (8)

xB =1

mABC(mARAB − mCRBC) (9)

xC =1

mABC(mARAB + mABRBC) . (10)

The following code sets the mass parameters for H3:

In[48]:= MA = MB = MC = mH;In[49]:= MAB = MA + MB;In[50]:= MBC = MB + MC;In[51]:= MABC = MA + MB + MC;

and defines the corresponding transformation functions:

In[53]:= X2R[XA_, XB_, XC_] := {XB - XA, XC - XB};In[54]:= R2X[RAB_, RBC_] :=

{-(MBC*RAB + MC*RBC), (MA*RAB - MC*RBC),(MA*RAB + MAB*RBC)}/MABC;

Next, we define a potential energy function in terms of atomicpositions along the Cartesian x-axis:

In[52]:= VX[XA_, XB_, XC_] := CalcPENGYGS[link,{{XA, 0., 0.}, {XB, 0., 0.}, {XC, 0., 0.}}];

and generate a 2D contour diagram in terms of bond lengths usingMathematica’s ContourPlot function:

In[55]:= ContourPlot[VX @@ R2X[rab, rbc],{rab, .75, 8}, {rbc, .75, 8},...];

where the resulting output is included as part of Fig. 5.There are a variety of interesting methods for determining

transition states and minimum energy paths; however, we havechosen the most straightforward and perhaps least elegantapproach, i.e., a simple grid search. The following code performsa sequence of 1Dminimum energy searches along a set of diagonalslices through the bond length coordinate system:

In[56]:= data = {};In[57]:= Do[soln = FindMinimum[{VX @@ R2X[r, r + b], r > 0},

{r, 1.}];rmn = r /. soln[[2]];data = Append[data, {b, {rmn, rmn + b}}];If[b > 0,data = Append[data, {-b, {rmn + b, rmn}}];];

, {b, 0., 10., .1}];In[58]:= B2R = Interpolation@Sort@data;

Each linear slice has the form RBC = RAB + b, where the interceptb ≥ 0 is taken to be a parametric variable. The diagonal lines shownin Fig. 5 are representative of the coordinate slices used. Symme-try considerations reduce the search to only half the coordinatesystem, and the set of extrema determines the reaction path as aparametric function of the intercept. The last line of code aboveintroduces an interpolation function that converts from b to(RAB, RBC). For example, the transition state (due to the symmetryof H3) is located at

In[59]:= B2R[0.]Out[59]= {1.75462, 1.75462}

Arclength provides a more physical representation of thereaction path. In terms of the parameter b, the arclength s alongthe reaction path is expressed as

s(b) =

b

0

R′

AB(b′)2 + R′

BC(b′)2db′ (11)

where b′ is a dummy variable. The following code uses Mathe-matica’s NIntegrate and Interpolation functions to define atransformation between the intercept parameter and arclength:

In[60]:= B2S[b_] := NIntegrate[Norm[B2R’[bb]],{bb, 0., b}];

In[61]:= S2B = Interpolation@Table[{B2S[bb], bb},{bb, -10., 10., .1}];

Page 8: POTLIB2Math: A Mathematica interface to the potential energy surface library for chemical systems

A.M. Tagliaboschi, J.B. Maddox / Computer Physics Communications 185 (2014) 294–301 301

Fig. 5. Contour diagram for collinear H3 as a function of bond coordinates. Thediagonal (purple) lines are representative of 1D slices alongwhichminimumenergypoints were found. The blue curve is theminimum energy path connecting reactantand product regions. The inset shows the potential energy profile as a function ofarclength along the minimum energy path. The vertical dashed lines correspondto the black dots on the contour diagram. (For interpretation of the references tocolour in this figure legend, the reader is referred to the web version of this article.)

The first line of code defines the B2S function that calculates thearclength from the transition state to some finite value b. The nextline generates a table of (s, b) data points and immediately definesan interpolation function to convert from s to b. The reaction pathis then visualized using ParametricPlot:

In[62]:= ParametricPlot[B2R@S2B[s],{s, -8., 8.},...];

and is shown as the blue curve in Fig. 5. The following line of codedefines the potential energy curve along the reaction path as afunction of arclength:

In[62]:= VS[s_] := VX @@ R2X @@ B2R@S2B[s];

and the inset of Fig. 5 shows the profile of the reaction barrieralong the reaction path. Vertical dashed lines on the inset diagramcorrespond with the points on the contour plot.

It is rather easy to perform a full grid search for a low-dimensional system; however, such an approach is generally notcost effective for larger chemical problems. There are of coursemuch more efficient algorithms for locating transition states andsubsequently following a reaction path to the desired reactantsand products [19]. However, this is a difficult challenge for ageneral high-dimensional molecular problem and is an active areaof research. As a research tool,POTLIB2Mathmay provide a usefulplatform for quickly prototyping new algorithms and rapidlydeploying and analyzing them across different chemical systems.

5. Summary

The POTLIB2Math package provides a convenient interfacebetween the POTLIB repository of potential energy surfacesubroutines and Mathematica. This allows users to interactivelyexecute POTLIB subprograms from within Mathematica andutilize its built-in graphical and numerical analysis tools to createapplications for studies in chemical physics.

Acknowledgments

J.B. Maddox gratefully acknowledges support of the AppliedResearch and Technology Program and the Office of SponsoredPrograms at Western Kentucky University. Both authors givethanks to Prof. Ronald J. Duchovic for comments on thismanuscriptand providing updated POTLIB source code.

Appendix A. Supplementary material

Supplementary material related to this article can be foundonline at http://dx.doi.org/10.1016/j.cpc.2013.08.011.

References

[1] D.G. Truhlar, R. Steckler, M.S. Gordon, Chem. Rev. 87 (1987) 217–236.[2] B.J. Braams, J.M. Bowman, Int. Rev. Phys. Chem. 28 (2009) 577–606.[3] R.J. Duchovic, Y.L. Volobuev, G.C. Lynch, D.G. Truhlar, T.C. Allison, A.F. Wagner,

B.C. Garrett, J.C. Corchado, Comput. Phys. Comm. 144 (2002) 169–187;Comput.Phys. Comm. 156 (2004) 319–322.

[4] R.J. Duchovic, Y.L. Volobuev, G.C. Lynch, A.W. Jasper, D.G. Truhlar, T.C.Allison, A.F. Wagner, B.C. Garrett, J. Espinosa-García, J.C. Corchado, POTLIB,http://comp.chem.umn.edu/potlib.

[5] W.L. Hase, R.J. Duchovic, X.Hu, A. Komornicki, K.F. Lim,D.-H. Lu, G.H. Peslherbe,K.N. Swamy, S.R.V. Linde, A. Varandas, H. Wang, R.J. Wolf, Quantum Chem.Program Exchange 16 (1996) 671.

[6] U. Lourderaj, K. Park, W.L. Hase, Int. Rev. Phys. Chem. 27 (2008) 361–403.[7] B.C. Garrett, G.C. Lynch, T.C. Allison, D.G. Truhlar, Comput. Phys. Comm. 109

(1998) 47–54.[8] J.C. Corchado, Y.-Y. Chuang, P.L. Fast, J. Villa, W.-P. Hu, Y.-P. Liu, G.C. Lynch,

K.A. Nguyen, C.F. Jackels, V.S. Melissas, B.J. Lynch, I. Rossi, E.L. Coitio, A.Fernadez-Ramos, J. Pu, R. Steckler, B.C. Garrett, A.D. Isaacson, D.G. Truhlar,POLYRATE Version 8.6, University of Minnesota, Minneapolis, Minnesota.http://comp.chem.umn.edu/polyrate/.

[9] D.G. Truhlar, B.C. Garrett, Annu. Rev. Phys. Chem. 35 (1984) 159–189.[10] Wolfram Research, Inc., Mathematica, Version 9.0, champaign, IL.[11] D. Clary, Chem. Phys. 71 (1982) 117–125.[12] I. Last, M. Baer, in: D.G. Truhlar (Ed.), Potential Energy Surfaces and Dynamics

Calculations, Plenum Press, New York, 1981, p. 519.[13] R.E. Weston, J. Chem. Phys. 31 (1959) 892–898.[14] P.J. Kuntz, E.M. Nemeth, J.C. Polanyi, S.D. Rosner, C.E. Young, J. Chem. Phys. 44

(1966) 1168–1184.[15] V.K. Babamov, V. Lopez, R.A. Marcus, J. Chem. Phys. 78 (1983) 5621–5628; J.

Chem. Phys. 81 (1984) 4182.[16] D.S. Perry, J. Polanyi, C.W. Wilson, Chem. Phys. 3 (1974) 317–331.[17] S. Sato, J. Chem. Phys. 23 (1955) 592–593.[18] A.J.C. Varandas, F.B. Brown, C.A. Mead, D.G. Truhlar, N.C. Blais, J. Chem. Phys.

86 (1987) 6258–6269.[19] H.B. Hratchian, H.P. Schlegel, in: C.E. Dykstra, K.S. Kim, G. Frenking,

G.E. Scuseria (Eds.), Theory and Applications of Computational Chemistry: TheFirst 40 Years, Elsevier, 2005, pp. 195–259.