THE JOURNAL OF CHEMICAL PHYSICS 149, 084106 (2018)

Toward quantum-chemical method development for arbitrary basis functions Michael F. Herbst,1,a) Andreas Dreuw,1,b) and James Emil Avery2,c) 1Interdisciplinary Center for Scientific Computing, Heidelberg University, Im Neuenheimer Feld 205, 69120 Heidelberg, Germany 2Niels Bohr Institute, University of Copenhagen, Blegdamsvej 17, 2100 København, Denmark (Received 15 June 2018; accepted 2 August 2018; published online 27 August 2018)

Wepresent the design of a flexible quantum-chemical method development framework, which supports employing any type of basis function. This design has been implemented in the light-weight program package molsturm, yielding a basis-function-independent self-consistent field scheme. Versatile interfaces, making use of open standards like python, mediate the integration of molsturm with existing third-party packages. In this way, both rapid extension of the present set of meth- ods for electronic structure calculations as well as adding new basis function types can be readily achieved. This makes molsturm well-suitable for testing novel approaches for discretising the electronic wave function and allows comparing them to existing methods using the same software stack. This is illustrated by two examples, an implementation of coupled-cluster doubles as well as a gradient-free geometry optimisation, where in both cases, arbitrary basis functions could be used. molsturm is open-sourced and can be obtained from http://molsturm.org. Published by AIP Publishing. https://doi.org/10.1063/1.5044765

I. INTRODUCTION computation per integral for having fewer more accurate basis functions. The central goal of electronic-structure theory is to find In many practical applications, the shortcomings of GTOs approximate solutions to the electronic wave equation numer- are not important, or one is able to compensate by employing ically. This requires a discretisation of the electronic wave specialised contracted basis sets.4,5 However, even contracted function. Typically, it is approximated as a linear combi- GTOs (cGTO) fail to describe both the nuclear cusp and the nation of Slater determinants: anti-symmetrised products of exponential decay of the electron density.6 In addition, no mat- single-particle functions. The latter are in turn constructed by ter the number of GTO basis functions used, the derivatives are expanding them in a of a priori determined single- always wrong at the nucleus, which causes singularities and electron functions. Usually, such basis sets are not complete computational failure, for example, in quantum Monte Carlo and introduce basis set errors. Proper choice of the basis func- calculations.7–9 Furthermore the description of some proper- tion type and size of basis set is thus decisive for an accurate ties such as the nuclear-magnetic resonance (NMR) shield- description of the system under investigation. It is also clear ing tensors or a description of Rydberg-like or auto-ionising from the onset that different basis function types can be more states10–13 directly involves the nuclear cusp or the asymptotic or less suited for a specific problem, suggesting us to conduct tail, making physically accurate basis functions desirable.14,15 investigations across existing basis function types. The name of our implementation, “molsturm,” is a port- -based methods are overwhelmingly predomi- manteau of molecular Sturmians: the project was born as a nant in computational electronic structure theory, which stems means to solve the problem of using state-of-the-art quantum from pragmatic reasons dating back to the founding years.1,2 chemistry methods together with generalised- and molecular It was well-known that bound state electronic wave func- Sturmian basis functions. The many promising results for gen- tions decay exponentially both at short and large distances eralised Sturmians were stranded due to the fact that only from the nuclei,3 but multi-centre electron-repulsion integrals electronic structure problems that were small enough to be (ERI) of products of exponential-type orbitals (ETO) were solved by direct configuration interaction methods could be impractically difficult to calculate. For Gaussian-type orbitals treated, preventing wider use. The existing mature quantum (GTO), on the other hand, ERI could be calculated efficiently chemistry software has been developed over hundreds of man- due to the Gaussian product theorem. However, the compu- years, and the methods are not easily reimplemented from tational challenges facing quantum chemists have changed scratch. since the 1970’s, and it may now be worth trading extra In theory, it should be a simple matter to include new basis function types in existing software by swapping the integral calculator. In practice, it turned out to be exceedingly difficult due to the very large and com- a)Electronic mail: [email protected] b)Electronic mail: [email protected] plicated code bases of all the investigated quantum chem- c)Electronic mail: [email protected] istry software. Assumptions about the basis function type

0021-9606/2018/149(8)/084106/14/$30.00 149, 084106-1 Published by AIP Publishing. 084106-2 Herbst, Dreuw, and Avery J. Chem. Phys. 149, 084106 (2018) scattered around the source code only make this even task more back end in molsturm, which will then both provide simple difficult. stand-alone calculations and a common interface to hook into Our solution, which is presented in this paper, is to imple- existing quantum chemistry packages. ment a light-weight layer that makes it easy to experiment with many different basis function types and quantum-chemical B. Toward basis-type agnostic quantum chemistry methods. It is designed for researchers to both build simple stand-alone programs for prototyping and teaching purposes, In order to reach a basis-type agnostic design, there and make plug-in modules to be hosted in standard quan- are three fundamental components to consider: (i) an inte- tum chemistry software. To the best of our knowledge, such a gral interface accommodating a wide range of very dif- framework with the ability to explore quantum-chemical meth- ferent basis set types and discretisation, but providing a ods across multiple basis function types has been missing up uniform way of accessing them, (ii) simple discretisation- to today. agnostic implementations of the self-consistent field (SCF) algorithms, and (iii) a flexible interface to employ the result- A. Alternative basis function types ing SCF orbital basis further in existing third-party code. Once the SCF orbitals have been obtained, the remain- Many research groups have worked on alternative basis der of a calculation, e.g., a Post-Hartree-Fock (Post-HF) function types. This section will provide a brief overview with method, can usually be formulated entirely in the SCF orbital particular focus on exponential-type orbitals (ETO). For fur- basis, without reference to the underlying basis functions. ther details regarding the basis function mentioned, the reader Thus, a basis-function independent SCF scheme automati- is referred to the cited works. cally leads to basis-function independent Post-HF methods as Efforts on making various types of ETOs computation- well. 16–19 ally feasible were pioneered by Harris et al. A particular This structure has another advantageous side effect in the 20–24 form of complete ETO basis is Coulomb Sturmians (CS). context of developing new basis function types, as it allows us Their functional form is identical to the familiar hydrogen-like to perform comparisons between old and new methods using orbitals, just with all occurrences of the factors Z/r replaced exactly the same software stack. In other words, one can thus by the Sturmian exponent k—a parameter, which is the same be sure that, apart from the discretisation, all aspects of the cal- for all functions of the basis, culation, e.g., SCF algorithms or guess methods, are optimised CS  3/2 l −kr 2l+1 m  at the same level leading to a fair apples-to-apples comparison ϕ r = k Nnl(2kr) e L (2kr)Y rˆ . (1) nlm n−l−1 l between old and new methods. m 2l+1 In this, Yl is a spherical harmonic, Ln−l−1 an associated Laguerre polynomial, and C. Paper outline s 2 (l + n)! The remainder of the paper is structured as follows: Sec.II N = (2) nl (2l + 1)! n(n − l − 1)! reviews existing projects with similar goals to molsturm. Section III provides a theoretical background for the program a normalisation constant. CS functions proved to be especially design choices, which are described in Sec.IV. SectionV easy to work with since their momentum-space representation provides example problems calculated using molsturm’s by hyperspherical harmonics allows efficient calculation of python interface, illustrating how to implement new methods multi-centre integrals, opening the way for efficient molecular on top of molsturm in a few lines of python. SectionVI calculations.25–28 The Coulomb Sturmian construction gen- outlines the current state of molsturm and what we hope to eralises well and generalised Sturmian basis sets preserving achieve in the future. many useful Sturmian properties can be constructed. These allow us, for example, to build N-particle basis functions that include important geometric properties of the physical II. RELATED QUANTUM-CHEMICAL SOFTWARE PACKAGES system under consideration at the level of the basis.29–37 Sim- ilarly, d-dimensional hyperspherical harmonic basis sets can This section reviews existing quantum chemistry software model collective motions of particles, for example, for treat- that shares some of the goals of molsturm. ing strongly interacting few-body systems or reactive scatter- The quantum Monte Carlo packages CASINO61 and ing.38–42 A particular type of one-particle Sturmians combines QMCPACK62 are among the few systems that support many a bound-state region and plane-wave asymptotics to model different basis function types. Both programs support dis- photoionisation in scattering.43–46 Other directions of research cretizations in terms of GTOs, Slater-type orbitals (STOs), toward alternative discretisation methods include quantum plane-waves, and numerical orbitals like splines. Similarly, the chemistry on numerical real-space grids,47,48 finite element packages CP2K,63 ASE,64 and GPAW65,66 can be employed methods,49–54 and wavelets.55–60 to perform and post-process computations using more than The molsturm package is to support such research one type of basis function. GPAW and CP2K further sup- directions by providing a common platform for development, port calculations with hybrid basis sets that mix Gaussian- testing, and analysis of quantum-chemical methods irrespec- type orbitals with plane waves. However, to the best of our tive of the basis function type employed for the discretisation. knowledge, the design of these packages is very specific to The goal is for the implementation work of introducing a new the particular combinations of the basis function type and basis function type to be reduced to adding an extra integral method. 084106-3 Herbst, Dreuw, and Avery J. Chem. Phys. 149, 084106 (2018)

Combining a FORTRAN or C/C++ implementation of the of both these projects, such that extending them by other types time-critical core with python as a high-level interface lan- of basis functions could still be difficult. guage works exceedingly well, and this solution has become 67 increasingly popular. Sun et al. describe the reasons as III. THEORY follows in their paper about : This section briefly discusses the theoretical background • There is no need to learn a particular domain-specific and properties of self-consistent field problems in the context input format. of the basis-type independent design aspired for molsturm. • All language elements from python are immediately A more detailed analysis is provided in Ref. 75. available to, e.g., automatise repetitive calculations with loops. A. Self-consistent field schemes • The code is easily extensible beyond what is available Both Hartree-Fock (HF) as well as Kohn-Sham density- inside pyscf, for example, to facilitate plotting or functional theory (DFT) can be viewed as a minimisation other kinds of analysis. procedure of an energy functional with respect to the occu- • Computations can be done interactively, which is pied HF or DFT orbitals.76–78 After employing a particular helpful for testing or debugging. basis set for discretisation, this minimisation problem becomes We add here that python as a high-productivity language parameterized in the orbital coefficients C and the associated often achieves even complicated tasks with few lines of code Euler-Lagrange equations may be written as while remaining easy to read and understand, demonstrated, F(C)C = SCE, for example, by the implementation shown (3) C†SC = I, in Sec.V. In the context of quantum chemistry, this has the pleasant side effect that a python script used for perform- where C is the matrix of occupied orbital coefficients, S is the ing calculations and subsequent analysis is typically brief, but overlap matrix, I is the identity matrix, and E is the diagonal still documents the exact procedure followed. All this comes at matrix of orbital energies. The Kohn-Sham or Fock matrix essentially no downside if python is combined with a care- F(C) itself depends on the solution coefficients C, making (3) fully optimised low-level C or FORTRAN code in the numerical a non-linear eigenproblem. In the following, our focus will hot spots. Sun et al.,67 for example, claim that pyscf is as be on the HF problem since molsturm currently does not fast as any other existing quantum chemistry packages written implement any DFT exchange-correlation functional. Due to solely in C or FORTRAN. the structural similarity of both HF and DFT, our approach Even meta-projects like ASE64 or cclib68 which aim nevertheless applies to DFT as well. at extending existing packages by a common python front Because (3) is non-linear, the HF problem must be solved (0) end have emerged. Other packages like HORTON,69 pyscf,67 iteratively. Starting from an initial guess C , the SCF proce- (1) (2) pyQuante,70 and GPAW65,66 are written almost exclusively dure aims to construct a sequence of trial matrices C , C , (n) in python and only employ low-level C or C++ code for the ..., C converging toward the minimiser of the HF energy computationally demanding routines to various extents. functional. Broadly speaking this can be achieved in two ways, 79–82 Starting from the opposite direction, Psi471 has gradu- either by directly minimising the HF energy functional or 83–86 ally introduced a more and more powerful python interface alternatively by satisfying (3), thus obtaining a stationary on top of their existing C++ core over the years. Recently their point on the SCF manifold. On top of that one may alternatively efforts have led to the Psi4NumPy project,72 which combines formulate the HF problem, such that instead of the coefficient the python interface of Psi4 with the tensor operation syn- matrix, the density matrix tax of numpy arrays.73 The aims of Psi4NumPy are very  † D(n) = C(n) C(n) (4) much in line with molsturm, namely, to provide a frame- work, which yields flexible and easy-to-read codes. It is thus is iterated. To distinguish SCF algorithms according to these highly suitable for reference implementations, rapid prototyp- parameterizations, we will refer to the latter kind of SCF ing, or teaching.72 Unlike molsturm, however, Psi4NumPy algorithms as density-matrix-based SCF schemes, whereas we does not exhibit a basis-type agnostic design and only supports will use the term coefficient-based SCF for the former set of discretisations based on cGTO basis sets. algorithms.75 Another common feature of pyscf and Psi4 is their To illustrate, Fig.1 shows simplified schemes for three modular design. They use well-established open standards like SCF algorithms: Roothaan’s repeated diagonalisation,83 the HDF574 or numpy arrays73 for data exchange, such that link- optimal damping algorithm (ODA),77 and the geometric direct ing their codes to external projects becomes easy. Psi4, for minimisation (GDM) scheme.82 While Roothaan’s algorithm example, managed to integrate more than 15 external packages and the GDM are coefficient-based, the ODA is density- into their framework. This includes three completely differ- matrix-based. Roothaan’s algorithm is the simplest representa- tive for solving (3) by repetitively treating the standard eigen- ent back ends for the computation of the required integrals.   In the case of pyscf, it only took us about a day to link problem that arises from fixing F C(n) . In contrast to this, the our molsturm to the full configuration interaction (FCI) GDM directly minimises the energy functional geometrically. algorithms of pyscf via an interface based on numpy. Nev- The ODA is a middle ground: It combines a line-search min- ertheless the numerical requirements of Gaussian-type orbitals imisation of the energy with respect to the density matrix with are currently hard-coded inside the optimised C or C++ parts repeated diagonalisation of arising Fock matrices. 084106-4 Herbst, Dreuw, and Avery J. Chem. Phys. 149, 084106 (2018)

FIG. 1. Schematic overview of a few exemplary self-consistent field algorithms. In each case, the Fock-update step is highlighted in pale red and the steps updating the coefficients or the density matrix are shaded in pale blue. For further details regarding the algorithms, see the indicated references. From left to right: (a) Roothaan repeated diagonalisation.83 (b) Optimal damping algorithm.77 (c) Geometric direct minimisation.82

The aforementioned algorithms can—on an abstract in our discussion towards a basis-type-independent SCF level—be written as a two-step process, where a Fock-update scheme. step and a coefficient-update or density-matrix-update step are iterated. In the former step, a new Fock matrix F(n) is B. Matrix structure and contraction-based methods constructed from the current set of SCF coefficients C(n) or the current density matrix D(n) (red boxes in Fig.1). In the Because different basis types can have very different second step, a new set of coefficients C(n+1) or a new den- selection rules and other discretisation properties, the struc- sity matrix D(n+1) is found by means of the Fock matrix F(n) ture of the Fock matrix—as well as the numerical approaches (blue boxes in Fig.1). Typically other results obtained in pre- required to efficiently solve the SCF problem—may vary. This vious iterations are taken into account in this step as well to in turn affects the requirements we need for the interface to the accelerate convergence. Consider, for example, Pulay’s com- update steps, which is a challenge for hiding the basis func- mutator direct inversion of the iterative subspace (DIIS)86 tion details from the SCF. This subsection briefly discusses scheme forming a linear combination of previous Fock contraction-based methods as a solution to this issue. matrices. Figure2 shows from left to right the Fock matrices arising Note, that apart from the initial discretisation of the HF if (a) finite elements, piece-wise polynomials on a real-space or DFT problem, no reference to the basis function type grid,88,89 (b) contracted Gaussians, or (c) Coulomb Sturmians was required in our discussion about SCF procedures. In have been employed as the basis. While the Coulomb Sturmian other words, provided that (i) an SCF algorithm can be and Gaussian matrices are both small, dense, and diagonal brought into two-step form and that (ii) within these steps dominant, the finite-element-discretised matrix is sparse, but the details of the basis function can be hidden, the algo- also much larger. In fact, for a description of the beryllium rithm can be implemented without making explicit refer- atom density at a relevant accuracy even larger basis sets with ence to the underlying basis. We are unaware of an SCF 105–106 finite elements are needed.53 algorithm which cannot be written in two-step form and As a result, for both cGTO as well as CS-based dis- will henceforth concentrate primarily on the second point cretisations, direct diagonalisation algorithms, i.e., where the

FIG. 2. Structure of the Fock matrix at the beginning of a Hartree-Fock SCF calculation of beryllium, discretised using finite elements, contracted Gaussians, and Coulomb Sturmians. The elements are colored by the log10-scale shown on the right. The (3, 2, 2) CS basis set of calculation (c) contains all CS functions (1) whose quantum numbers n, l, m satisfy n ≤ 3, l ≤ 2, and m ≤ 2 and with the exponent parameter chosen as k = 2.0. More details about construction schemes 87 for CS basis sets can be found in Ref. 75. From left to right: (a) Q2 finite elements, adaptively refined 3D grid. (b) Contracted Gaussians, pc-2 basis set. (c) Coulomb Sturmians, (3,2,2) basis with k = 2.0. 084106-5 Herbst, Dreuw, and Avery J. Chem. Phys. 149, 084106 (2018) full Fock matrix is diagonalised completely, are applicable. range of iterative subspace-based algorithms such as the gener- For finite-element-based approaches, on the other hand, iter- alised minimal residual method (GMRES), conjugate-gradient ative subspace-based algorithms like Arnoldi’s method90 or (CG), Arnoldi’s method, or Davidson’s method.90,91,99–101 For Davidson’s method91 are more common, due to the size of the a density-matrix-based SCF scheme, a contraction-based for- matrix. Recently these have been combined with the so-called mulation is possible as well. Since the density matrix and matrix-free methods,92 which avoid building the finite-element the Fock matrix have similar memory requirements and the problem matrix in memory at all. Instead only an expression density matrix inevitably needs to be stored in a density- for the computation of the matrix-vector product is passed to an matrix-based SCF, the main prospect of contraction-based iterative solver. Since such expressions may in general involve methods, to avoid the memory bottleneck of storing the Fock arbitrary tensor contractions, like a contraction over the ERI matrix, is directly subverted. Our discussion will not consider tensor to compute the Coulomb or the exchange part of the density-matrix-based SCF schemes further for this reason. Fock matrix, we will refer to these approaches by the term In principle, the Fock update step may be implemented by contraction-based methods.75 a conventional re-computation of the full Fock matrix like in a The main driving force for such approaches is usu- cGTO setting. Similarly, the matrix-vector-product expression ally to reduce the amount of storage required and instead may be realised by multiplying the resulting stored matrix with employ well-optimised high-throughput matrix-vector con- an appropriate vector. Thus the contraction-based SCF scheme traction expressions. For cases where this avoids slow is a generalisation of the traditional method that provides storage such as hard drives, runtime may be reduced additional flexibility to deal with Fock matrices of various significantly even though matrix data will effectively be structures. To conclude, a single contraction-based interface computed over and over. Examples for contraction-based between the SCF algorithm and Fock matrix is sufficient to pro- methods in electronic structure theory are efficient implemen- vide a contraction-based SCF irrespective of the basis function tations of Post-HF methods, like the algebraic diagrammatic type and resulting matrix structures. construction (ADC) scheme93–95 as well as modern coupled- One should notice, however, that iterative eigensolvers cluster algorithms.96 One should mention that in this con- are not appropriate for all systems. For some cGTO dis- text, the contraction expressions are usually called working cretisations with small and dense Fock matrices stored in equations. memory, direct solver methods perform better than iterative Note, however, that contraction-based methods may even ones and are thus preferable. Optimal performance requires an be favourable for cases where the size of the system matrix abstraction layer that—depending on the basis function type allows us to get around using the hard drive and place it in main and matrix structure—transparently switches (i) between con- memory instead.75 This can be understood by considering traction expressions and dense matrices for representing the modern hardware trends. State-of-the-art central processing Fock matrix and (ii) between iterative or direct solver algo- units can perform on the order of 1000 floating point opera- rithms. As will be discussed in Sec.IVB, the lazyten lazy tions during the time needed to load data from main memory,97 matrix library is used for this purpose to achieve a basis-type- a number which is likely going to increase in the future.98 independent SCF code. The details of the solver algorithm This implies that more and more algorithms may become switching and the basis-dependent routines for computation bound by memory latency and bandwidth rather than com- are hidden in the abstraction layer of the linear algebra and the putation. Especially for cases where matrix elements are fast contraction expression. to compute from smaller stored intermediates or even from tractable analytic expressions, contraction-based methods are IV. PROGRAM DESIGN highly suitable. Additionally a contraction-based approach A. Design goals often allows us to reorder terms in the matrix-vector product or make use of discretisation-specific properties providing addi- As mentioned above, molsturm aims to remove the tional sources of reducing runtime cost. Such advantageous difficulty in implementing new types of basis functions and side-effects apply not only to finite-element-based HF, but to discretisations and to simplify experimenting with new com- Coulomb-Sturmian-based Hartree-Fock27,75,92 as well, mak- putational methods in quantum chemistry. Assessment of new ing contraction-based methods worth considering in a context methods and comparison between old and new should be pos- where multiple basis functions ought to be employed. sible within the same framework to ensure treatment on an Additionally, a contraction-based approach can be read- equal footing. A high-level interface aiding automation of ily combined with the two-step SCF described in Subsec- repetitive calculations is desirable, too. Once the trial phase tion III A. Focusing on a coefficient-based SCF for a second, is completed, it should be easy to incorporate the new meth- a contraction-based ansatz would implement the Fock matrix ods into existing quantum chemistry software and thus make F(C) as a matrix expression with the current coefficients C them widely available. This motivates the overall design goals as some mutable state.75 The Fock-update step then amounts of molsturm. to transparently replacing the current C in the Fock matrix 1. Enable rapid development expression, which is a trivial process. Furthermore, both ways to think about the HF problem, namely, to think of it as a In the early stages of developing a new quantum-chemical non-linear eigenproblem as well as an optimisation problem, method, it is often not clear how it will perform in practice can be tackled by iteratively solving appropriate linear prob- or which approaches are required to yield efficient and sta- lems or eigenproblems. This can be achieved using a wide ble algorithms. To simplify implementation, the code should 084106-6 Herbst, Dreuw, and Avery J. Chem. Phys. 149, 084106 (2018) be high level and close to the physical formulae, and at required in the future. This is further aided by molsturm’s the same time be flexible enough to enable experimentation test suite, which employs a range of testing strategies with different numerical methods. Sec.IVD discusses further including unit tests, functionality tests, and property-based details. tests. 2. Plug-and-play implementation of new Most molsturm modules are written in C++, but the discretisations top layer of the program is a python module defining the user interface of the framework. Below this, gint, the gen- It is a significant barrier, to incorporate new basis func- eral integral library, provides a single link to the multiplex tion types and discretisation schemes to quantum chemistry, between the supported integral calculation back ends and that assumptions about basis function types are scattered gscf implements the contraction-based SCF schemes, fol- around in the—often very large—programs. We have designed lowing the general two-step update structure mentioned in molsturm to isolate this to the actual electronic integral back Sec. III A. Both modules use the library lazyten, which ends, and otherwise only where absolutely necessary. The SCF defines a generalised linear algebra interface allowing to trans- stage and post-HF methods should only know about integrals parently use dense, sparse, and contraction-based Fock matri- on an abstract level. Since symmetry, sparsity, selection rules, ces in gint and gscf; see Sec.IVB. Finally krims is and recursion rules are basis function dependent, the integral molsturm’s common utility library, named after the Ger- library should be in charge of performing the operations where man word “Krimskrams” for “odds and ends.” The individual this information is used. This is primarily in the tensor con- components are discussed further in Secs.IVB–IV D. tractions, for example, the ERI-contractions with molecular coefficients. Sec.IVC discusses how this is done, expanding B. Library for contraction-based algorithms on the strategies introduced in Sec. III. We saw in Sec. III B that contraction-based methods pro- 3. Easy interfacing with existing code vide a versatile ansatz for self-consistent field algorithms, A challenge for new quantum-chemical methods is that leading to a basis-function independent formulation of the they are hard to compare to well-established ones: One is problem. We noted that when the Fock matrix is small and either restricted to toy problems, or faced with the enormous should be stored in memory, an abstraction layer to switch task of implementing advanced methods, refined over hun- between dense and iterative solver schemes is needed for max- dreds of man-years in the state-of-the-art quantum chemistry imal efficiency. On top of that an issue with contraction-based packages—clearly a rather daunting task. For this reason, it is methods is that the expressions for computing the matrix- explicitly not our goal to create yet another general purpose vector products can become complicated, such that these are quantum chemistry package and the large ecosystem of func- less intuitive to handle compared to a plain matrix or tensor tionality needed in such a project, but on the contrary to supply operations. small flexible modules that can both be used on their own for Inside molsturm, the library lazyten solves these experimentation and teaching, and can be easily incorporated challenges by representing matrices by a data structure called 75 into existing quantum chemistry software by simple interfaces. a lazy matrix. These employ lazy evaluation, a rigor- For details, see Sec.IVD as well as the examples in Sec.V. ous method from programming language theory that allows postponing computation until the moment it is needed.102 4. Modular structure with low code complexity In contrast to a stored matrix, which we define as a dense The aspired flexibility requires that individual modules table, which has all its elements residing in a continuous chunk are as independent from each other as possible. We therefore of memory, this restriction does no longer hold for a lazy choose a design in molsturm, where the five main modules matrix. It may, for example, follow a particular sparse stor- are arranged in layers; see Fig.3. Dependencies between the age scheme like a compressed-row format,103 but it may not modules are only downwards, never sideways or upwards. This even be associated with any kind of storage at all. In the most aids both reuse of molsturm’s modules in external projects general sense, it can be thought of as an arbitrary contrac- as well as restructuring or replacement of the code if this was tion expression for computing the matrix elements, which is

FIG. 3. Structure of the molsturm framework: Shown are the five mod- ules of the package, along with third- party integral back ends and post-HF methods to indicate the mediator role of molsturm. The grayed-out parts are not yet implemented, but could be supported by the design. 084106-7 Herbst, Dreuw, and Avery J. Chem. Phys. 149, 084106 (2018) dressed to look like an ordinary matrix from the outside. One of the available third-party linear algebra back ends for solv- may still obtain individual matrix elements and add, subtract, ing the problem. As a result, algorithms programmed using or multiply lazy matrix objects, but not all operations are as lazyten may be called with both lazy and stored matri- efficient as for stored matrices. Most importantly, accessing ces, and the solvers will be automatically chosen to match the individual elements of lazy matrices can be costly since the change in the matrix structure. The user, however, remains in elements may be computed, e.g., from a particular tensor con- full control: By providing appropriate parameters, all choices traction. However, contraction operations of such objects must made automatically by lazyten can be overwritten, as can be fast. the parameters passed to the underlying solvers. Lazy matrix operations are subject to lazy evaluation, Overall, lazyten provides intuitive high-level syntax explaining the name of these data structures. Lazy evaluation for contraction-based methods in the form of lazy matrices. is a prominent concept of functional programming languages, The library allows the algorithm code to be written only once, excellently introduced in Ref. 104. In our context, this means but to stay flexible. For example, one may adapt to modern that operations between lazy matrices are not directly per- hardware trends or to the deviating numerical requirements formed, but delayed until a contraction of the resulting expres- imposed by a different basis function type simply by changing sion with a vector or a stored matrix unavoidably requires the implementation of the lazy matrices passed to the algorithm evaluation. To illustrate this, consider the instructions code. A more in-depth discussion of lazyten can be found in Ref. 75. D = A + B, E = DC, (5) C. Self-consistent field methods and integral interface y = Ex, The lazy matrices of lazyten are constructed to be used as a high-level language for implementing basis-type- where A, B, and C are lazy matrices and x is a vector stored in independent contraction-based SCF algorithms.75 For exam- memory. The first two lines do not give rise to any computation. ple, the linear algebra interfaces of lazyten can be employed They only build an expression tree in the returned lazy matrix in the coefficient-update step making implicit use of the auto- E, as illustrated in Fig.4. The final instruction is a matrix- matic switching between dense and iterative diagonalisation vector product with the stored vector x, and the actual result methods. The Fock update may be implemented building on should be returned in the vector y. This triggers the complete top of a similar function from lazyten, namely, by altering expression tree to be worked upon in appropriate order, such the coefficient matrix the Fock expression currently refers to. that the expression All the SCF algorithms in gscf are implemented in y = (A + B)Cx (6) this way: as solvers for a non-linear eigenproblem defined by an input lazy matrix, which represents the SCF problem is evaluated at once at this very instance. At this point, the full under study. Since the algorithms only see the final contraction expression could be simplified, and the most efficient evalua- expression and its update function, gscf is self-contained and tion order could be chosen. This is, however, not implemented may be applied to any non-linear eigenproblem with a struc- yet. ture similar to the HF minimisation problem. This is desirable Due to lazy evaluation, we can thus build complicated because quite a few electronic structure theory methods can expressions from familiar matrix operations. This allows us to be thought of as modifications of the HF problem. Examples view the lazy matrix framework as a domain-specific language include the Kohn-Sham matrix arising in the usual density- for contraction-based algorithms, which makes working with functional theory (DFT) treatments or additional terms in the contraction expressions feel like working with actual matrices. problem matrix, arising from modeling an external field, or Note, however, that the lazy matrices generalise real matrices correction terms due to embedding. as they also allow non-linear transformations of a vector to be The lazy Fock matrix object describing the problem to be represented. solved is prepared by the upper molsturm layer based on the Inside lazyten, various kinds of lazy matrices, as well electronic structure method chosen by the user. For example, 75 as lazy and stored objects, can be combined transparently. HF would be the sum of four lazy matrices, which represent the Similarly, lazyten provides high-level interfaces for solv- kinetic, nuclear attraction, Coulomb, and exchange matrix.96 75 ing linear or eigenproblems where the involved matrices may Similarly one would add an exchange-correlation term for be stored or lazy. The call passes through a branching layer, DFT or other terms such as an embedding operator. The latter which inspects the matrix structure and accordingly selects one methods are not yet available in molsturm, however. The individual terms of the Fock matrix are obtained from gint, which acts as a broker, presenting a common interface for all basis function types and third-party integral back end libraries to the rest of the molsturm ecosystem. On calcula- tion start, molsturm will take the discretisation parameters supplied by the user and hand them over to gint, which— based on these parameters—sets up the selected integral back end library and returns a collection of lazy matrix integral FIG. 4. Examples for lazy matrix expression trees. The upper panel represents the instruction D = A + B and the lower one the multiplication of the result D objects. For each basis type and back end, the interface of the with C. returned objects will thus look alike since they are all lazy 084106-8 Herbst, Dreuw, and Avery J. Chem. Phys. 149, 084106 (2018) matrices. On call to their respective contraction expressions, change from time to time, breaking parser scripts or—even however, the required computations will be invoked in the worse—producing wrong results without any notice. This is previously selected integral back end. gint itself does not a common problem in the current practice of computational implement any routine for computing integral values at all, it chemistry. just transparently redirects the requests. Notice that the pre- In contrast to this, the SCF results in molsturm are cise kind of parameters needed by gint to setup the back returned to the host python environment through an inter- end may well vary from discretisation to discretisation. For face built on numpy arrays. These have become the de facto example, a Coulomb Sturmian basis requires the Sturmian standard for storing and manipulating matrices or tensors in exponent k and the selection of (n, l, m)-triples of the basis python. All python packages that are commonly used for functions,75 whereas a contracted Gaussian basis requires plotting or data analysis, such as matplotlib,106 scipy,73,107 or the list of angular momentum, exponents, and contraction pandas,108 use numpy arrays in their interfaces. Consequently, coefficients.2,4,5 a complete computational procedure may be orchestrated from At the moment cGTO and CS integrals are the only ones a single python script, which contains all parameters influ- supported in gint. For each of these, at least two different encing the setup, calculation, analysis, and all decisions taken implementations are available, however. Adding more back for presenting the data in plots or tables. Such a script serves end libraries or basis function types is rather easy since one as automatic documentation for the full procedure and allows only needs to implement a collection of lazy matrices, where others to reproduce the presented plots or tables without effort: the contraction expressions initiates the appropriate integral All it takes is to re-run the script. computations in the back end. This collection then needs to be All parameters for gint, the SCF algorithms of gscf, registered as a valid basis type to gint to make it available and the linear solvers from lazyten are made avail- to the upper layers. For example, preliminary support for the able through the python interface. By changing these, the contracted Gaussian library libcint105 was added with just user may directly influence, e.g., the algorithms chosen by two days of work. Notice, that gint is designed to allow all lazyten for diagonalisation, or how gscf switches between of this to be achieved without changing a single line of code SCF solvers. This is particularly handy during method devel- inside gint itself since the call to the registration function opment, where one may run molsturm from an interac- can happen dynamically at runtime. So one can implement a tive IPython109 shell and use these parameters to control the new integral back end in a separate shared library and add it progress of a calculation. In that way, one can check assertions in a plug-in fashion without recompiling molsturm. about intermediate results or visualise such graphically with To summarise, by means of the lazy matrices of matplotlib.106 This greatly reduces the feedback loop for small lazyten, the responsibility for the HF problem has been split calculations, e.g., during debugging. between three different well-abstracted modules: gint, which Interactive analysis of larger calculations is facilitated by provides the interface to the integrals and selects the discreti- archiving functionality in molsturm. The SCF results may sation, molsturm, which builds the lazy matrix expression of be stored either in YAML110 or HDF574 format. In this way, the problem to be solved, and gscf which uses this expres- large calculations can be performed in advance over night or on sion to solve the SCF problem in a basis-type-independent a high-performance computing (HPC) system, then archived manner. and transferred to the workstation. Here, the archive may be loaded in an interactive shell, restoring the full state of the D. Python interface module calculation as if it had been performed locally. Next to the The topmost layer of molsturm is the “molsturm” SCF results, molsturm’s archived state contains the precise python module, providing the user interface of the package. set of input parameters which were used to obtain the stored This layer assists with setting up a calculation, drives the SCF results. These are not the parameters provided by the user to procedure in gscf, and returns the converged results to the start the calculation, but the post-processed parameters which user. We chose the scripting language python to implement were actually used by the lower layers, including, e.g., default the majority of this interface layer and especially the interface values. This helps make the archive self-documenting, and itself. simplifies setting up a refined calculation building on top of Our reasoning is related to the arguments of the pyscf the already obtained results. authors67 discussed in Sec.II, namely, we wanted to avoid Our numpy-based interface has already proven to be help- inventing yet another “input format” and “output format” ful for linking molsturm to other third-party quantum chem- for quantum-chemical calculations. Instead, calculations in istry codes: It allowed us to link molsturm to the python molsturm can be initiated cleanly and flexibly directly from interfaces of pyscf,67 as well as adcman94 in only a few a host python script, which can additionally be used for sub- days. As a result, FCI as well as calculations for comput- sequent analysis. This not only implies that all of python and ing excited states by the algebraic diagrammatic construction its libraries are available for the calculation setup and analysis, (ADC) scheme111,112 may be started on top of molsturm’s but also that no explicit parsing of program output is required SCF using the respective aforementioned packages. By way for analyzing the results. This lowers the barriers for people of interface generators like Simplified Wrapper and Interface who are new to the field since they do not need to learn both Generator (SWIG),113 numpy arrays can be automatically how to write input files that define calculations, as well as converted to plain C arrays, such that third-party packages the syntax of a scripting language for parsing results. More consisting only of low-level C++, C, or FORTRAN code can subtly, the output formats of quantum-chemistry programs be linked to molsturm in the future. 084106-9 Herbst, Dreuw, and Avery J. Chem. Phys. 149, 084106 (2018)

We see that the interface of molsturm not only facili- has just become available in gint, as well as comparing it to tates rapid development of new algorithms, but also relieves existing methods subject to the test case provided by a script. one from the need to re-invent the wheel, i.e., to imple- ment standard quantum-chemical methods over and over for A. Coupled-cluster doubles (CCD) each new basis function type. Instead, existing functional- This example shows how one can extend molsturm with ity in external packages can be quickly leveraged for one’s novel methods using its high-level python interface together own purposes. The aspects described in this section will be with standard functionality from python/numpy.73,107 demonstrated with practical examples in Sec.V. Even though molsturm right now neither offers any coupled-cluster method nor an interface to any third-party coupled-cluster code, we managed to implement a simple V. EXAMPLES working coupled-cluster doubles (CCD)114,115 algorithm in In this section, we present two examples that demon- only about 100 lines of code and about two days of work, strate how the python interface of molsturm can be com- including the time needed for research about the method and bined with existing features of python in order to analyze the computational procedures. The most relevant part of the the results or to extend the capabilities of molsturm. We implementation, namely, computing the CCD residual for ab concentrate our discussion on molecular computations with the current guess of the T 2 amplitudes tij , is shown toward contracted Gaussian basis sets. It should be stressed again, the right of Fig.5, side-by-side with the expression of the however, that due to the basis-function independent nature of CCD residual.114 The full CCD code is available as an exam- molsturm, the procedures outlined in the scripts could be ple in the file examples/state interface/coupled easily performed with other types of basis functions as well. cluster doubles.py of the molsturm repository.116 In fact, the design of molsturm assures that the discreti- We follow the standard procedure of employing a quasi- sation details can be selected at a high level, without affecting Newton minimisation of the CCD residual with respect to the code that performs the actual computation and analysis. the T 2 amplitudes using the orbital energy differences as an 96,114 SectionVB gives an example for which the choice of the approximate Jacobian. The guess for the T 2 amplitudes basis type is made in the main function of the script. This is taken from second order Møller-Plesset perturbation theory ensures that a script performing a particular modeling task can (MP2). ab be easily used as a template for a systematic study of the effect The expression of the CCD residual rij requires the eval- of changing basis function type or integral implementation: uation of a sequence of tensor contractions involving the Fock All it takes is to iterate over the appropriate list of discretisa- matrix in the molecular orbital basis, f pq, the antisymmetrised tion parameters and call the calculation for each instance. This electron-repulsion integrals, hpq||rsi, as well as the current ab greatly simplifies testing a novel basis function type, which guess for the T 2 amplitudes, tij . As usual, we employ the

FIG. 5. Equation for the coupled-cluster doubles (CCD) residual114 on the left and excerpt of a CCD implementation using molsturm and numpy on the right. Equivalent quantities are highlighted in the same colour. The first two lines of code show the computation of the antisymmetrised electron repulsion integrals from the state.eri object obtainable from molsturm, which is carried out once at the beginning of the algorithm. The remaining lines compute the residual for a particular T 2 amplitude stored in the tensor object t2. 084106-10 Herbst, Dreuw, and Avery J. Chem. Phys. 149, 084106 (2018) convention that indices i, j, k, l, ... refer to occupied orbitals, indices a, b, c, d, ... to virtual (i.e., unoccupied) orbitals, and indices p, q, r, s, ... to either kind of orbitals. The python implementation (right-hand side of Fig.5) computes those contractions. For this, it employs the data structures molsturm provides in the state object, which is returned by the SCF procedure. Our code uses chemists’ indexing convention in the electron-repulsion integrals object state.eri. The CCD equations, however, are written using the antisymmetrised electron-repulsion integrals hpq||rsi. Therefore the first two lines of the code of Fig.5 are exe- cuted once to perform the antisymmetrisation. The subsequent lines are executed once per CCD iteration and compute the residual tensor res by contracting the relevant blocks of the state.fock eri FIG. 6. Density plot of the final optimised H2O Hartree-Fock geometry with Fock matrix , the object, and the T 2 ampli- a O–H bond length of 0.950 46 Å and a H–O–H bond angle of 106.35◦.A tudes contained in t2. This is implemented using the einsum geometry optimisation in ORCA118 employing the same basis set agrees with method from numpy, which performs tensor contractions this result within the convergence tolerance of 10−5. expressed in Einstein summation convention. Note how the interplay of numpy with the data structures molsturm results in a strikingly close resemblance of implementation repulsion integrals. Individual terms of the Fock matrix or and actual equation. quantities like the overlap matrix in terms of the underlying The state object provides access to more quantities discretisation basis functions may be obtained as well. We from the SCF procedure than just the Fock matrix and the provide this data as numpy arrays extended with extra

FIG. 7. Example for performing a gradient-free optimisation using Pow- ell’s method119,120 and molsturm. python import statements at the top of the script and the explicit call to main are skipped. 084106-11 Herbst, Dreuw, and Avery J. Chem. Phys. 149, 084106 (2018) functionality to simplify implementation of Post-HF quantum- VI. CURRENT STATE AND FUTURE OF MOLSTURM chemical methods, such that the user can employ the SCF results freely and flexibly within the python ecosystem. Cou- After about two years of development, molsturm allows pled with the basis-function independence of molsturm’s us to solve the Hartree-Fock (HF) equations basis-function SCF, this allows for rapid development and systematic investi- independently, following a contraction-based self-consistent gation of Post-HF methods based on arbitrary basis functions. field (SCF) ansatz. All aspects of the calculation, including At the moment, we make no efforts to exploit symme- the diagonalisation algorithm and the basis function type of the try or parallelise the computation of the tensor contractions discretisation, may be fully controlled via a python module. shown in the script of Fig.5. For this reason, such imple- This module integrates well into the existing python ecosys- mentations are not suitable for real-world applications. Never- tem, simplifying repetitive calculations as well as analysis of theless, the script presented in Fig.5 may be used for CCD obtained results. calculations of small molecules with small basis sets. For At present, molsturm’s integral library gint supports 117 example, an O2 6-31G calculation on a recent laptop took calculations employing either Coulomb Sturmians or con- −4 about an hour to converge up to a residual l∞-norm of 10 . tracted Gaussian basis functions, both in multiple implementa- For investigating new methods on top of the molsturm tions. For contracted Gaussians, the third-party libint122,123 framework, or to provide a flexible playground for teaching or libcint105 libraries can be used, and Coulomb Sturmians Post-HF methods to students, such scripts are therefore still are available via our own sturmint124 library. In the future, well-suited. we plan to add support for further basis function types in gint and molsturm, in particular, molecular and generalised Sturmians.25–28 B. Gradient-free geometry optimisation Via gscf, multiple SCF schemes are available, namely, In order to make a novel basis function type properly Roothaan’s repeated diagonalisation,83 Pulay’s commutator accessible to the full range of quantum-chemical methods, a direct inversion of the iterative subspace (DIIS),86 and the trun- daunting amount of integral routines and computational pro- cated optimal damping algorithm (tODA),75 an approximation cedures need to be implemented. For assessing the usefulness of the optimal damping algorithm,77 which is more suitable of a new discretisation method, it is, however, important to be for the contraction-based interface of gscf. During the SCF able to quickly investigate its performance with respect to as procedure, molsturm automatically switches between the many problems as possible. Undoubtedly, a very important available schemes, trying to balance the convergence rate and application of is structure predic- expense of the individual algorithms. tion, i.e., geometry optimisation. Performing such calculations Once an SCF computation has finished, the results can requires the appropriate integral derivatives for the chosen be archived in either in YAML110 plain text or in HDF574 basis function type. Since implementing these in the inte- binary files. Such an archive not only contains the full final gral library can be as difficult as implementing the integrals state of the calculation but also the precise parameters which required for the SCF scheme itself, one would much rather skip were used in the SCF procedure, making the archive file this step at first, and concentrate only on what is required for self-documenting. the SCF. For treating electron correlation, molsturm only imple- This example extends molsturm with a gradient-free ments second order Møller-Plesset perturbation theory (MP2). geometry-optimisation procedure, implemented with building Further methods, however, can be easily called via inter- blocks readily available from python. This sidesteps the need faces to third-party libraries. Full configuration interaction for nuclear derivatives on the side of the integral library and (FCI) is available via pyscf, and a range of excited states- facilitates simple structure optimisations, even without nuclear methods based on the algebraic diagrammatic construction gradients—neither analytical nor numerical. (ADC) scheme via adcman,94 namely, ADC(1), ADC(2), Figure6 shows the script, which performs a geome- ADC(2)-x,111 and ADC(3).112 try optimisation of water based on Powell’s gradient-free The extension of molsturm to other methods or optimisation algorithm119,120 as implemented in the scipy packages is easily accomplished by molsturm’s python library.73,107 The optimal structure is found in a two-step pro- interface; see Sec.V. Along these lines, closer integration cedure. First, a cheap STO-3G2 basis set is used to obtain a with projects such as pyscf,67 Psi4,71 or Psi4NumPy72 reasonable guess. Then, the final geometry is found by min- could be promising since these already provide high-level imising to a lower convergence threshold in the more costly python interfaces to many state-of-the-art Post-HF meth- def2-SV(P)121 basis. ods. In this way, configuration-interaction, coupled-cluster, The time required to code the script was only about 30 min, multi-configurational self-consistent field, or density matrix showing the great power of a flexible design. Nevertheless, renormalisation group approaches could be used directly from convergence to the equilibrium geometry shown in Fig.7 was molsturm’s SCF. With manageable development time, these achieved in a couple of minutes. In line with what was dis- methods would thus become available for all basis func- cussed above, a novel basis function type, for which one just tion types implemented in gint. Similarly, the extension implemented the SCF integrals in gint, can be directly used of molsturm’s SCF toward Kohn-Sham density-functional for geometry optimisations. Only the discretisation parameters theory is possible employing third-party libraries such as need to be changed, in lines 36 and 41 of the outermost main libxc125 or xcfun126 for computing the required exchange- function. correlation integrals. 084106-12 Herbst, Dreuw, and Avery J. Chem. Phys. 149, 084106 (2018)

As discussed in Sec.IVB, a contraction expression inside novel quantum-chemical methods, or rapidly amend func- molsturm’s SCF is evaluated whenever the Fock matrix tionality in a preliminary way, where a proper implementa- is applied to a trial vector. This proceeds by working on tion would be much more involved. We hinted how system- the expression tree, which represents the Fock matrix. In atic comparisons with established basis functions as well as lazyten, the corresponding computations are right now nei- subsequent graphical analysis is convenient to perform by the ther parallelised, nor are symmetries or repetitive terms in the means of our readily scriptable interface. We hope that in this expression tree exploited. This currently limits the applicabil- manner, molsturm will be a useful package to rapidly try ity of molsturm’s contraction-based SCF to small basis set novel basis function types and get a feeling for their range of sizes. Both automatic parallelisation of linear algebra expres- applicability. sions and finding optimal evaluation schemes for expression 127–134 trees is ongoing research, however. By integrating such ACKNOWLEDGMENTS efforts into lazyten, a direct improvement of molsturm’s SCF could be achieved without changing any other code. The authors express their thanks to Adrian L. Dempwolff and Maximilian Scheurer for many fruitful discussions dur- ing the preparation of the work. Michael F. Herbst gratefully VII. DISCUSSION AND CONCLUSION acknowledges funding by the Heidelberg Graduate School of Implementation of quantum-chemical methods using Mathematical and Computational Methods for the Sciences novel types of basis functions often requires unusual numerical (GSC220). Last but not least the authors wish to commemorate techniques as well. Implementing these into existing quantum their former collaborator, supervisor, and friend Dr. Michael chemistry packages can be a large task, as these are highly Wormit, whose ideas have survived in this project as well as optimised for the methods they already accommodate and are in countless others. typically not flexible enough to meet other requirements. 1 The molsturm framework presented here tries to fill this S. F. Boys, Proc. R. Soc. London, Ser. A 200, 542 (1950). 2W. J. Hehre, R. F. Stewart, and J. A. Pople, J. Chem. Phys. 51, 2657 (1969). gap by providing a light-weight package designed with a range 3J. D. Morgan, J. Phys. A: Math. Gen. 10, L91 (1977). of different basis functions in mind. The key ingredient to reach 4F. Jensen, Wiley Interdiscip. Rev.: Comput. Mol. Sci. 3, 273 (2013). the necessary flexibility is a contraction-based self-consistent 5J. G. Hill, Int. J. Quantum Chem. 113, 21 (2013). 6T. Kato, Commun. Pure Appl. Math. 10, 151 (1957). field (SCF) scheme, which we employ for solving the Hartree- 7W. M. C. Foulkes, L. Mitas, R. J. Needs, and G. Rajagopal, Rev. Mod. Fock problem. In a contraction-based ansatz, the numerical Phys. 73, 33 (2001). algorithms are formulated without requiring any explicit refer- 8A. Ma, M. D. Towler, N. D. Drummond, and R. J. Needs, J. Chem. Phys. ence to the Fock matrix memory. Instead, the SCF iterations are 122, 224322 (2005). 9P.-F. Loos, A. Schemama, and M. Caffarel, “Electron-nucleus driven by contractions of the Fock matrix with other vectors. cusp corrections for molecular orbitals,” http://www.irsamc.ups- The details how this matrix-vector product is computed can be tlse.fr/loos/poster/o24.pdf, 2017, cMMSE 2017. varied flexibly, matching the numerical properties of the dis- 10H. Feshbach, Ann. Phys. 5, 357 (1958). 11 cretisation at hand. In this way, we have reached a design where H. Feshbach, Ann. Phys. 19, 287 (1962). 12U. V. Riss and H.-D. Meyer, J. Phys. B: At., Mol. Opt. Phys. 26, 4503 the code for the SCF algorithm is separated from the code (1993). performing the linear algebra computation. Thus, changes to 13R. Santra and L. S. Cederbaum, Phys. Rep. 368, 1 (2002). the SCF scheme can be made without affecting other parts of 14M. Guell,¨ J. M. Luis, M. Sola,` and M. Swart, J. Phys. Chem. A 112, 6384 molsturm and the SCF code itself becomes basis-function (2008). 15P. E. Hoggan, in Self-Organization of Molecular Systems: From Molecules independent. and Clusters to Nanotubes and Proteins, edited by N. Russo, V. Y. On top of that, the interfaces of our SCF are easy-to- Antonchenko, and E. S. Kryachko (Springer Netherlands, Dordrecht, use and readily extensible. This allows quick incorporation 2009), pp. 199–219. 16 of functionality of third-party packages and extensions of F. Harris and H. Michels, Adv. Chem. Phys. 13, 205 (1967). 17E. Steinborn, in Methods in Computational Molecular Physics, edited by molsturm in ways we as the authors would have never G. Dierksen and S. Wilson (Reidel, 1983). thought of. Right now, molsturm may be used to per- 18E. Weniger and E. Steinborn, J. Chem. Phys. 78, 6121 (1983). form calculations based on contracted Gaussians2—using the 19International Conference on ETO Multicenter Integrals, edited by libint122,123 libcint105 C. Weatherford and H. Jones (Reidel, Dordrecht, 1982). integral libraries or —and based 20H. Shull and P.-O. Lowdin,¨ J. Chem. Phys. 30, 617 (1959). 20,21 124 on Coulomb Sturmians —using sturmint. Selected 21M. Rotenberg, in Advances in Atomic and Molecular Physics, edited by Post-HF methods from pyscf67 as well as excited states D. Bates and I. Esterrnan (Academic Press, 1970), Vol. 6, pp. 233–268. 22 methods from adcman94 are available on top. Extending the A. Vincenzo, C. Andrea, and C. Simonetta, Int. J. Quantum Chem. 92, 99 (2003). set of basis function types available inside molsturm can be 23C. Coletti, D. Calderini, and V. Aquilanti, Adv. Quantum Chem. 67, 73 achieved in a plug-and-play fashion, namely, by implement- (2013). ing a single well-defined interface class in our integral library 24D. Calderini, S. Cavalli, C. Coletti, G. Grossi, and V. Aquilanti, J. Chem. gint. Thereafter such basis functions are available for the Sci. 124, 187 (2012). 25J. S. Avery and J. E. Avery, Mol. Phys. 110, 1593 (2012). full molsturm ecosystem including the Post-HF methods 26J. E. Avery, Adv. Quantum Chem. 67, 129 (2013). provided by the third-party libraries mentioned above. 27J. E. Avery and J. S. Avery, Adv. Quantum Chem. 70, 265 (2015). The abilities of molsturm have been demonstrated by 28J. E. Avery and J. S. Avery, Adv. Quantum Chem. 76, 133 (2017). 29 two practical examples with particular emphasis on the way V. Aquilanti, S. Cavalli, C. Coletti, and G. Grossi, Chem. Phys. 209, 405 (1996). our python interface integrates with existing python pack- 30V. Aquilanti, S. Cavalli, and C. Coletti, Chem. Phys. 214, 1 (1997). ages. We showed how to aid repetitive calculations, implement 31V. Aquilanti, S. Cavalli, and C. Coletti, Phys. Rev. Lett. 80, 3209 (1998). 084106-13 Herbst, Dreuw, and Avery J. Chem. Phys. 149, 084106 (2018)

32J. S. Avery and J. E. Avery, Adv. Quantum Chem. 43, 185 (2003). B. Hammer, H. Hakkinen,¨ G. K. H. Madsen, R. M. Nieminen, J. K. 33J. S. Avery, J. E. Avery, V. Aquilanti, and A. Caligiana, Adv. Quantum Nørskov, M. Puska, T. T. Rantala, J. Schiøtz, K. S. Thygesen, and K. W. Chem. 47, 157 (2004). Jacobsen, J. Phys.: Condens. Matter 22, 253202 (2010). 34J. E. Avery and J. S. Avery, Generalized Sturmians and Atomic Spectra 67Q. Sun, T. C. Berkelbach, N. S. Blunt, G. H. Booth, S. Guo, Z. Li, J. Liu, (World Scientific, 2006). J. McClain, E. R. Sayfutyarova, S. Sharma, S. Wouters, and G. K.-L. Chan, 35J. E. Avery and J. S. Avery, J. Math. Chem. 46, 164 (2009). Wiley Interdiscip. Rev.: Comput. Mol. Sci. 8, e1340 (2017). 36D. Calderini, C. Coletti, G. Grossi, and V.Aquilanti, in Computational Sci- 68N. M. O’boyle, A. L. Tenderholt, and K. M. Langner, J. Comput. Chem. ence and Its Applications—ICCSA 2013, edited by B. Murgante, S. Misra, 29, 839 (2008). M. Carlini, C. M. Torre, H.-Q. Nguyen, D. Taniar, B. O. Apduhan, and 69T. Verstraelen, P. Tecmer, F. Heidar-Zadeh, C. E. Gonzalez-Espinoza,´ O. Gervasi (Springer, Berlin, Heidelberg, 2013), pp. 32–45. M. Chan, T. D. Kim, K. Boguslawski, S. Fias, S. Vandenbrande, D. Berro- 37A. Abdouraman, A. Frapiccini, A. Hamido, F. Mota-Furtado, P.O’Mahony, cal, and P. W. Ayers, Horton 2.1.0, 2017. D. Mitnik, G. Gasaneo, and B. Piraux, J. Phys. B: At., Mol. Opt. Phys. 49, 70R. Muller, “Pyquante: Python quantum chemistry,” http://pyquante. 235005 (2016). sourceforge.net; accessed 26 November 2017. 38J. S. Avery, Hyperspherical Harmonics: Applications in Quantum Theory 71R. M. Parrish, L. A. Burns, D. G. A. Smith, A. C. Simmonett, A. E. (Springer, 1989). DePrince, E. G. Hohenstein, U. Bozkaya, A. Y. Sokolov, R. Di Remi- 39V. Aquilanti and S. Cavalli, in Few-Body Problems in Physics, edited by gio, R. M. Richard, J. F. Gonthier, A. M. James, H. R. McAlexander, C. Ciofi degli Atti, E. Pace, G. Salme,` and S. Simula (Springer Vienna, A. Kumar, M. Saitow, X. Wang, B. P. Pritchard, P. Verma, H. F. Schaefer, Vienna, 1992), pp. 573–580. K. Patkowski, R. A. King, E. F. Valeev, F. A. Evangelista, J. M. Turney, 40V. Aquilanti, A. Lombardi, and R. G. Littlejohn, Theor. Chem. Acc. 111, T. D. Crawford, and C. D. Sherrill, J. Chem. Theory Comput. 13, 3185 400 (2004). (2017). 41J. E. Avery and J. S. Avery, Hyperspherical Harmonics and Their Physical 72D. G. A. Smith, L. A. Burns, D. A. Sirianni, D. R. Nascimento, A. Kumar, Applications (World Scientific, 2018). A. M. James, J. B. Schriber, T. Zhang, B. Zhang, A. S. Abbott, E. J. Berquist, 42T. K. Das, Hyperspherical Harmonics Expansion Techniques (Springer, M. H. Lechner, L. A. Cunha, A. G. Heide, J. M. Waldrop, T. Y. Takeshita, 2016). A. Alenaizan, D. Neuhauser, R. A. King, A. C. Simmonett, J. M. Tur- 43J. M. Randazzo, L. U. Ancarani, G. Gasaneo, A. L. Frapiccini, and F. ney, H. F. Schaefer, F. A. Evangelista, A. E. DePrince, T. D. Crawford, D. Colavecchia, Phys. Rev. A 81, 042520 (2010). K. Patkowski, and C. D. Sherrill, J. Chem. Theory Comput. 14, 3504 44D. M. Mitnik, F. D. Colavecchia, G. Gasaneo, and J. M. Randazzo, Comput. (2018). Phys. Commun. 182, 1145 (2011). 73S. van der Walt, S. C. Colbert, and G. Varoquaux, Comput. Sci. Eng. 13, 45J. M. Randazzo, D. Mitnik, G. Gasaneo, L. U. Ancarani, and F. D. Colavec- 22 (2011). chia, Eur. Phys. J. D 69, 189 (2015). 74The HDF Group, HDF5 Reference Manual (The HDF Group, 2011), 46C. M. Granados-Castro, L. U. Ancarani, G. Gasaneo, and D. M. Mitnik, release 1.8.8. Adv. Quantum Chem. 73, 3 (2016). 75M. F. Herbst, “Development of a modular quantum-chemistry 47J. M. Soler, E. Artacho, J. D. Gale, A. Garc´ıa, J. Junquera, P. Ordejon,´ and framework for the investigation of novel basis functions,” Ph.D. D. Sanchez-Portal,´ J. Phys.: Condens. Matter 14, 2745 (2002). thesis, Ruprecht-Karls-Universitat¨ Heidelberg, 2018, https://michael- 48L. Frediani and D. Sundholm, Phys. Chem. Chem. Phys. 17, 31357 herbst.com/publications/2018.05 phd corrected.pdf. (2015). 76B. Sutcliffe, E. Cances,` M. Caffarel, R. Assaraf, G. Turinici, I. Catto, 49E. Tsuchida and M. Tsukada, Phys. Rev. B 52, 5573 (1995). P.-L. Lions, C. L. Bris, O. Bokanowski, B. Grebert,´ N. J. Mauser, X. Blanc, 50L. Lehtovaara, V. Havu, and M. Puska, J. Chem. Phys. 131, 054103 M. Defranceschi, V. Louis-Achille, B. Mennucci, J. Dolbeault, M. J. Este- (2009). ban, E. Ser´ e,´ T. Saue, and H. J. A. Jensen, in Mathematical Models and 51R. Alizadegan, K. J. Hsia, and T. J. Martinez, J. Chem. Phys. 132, 034101 Methods for Ab Initio Quantum Chemistry, Lecture Notes in Chemistry, (2010). edited by M. Defranceschi and C. L. Bris (Springer-Verlag, 2000), Vol. 74. 52J. E. Avery, “New computational methods in the quantum theory of nano- 77E. Cances` and C. Le Bris, Int. J. Quantum Chem. 79, 82 (2000). structures,” Ph.D. thesis, University of Copenhagen, 2011. 78E. Cances` and C. Le Bris, ESAIM: Math. Modell. Numer. Anal. 34, 749 53D. Davydov, T. D. Young, and P. Steinmann, Int. J. Numer. Methods Eng. (2000). 106, 863 (2015). 79R. McWeeny, Proc. R. Soc. A 235, 496 (1956). 54N. M. Boffi, M. Jain, and A. Natan, J. Chem. Theory Comput. 12, 3614 80A. Igawa and H. Fukutome, Prog. Theor. Phys. 54, 1266 (1975). (2016). 81R. Seeger and J. A. Pople, J. Chem. Phys. 65, 265 (1976). 55F. A. Bischoff and E. F. Valeev, J. Chem. Phys. 134, 104104 (2011). 82T. van Voorhis and M. Head-Gordon, Mol. Phys. 100, 1713 (2002). 56F. A. Bischoff, R. J. Harrison, and E. F. Valeev, J. Chem. Phys. 137, 104103 83C. C. J. Roothaan, Rev. Mod. Phys. 23, 69 (1951). (2012). 84V. R. Saunders and I. H. Hillier, Int. J. Quantum Chem. 7, 699 (1973). 57F. A. Bischoff and E. F. Valeev, J. Chem. Phys. 139, 114106 (2013). 85P. Pulay, Chem. Phys. Lett. 73, 393 (1980). 58F. A. Bischoff, J. Chem. Phys. 141, 184106 (2014). 86P. Pulay, J. Comput. Chem. 3, 556 (1982). 59F. A. Bischoff, J. Chem. Phys. 141, 184105 (2014). 87F. Jensen, J. Phys. Chem. A 111, 11198 (2007). 60F. A. Bischoff, J. Chem. Phys. 146, 124126 (2017). 88C. Großmann and H.-G. Roos, Numerik Partieller Differentialgleichungen, 61R. J. Needs, M. D. Towler, N. D. Drummond, and P. L. R´ıos, J. Phys.: Teubner Studienbucher¨ Mathematik, 2nd ed. (Vieweg+Teubner Verlag, Condens. Matter 22, 023201 (2010). 1992). 62J. Kim, K. P. Esler, J. McMinis, M. A. Morales, B. K. Clark, L. Shulen- 89S. C. Brenner and L. R. Scott, The Mathematical Theory of Finite Element burger, and D. M. Ceperley, J. Phys.: Conf. Ser. 402, 012008 (2012). Methods, 3rd ed. (Springer-Verlag, 2008). 63J. Hutter, M. Iannuzzi, F. Schiffmann, and J. VandeVondele, Wiley 90W. E. Arnoldi, Q. Appl. Math. 9, 17 (1951). Interdiscip. Rev.: Comput. Mol. Sci. 4, 15 (2014). 91E. R. Davidson, J. Comput. Phys. 17, 87 (1975). 64A. H. Larsen, J. J. Mortensen, J. Blomqvist, I. E. Castelli, R. Christensen, 92M. Kronbichler and K. Kormann, Comput. Fluids 63, 135 (2012). M. Dułak, J. Friis, M. N. Groves, B. Hammer, C. Hargus, E. D. Hermes, 93M. Wormit, “Development and application of reliable methods for the P. C. Jennings, P. B. Jensen, J. Kermode, J. R. Kitchin, E. L. Kolsbjerg, calculation of excited states: From light-harvesting complexes to medium- J. Kubal, K. Kaasbjerg, S. Lysgaard, J. B. Maronsson, T. Maxson, T. Olsen, sized molecules,” Ph.D. thesis, Universitat¨ Frankfurt, 2009. L. Pastewka, A. Peterson, C. Rostgaard, J. Schiøtz, O. Schutt,¨ M. Strange, 94M. Wormit, D. R. Rehn, P. H. Harbach, J. Wenzel, C. M. Krauter, K. S. Thygesen, T. Vegge, L. Vilhelmsen, M. Walter, Z. Zeng, and K. W. E. Epifanovsky, and A. Dreuw, Mol. Phys. 112, 774 (2014). Jacobsen, J. Phys.: Condens. Matter 29, 273002 (2017). 95A. Dreuw and M. Wormit, Wiley Interdiscip. Rev.: Comput. Mol. Sci. 5, 65J. J. Mortensen, L. B. Hansen, and K. W. Jacobsen, Phys. Rev. B 71, 035109 82 (2014). (2005). 96T. Helgaker, J. Olsen, and P. Jorgensen, Molecular Electronic-Structure 66J. Enkovaara, C. Rostgaard, J. J. Mortensen, J. Chen, M. Dułak, L. Ferrighi, Theory, 1st ed. (Wiley, 2013). J. Gavnholt, C. Glinsvad, V. Haikola, H. A. Hansen, H. H. Kristoffersen, 97Latency numbers every programmer should know, https://gist.github.com/ M. Kuisma, A. H. Larsen, L. Lehtovaara, M. Ljungberg, O. Lopez- hellerbarde/2843375; accessed 08 February 2018. Acevedo, P. G. Moses, J. Ojanen, T. Olsen, V. Petzold, N. A. Romero, 98D. Cheney, Five things that make Go fast, Presentation at Gocon2014, J. Stausholm-Møller, M. Strange, G. A. Tritsaris, M. Vanin, M. Walter, Tokyo, Japan, 2014. 084106-14 Herbst, Dreuw, and Avery J. Chem. Phys. 149, 084106 (2018)

99Y. Saad, Iterative Methods for Sparse Linear Systems, 2nd ed., edited by 121F. Weigend and R. Ahlrichs, Phys. Chem. Chem. Phys. 7, 3297 (2005). Y. Saad (SIAM Publishing, 2003). 122E. F. Valeev, Libint: A library for the evaluation of molecular integrals 100P. Arbenz, Lecture notes on solving large scale eigenvalue problems, of many-body operators over Gaussian functions, http://libint.valeyev.net Lecture Notes, ETH Zurich,¨ 2010. (2017), version 2.3.1. 101Y. Saad, Numerical Methods for Large Eigenvalue Problems, 2nd ed. 123E. Valeyev, J. Calvin, D. Lewis, J. Dullea, C. Peng, K. Nishimra, J. T. (SIAM Publishing, 2011). Fermann, J. D. Whitfield, O. Certˇ ´ık, M. F. Herbst, S. Y. Willow, and 102P. Hudak, ACM Comput. Surv. 21, 359 (1989). D. Williams-Young, evaleev/libint: 2.3.1, 2017. 103A. Buluc¸, J. T. Fineman, M. Frigo, J. R. Gilbert, and C. E. Leiserson, in 124J. E. Avery and M. F. Herbst, https://molsturm.org/sturmint. Symposium on Parallelism in Algorithms and Architectures (SPAA) (ACM, 125S. Lehtola, C. Steigemann, M. J. Oliveira, and M. A. Marques, SoftwareX 2009), pp. 233–244. 7, 1 (2018). 104J. Hughes, in Research Topics in Functional Programming (Addison- 126U. Ekstrom,¨ R. Bast, S. S. Reine, C. Jacob, J. Juselius, E. Rebolini, Wesley, 1990), Chap. 2, pp. 17–42. R. D. Remigio, A. S. P. Gomes, S. Reimann, A. Borgoo, M. Ilias, and 105Q. Sun, J. Comput. Chem. 36, 1664 (2015). yurivict, Xcfun DFT library, http://dftlibs.org/xcfun; accessed 11 June 106J. D. Hunter, Comput. Sci. Eng. 9, 90 (2007). 2018. 107E. Jones, T. Oliphant, P. Peterson et al., SciPy: Open source scientific tools 127G. Baumgartner, A. Auer, D. Bernholdt, A. Bibireata, V. Choppella, for Python (2001–); accessed 09 March 2017. D. Cociorva, X, R. H. Gao, S. Hirata, S. Krishnamoorthy, S. Krishnan, 108W. McKinney, J. Reback et al., PANDAS: Python data analysis library C. Lam, Q. Lu, M. Nooijen, R. Pitzer, J. Ramanujam, P. Sadayappan, and (2008–); accessed 09 March 2017. A. Sibiryakov, Proc. IEEE 93, 276–292 (2005). 109F. Perez´ and B. E. Granger, Comput. Sci. Eng. 9, 21 (2007). 128E. Solomonik, D. Matthews, J. Hammond, J. Stanton, and J. Demmel, 110O. Ben-Kiki, C. Evans, and I. dot¨ Net, YAML Ain’t markup language J. Parallel Distrib. Comput. 74, 3176 (2014). (YAML) version 1.2, http://www.yaml.org/spec/1.2/spec.html (2009), 129E. Peise, D. Fabregat-Traver, and P. Bientinesi, in High Performance Com- accessed 03 December 2017. puting Systems. Performance Modeling, Benchmarking, and Simulation, 111J. Schirmer, Phys. Rev. A 26, 2395 (1982). edited by S. A. Jarvis, S. A. Wright, and S. D. Hammond (Springer-Verlag, 112A. B. Trofimov, G. Stelter, and J. Schirmer, J. Chem. Phys. 111, 9982 Cham, 2015), pp. 193–212. (1999). 130J. A. Calvin, C. A. Lewis, and E. F. Valeev, in Proceedings of the 5th 113D. Beazley, L. Ballabio, W. Fulton, M. Gossage, M. Koppe,¨ J. Lenz, Workshop on Irregular Applications: Architectures and Algorithms, IA3 M. Matus, J. Stewart, A. Yerkes, S. Yoshiki, S. Singhi, X. Delacour, ’15 (ACM, New York, NY, USA, 2015), pp. 4-1–4-8. O. Betts, and D. Z. Gang, SWIG: Simplified wrapper and interface 131B. Huber and S. Wolf, Xerus—A general purpose tensor library, generator, accessed 09 March 2018. https://libxerus.org (2014–2017); accessed 10 March 2018. 114R. J. Bartlett and G. D. Purvis, Int. J. Quantum Chem. 14, 561 (1978). 132M. R. B. Kristensen, S. A. F. Lund, T. Blum, and J. E. Avery, in Proceed- 115A. C. Hurley, Electron Correlation in Small Molecules (Academic Press, ings of the 2016 International Conference on Parallel Architectures and London, New York, 1976). Compilation, PACT 16 (ACM, 2016), pp. 71–85. 116M. F. Herbst and J. E. Avery, https://molsturm.org. 133M. R. B. Kristensen, J. E. Avery, T. Blum, S. A. F. Lund, and B. Vinter, 117W. J. Hehre, R. Ditchfield, and J. A. Pople, J. Chem. Phys. 56, 2257 (1972). in International Conference on High Performance Computing (Springer, 118F. Neese, Wiley Interdiscip. Rev.: Comput. Mol. Sci. 2, 73 (2012). 2016), Vol. 9945. 119M. J. D. Powell, Comput. J. 7, 155 (1964). 134E. Epifanovsky, M. Wormit, T. Kus,´ A. Landau, D. Zuev, K. Khistyaev, 120W. H. Press, S. A. Teukolsky, W. T. Vetterling, and B. P. Flannery, P. Manohar, I. Kaliman, A. Dreuw, and A. I. Krylov, J. Comput. Chem. Numerical Recipes (Cambridge University Press, 1992). 34, 2293 (2013).