Ab initio calculations on a microcomputer - Journal of Chemical

Bits and pieces, 35. Program that performs a Hartee-Fock-Roothaan calculation for a two-electron diatomic molecule on Apple II+ and IIe computers...
0 downloads 0 Views 7MB Size
Bits and Pieces, 35 Guidelines for Authors of Bits and Pieces appeared in July 1986. Most authors of Bits and Pieces will make available listings and/or machine-readable versions of their programs. Please read each description carefully to determine compatibility with your own computing environment before requesting materials from any of the authors. Several programs described in this article and marked as such are available from Project SERAPHIM. Diskettes are available a t $5 per 5V-in. disk, $10 per 31/2-in. disk; program listings and other written materials are available for $2 each; $2 domestic or 510 foreign postage and handling is required for each shipment. Make checks payable to Project SERAPHIM. T o order, or get a Project SERAPHIM Catalogue, write to: John W. Moore, Director, Project SERAPHIM, Department of Chemistry, Eastern Michigan University, Ypsilanti, MI 48197. (Project SERAPHIM is supported by NSF Science and Engineering Education Directorate.)

ence Manual (2))although a smaller voltage usually works. Apple I1 hardware registers the instantaneous polarity of the voltage applied a t the cassette input by setting the sign of the byte stored at $C060. This polarity is accessible from KASIC or from assembly language. For the audio frequenciesof the experiment (1-2 kHz) only the latter has adequate speed. Our assembly language counting program, the logic of which is indicated in Figure 1, is a callable subroutine of an administrative BASIC program. Time intervals may be measured using, for example, the sweep second hand of a wall clock. Counting is started a t time zero by pressing a key, usually the space bar. Computer counting1 of polarity changes then

Audio Frequency Measurements for Heat Capacity Ratios Using Apple I1 Robert V. St. Louis University of Wisconsin-Eau Claire Eau Claire. WI 54702

The heat capacity ratios y = CdC, of simple gases are important in the history of quantum theory. The classical equipartition theorem yielded predicted values of y that were in agreement with experiment for monatomic gases but gave erroneous predictions for polyatomic gases. For instance, for air, ?(predicted) = 1.29, whereas y(measured) = 1.40 a t room temperature. The discrepancies were resolved after the introduction of quantum theory and the quantum formula for vibrational heat capacity. These points can be made clear to the student who measures heat c a.~ a c i.t vratios iur se\.eral simple gases. The speed-ol-sound method of meahuremenr involves >I Kundt's tuhe: an essential vart of thin procedure is the accurate measurement of the frequency of the sound wave that is set up in the gas in the tube. We have used Apple I1 plus and IIe computers to measure the frequency of sound waves in the experiment "Heat Capacity Ratios for Gases" ( I ) . This offers an interesting and precise alternative to using a commercial frequency counter, making tuning fork comparisons of pitch, or calibration methods discussed in ref. I. No special input-output board is needed; a simple shielded cable attached to a "mini plug" (e.g., Radio Shack #42-2434) connects the signal to the computer's cassette input jack. The ac voltage source driving the loudspeaker or the amplified signal from the receiving microphone may be measured; we have used the latter. Before attachment to the computer is made the voltage should be adjusted to approximately 0.37 V ac (1.0 V peak-to-peak, consistent with the recommendation in the Apple I1 Refer-

' A 3-bytecounter is used. 788

Journal of Chemical Education

0 $till

positive?

I s Figure 1. Flow chart for

hY Return

program thatcounts polarity transitions

begins and continues until the space bar is (again) pressed. The elapsed time, for example. an interval of 120 seconds. is then entered. The total number of cycles is half the counted number of polarity changes; division hv. elapsed . time vields average fre&enc$over tIhe interval. Precision is dependent on the reaction time of the operator, the size of the time interval used, and the stability of the audio oscillator; with 2-minute intervals we obtain precisions of the order of tenths of a percent. I t is pleasing that such precise results may be obtained using a minimum of hardware of software. The resultant freauencies. in comhination with measured temperatures and wavelengths, yield the expected heat-ca~acitv . " ratios within exnerimental error. If noise is superimposed on the sine wave signal, false zero crossings may be counted if the computer's polarity sampling is too fast; for this reason, a time delay was inserted between samplings. . . We arbitrarily chose to sample - approxi.mately 12 times per cycle. A one-byte delay parameter makes possible this delay for the frequencies of the experiment. The delay parameter is calculated in the BASIC program from an input rough estimate of the expected frequency; the parameter is then poked into memory for use by the delay part of the counting subroutine (sse Fig. 1). The procedure and use of the program are conveniently tested on an ac voltage source of known frequency. We use wall-olue . .. voltaee that has been dronned .. to 6.3 V ac bv a small step-down transformer and further reduced to 0.3; V ac hv a 100 K voltarc divider (~utentiurneter~. Measured z the method. freqiency values ver; close to 6 0 ~ verify Copies of the program may he obtained from the writer.

Exercises in QuantumMechanics Frank Rloux Saint John's University Collegeville. MN 56321 A simple, hut reasonably accurate, Enler finite difference approximation is used to obtain numerical solutions for a wide variety of quantum mechanical problems. The prohlems treated require solutions for the Schroedinger equation and the relativistic Klein-Gordon equation. The computer programs are written in BASIC code and utilize the graphics capability of the microcomputer to display the solutions. The problems treated are Pnrric..~in rhr onr-dinwniimal polmtlnl well R c h r i \ , i ~ r i cpartirir in the me-dimensimal purenrinl u,ell VRIIIIIIS perrurbrd particle i n th* unrdimensionnl uell problems Particle an a ring Quantum mechanical tunnelling.of potential harriers with an . extension to metallic band theory One-dimensionalmodels of the van der Waals interaction and the nuclear force One-dimensional models for the H atom, Het ion, positronium, and the muonic atom A SCF calculation on a one-dimensionalmodel for the He atom The simple harmonic oscillator, anharmonic oscillator, and the isotope effect Numerical solutions to the radial equation far the three-dimensional hyrogen atom Numerical solutions to the radial eauatian far the relativistic treatment of the hydrogen atom Quasi-classicalmodels for the hydrogen atom and the hydrogen molecule ion. These exercises represent an extension of work reported earlier in this series (3).The programs and accompanying instructions for the exercises are available on floppy disk through SERAPHIM. The programs have modest memory requirements and have been written for IBM and IBMcompatible PC's. However, they can he easily modified to run on any standard microcomputer.

Ab lnitio Calculations on a Microcomputer Lynne H. Reed Princeton University Princeton, NJ 08544 Arthur R. Murphy Fairleigh Dickinson University Teaneck.NJ07666 Many chemistry majursare never exposed to3h initioselfronsistent field rSCFl uuantum mrchnnicnl cnlculntiuns. This situation is an unfdrtunate one, hut i t is understandable because some chemistry departments may not have ready access to mini- or mainframe computers. Fortunately, microcomputers may be used to introduce students to such calculations. We have recently translated and modified the ah initio SCF FORTRAN program appearing in Appendix B of the excellent hook by A. Szaho and N. Ostlung (4) into a highly interactive BASIC program that can be used with the uhiquitons Apple 11+ and Apple IIe microcomputers. The proeram. which ~ e r f o r m sa Hartree-Fock-Roothaan calcula;ion for a two:electron diatomic molecule, has great pedogogical value, and it should prove quite useful in courses such as physical chemistry, quantum chemistry, molecule strncture, and mathematical methods in chemistrv. Depending m the course, instructors could either prrsent a rletailrd descrip~ionutmnior aectionsoithe calrulation.or they could focus on the anal& and use of the output. The calculation is performed in the following manner. The Hartree-Fock equations obtained from a restricted closedshell two-electron Slater determinant are transformed into the Hartree-Fock-Roothaan equations by introducing a minimal basis set consisting of 1s-contracted Gaussian-type functions. By means of a unitary transformation obtained from a canonical orthogonalization of the basis functions, the transformed Hartree-Fock-Roothaan equations are ohtained. An interaction method is used to solve these nonlinear equations. After guessing a t a density matrix, the transformed Fock matrix is diagonalized. The resulting eigenvectors are transformed, and a new densitv matrix is computed. This procedure is repeated until convergence is attained, or it is aborted if the number of iterations exceeds a fixed numher. T o initiate a calculation, six parameters must he entered: the atomic numbers of the two nuclei, the internuclear distance, the length of the contraction used in the contracted Gaussian functions. and the Slater orbital exnonents for each atom. The outout consists of the orbital enereies. eieenvectors. the electrckc energy, the total electronic energy including nuclear-nuclear reoulsion. various matrices. and a Mulliken population analysis. Students could use the results from calculations performed a t different internuclear distances to obtain a potential energy curve. An approximate equilibrium internuclear distanceas well as a dissociation energy could then he determined. The ionization potential, electron affinity, and Mulliken nooulation analvsis could also he criticallv analvzed. .. Written documentation focusing on various theoretical aspects of the calculation as well as a 5%-in. disk containine thk SCF program and additional documentation, for use with an Apple I I + / A D DIIe ~ ~ microcomnnter with 64K memory, may be obtained &om Project SERAPHIM. Acknowledgment The main formulas appearing in the "Discussion of Iutegrals" section of the written documentation as well as the Author to whom correspondence shollld be sent. Volume 64 Number 9

September 1987

789

FORTRAN SCF programs are from (4). We wish to thank the Macmillan Publishine Comnanv . " for allowine us to use this material.

-

X-Ray Structure Refinement and Electron Density Map: A Computer Programming Experiment G. L. Breneman Eastern Washington University Cheney, WA 99004

The structure of K2PdClerequires only the determination and refinement of one oositional parameter since all of the othersare fixed by symmetry. ~ e f i n i n gthii pnrameteralong nit11 [he or,erall temprrsture fartor and the data scale tactclr make a reasonable a i d interesting computer problem for an upper-division chemistry course. An electron-density map of the structure can also be calculated giving a direct picture of the locations of the atoms in the unit cell. Both of these projects involve millions of mathematical operations and conclusively show students that certain types of programs absolutely require the use of computers. Refinement All of the positional parameters fixed by symmetry are given to the student. Only the x coordinate of C1 at x , 0, 0 need be determined. This value. which corresnonds to the I'd CI bond length since there isa I'd at 0,0,0 in the sell.ran hr rsrimatcd t n m thr knuwn atomic rrtdii of Pd and Cl. The observed data consist of 51 structure factors. A simple trialand-error procedure was adopted where different valu6s of the Cl's x-parameter, the &era11 temperature factor, the scale factor are used to calculate R. The set of these three parameters that give the lowest R value are considered the best. The lowest value of R that could be achieved with the given data was 0.051, which is consistent with many accurately determined structures. If a total of 1000 different combinations of the three Darameters (10 values for each) are tried, the computer must perform about 2,200,000 mathematical operations including addition, multiplication, division, exponents, and function (cosine) evaluation. More calculations can be done to refine the parameters to the limit of computer round-off error. Electron Denslty Map The formula for the electron density is given to the student. All of the data needed for this formula are not contained in the given observed structure factors as many intensities are related to each other by the m3m diffraction symmetry for this structure. A short section of computer coding that generates the missing data is furnished to the student along with the value for F(000). The and - signs on the calculated structure factors are applied to the observed structure factors. An electron-densitv . mar,. is then calculated, and contours are drawn through points of constant electron density with the atoms showing up very plainly as peaks (see Fig. 2.). Approximately 5,400,000 mathematical operations are required for a map covering one-eighth of the unit cell.

Figure 2. Section of electron density map showing Pd and CI atoms.

terson map can be calculated hy substituting the square of the observed structure factors in place of the structure factors in the electron-density formula. This map, which shows vectors between all the atoms, can be used to find the P d atoms (and perhaps others). These positions can be used to calculate structure factors and an electron densitv man. Some or all of the missing atoms willshow up on themap and can be included in another round of calculations. The refinement and electron density map for K2PdCk make an interesting and significant experiment. Many of the ideas used in X-ray crystallography are involved and an appreciation of the necessity (with 7,600,000 calculations involved) for using computers in this area is gained without getting bogged down in too large a programming problem. (A 60-line BASIC or similarly short program in other languages will do the job). A VAX BASIC program listing and a complete set of student handouts for this experiment are available from SERAPHIM. Acknowledgment The original experiment on which this one is based was developed by R. D. Willett, Washington State University.

Problem Solving in Physical Chemistry Using Electronic Spreadsheets

+

Extenslons and Concluslon Individual temperature factors could he included in the equation for the structure factors and varied to give a minimum value for R. Then the differences in the maenitude of vibration of the Pd, K, and C1 atoms could be compared. This addition would. however. add two more parameters to the refinement and 'could inc;ease the number of calculations bv a factor of 100. I t isBlso possible to solve the structure from scratch by modifying the electron-density program used above. A Pat790

Journal of Chemical Education

Bhairav D. Joshi State University of New York Geneseo. NY 14454 Electronic spreadsheets have been generally thought of as programs designed primarily for business-oriented applications. Our ex~eriencein the use of these orozrams during the past two suggests that they are e&aily well suited as scientific problem-solving tools. In this note we present two examples of the ways and spreadsheet LOTUS 1-2-3 is being used on an IBM PC for problem solving in our undergraduate physical chemistry c o u r ~ e . ~ lteratlve Computation of Roots Numerous time-consuming problems in physical chemistrv involve findine roots of eauations of various t . v.~ e sSuch . problems can be handled in a quick and routine way using an "LOTUS 1-2-3".

Cambridge. MA, 1985.

Release 2; Lotus Development Corporation,

appropriately designed spreadsheet template. One such temnlate. of . . useful for findine the roots of anv" nolvnomial ." amder 3, is shown in Figure 3. The user supplies the values of thecoefficients A throueh D and the initial euessof the root. ~ ( 0 )An . improved x(2), is found u s k g the ~ e w t o n ' s formula ( 5 ) ,x(2) = x(0) - F(xO)lF'(xO). Here the first derivative F(x0) is approximated by the quotient (Ffxl) F(xO))ldx, where x(1) = x(0) dx and dx = 0.001. The automation of the template is accomplished by the macro shown in Figure 4. With veri few changes in its overall structure, the template shown in Figure 3 can be modified to solve just about any equation for irealroot. Such templates provide unlimited power to users interested in the "what-if' aspects of the parametric dependence of real solutions of any equation in one unknown.

-

Quantum Mechanical Expansion Theorem Given a comnlete orthonormal set of well-behaved functious satisfyingcertain boundary conditions in the specified domain of their variables, anv other function in the same domain and satisfying the s a k e boundary conditions can always be expanded as a convergent infinite series in terms of the given orthonormal set of functions (6). As an example, consider the expansion of F(y) = y ( l - y)3 in terms of particle-in-a-box wave functions, $&) = @sin (nrry), where 0 5 y 5 1and n 2 1.The expansion of F(y) in terms of $.(y) is

Solve t h i s equation by the Newton'r method: F(X1 = AVO3 + B'X"2 6 7 Procedure: 8 9 10

!!

1. 2. 3.

Type must Type Type

+ CX '

+ 0

=

0

t h e valuer o f c o e f f i c i e n t 3 A through 0 . Each entry be followed by the [Enter1 Ley. i n i t i a l guess under X(O), and press I E n t e r I key IAltIl

Figwe 3. Spreadsheet template for finding roots of any polynomial of order three.

5 6

I1

7 8 9 10

LoOD

C a l c u l a t e an improved guess Go t o t h e c e l l c o n t a i n i n g X I 0 1 Enter improved gucrr c a i r v 1 a t e an improved guess lxi1E-l5~@abr((l(Ol-X(2l~/X(Z~~xlxqT e s t f o r convergence IxgLoopr Repeat, i f not converged

lcalcl lgofolX(O)% tX(21x lcaicl*

Figure 4. Mano to automate the template shown in Figws 3

where ..

Two key segments of a spreadsheet designed to evaluate the sum of eq 1 and test its convergence are shown in Figure 5. The basic formula for C.J.(\ I is first entered in the cell ,., .. , B18. The relative and absolute addressing capabilities of LOTUS 1-2-3 then make it nossible to simnlv . . conv .. this formula from B18 into the re& of the table spanning all of t h e n and v values chosen. This comnletes the calculations of all ~,+,0;) values needed. T o studs the convergence of the sum in ea 1, let Fvi represent ;he sum of first i terms in the series: Four such sums are shown in Figure 3 in rows 24 through 27 for typical values of y, and corresponding exact values of f ( y ) are shown in row 29. A visual comparison of Fyl, Fy2, Fy5, and F h ) is shown in Figure 6, demonstrating that as i increases Fyi converges to F(y).4The percent error in Fyi is a function of i as well as y. Its dependence on i for y = 0.99 is demonstrated in Figure 5, rows 31 through 35.

-

Figure 5. Spreadsheetdesigned to Implement the qvantvm mechanical expansion theorem.

Conclusion Availabilitv. of snreadsheet temolates to e x ~ l o r different e . types of prohlems can minimize students' fears about learning the intricacies of LOTUS 1-2-3. Once thev- a~nreciate .. the power and elegance of this spreadsheet program with the help of a few well-designed templates, they are willing to explore the program ontheir ownand soon (earn to develop their own worksheets. These fast and powerful computational and graphic tools can help them acquire a better understanding of the equations and data encountered in their courses. Note Detailed descriptions of templates outlined here and other ~hvsicalchemistrv temnlates are available to interested readers from the author f& $5 (US funds). 'The plots shown in Figure 4 were generated from thedata partially shown in Figure 3 using the high-resolution graphics capabilitiesof

Figure 6. Vlsual comparison of a function Fy with three series approximations

LOTUS 1-2-3.

Fyl, Fy2, and FyS.

Volume 64

Number 9

September 1987

791

Simplex Optimization: A Computer Program tor Instrumental Analysis James P. Deavor College of Charleston Charleston. SC 29424 One of the problems of any instrumental analysis course is deciding what material should be covered in lecture and what experiments to perform in lab. Many techniques are discussed and employed in any course hut many have to he left out due to time limitations. One way of attacking this problem is by use of CAI that can be assigned as either homework or for use during lab time. Experimental design is a topic that can be covered in this manner; it should be discussed but often is not covered. This nroeram is desiened for use on an IBM PC. I t consists of five sections: (1)di&ssion of experimental design and simplex optimization, (2) a sample simplex calculation, (3)a demonstration of simplex optimization, (4) a student problem to solve, and (5) a review section. This entire program can be completed by a novice in 45-60 minutes. A menu allows students to uerform whatever sections of the program that they desire tb complete a t any one sitting. within a section a student can advance or reverse one screen a t a time or return to the menu. The discussion section introduces experimental design. Both erid searches and one-factor-at-a-time methods are discusiedand shown. The student isshown what asimplex is and how the simulexmethod works. This isdone in alecturetype format but requiresstudent responsesat several points. In the second sertion thestudent is led throueh a calculation of determining a new simplex vertex. This includes a discussion of how to rank the resnonses. in the third section. A synA demonstration is thesis problem is explored to determine the optimum conditions of reaction temperature and mass of one reactant in order to achieve a maximum percent yield. Another demonstration is then performed starting i n another region of factor space to assure that a global optimum has been determined instead of a local optimum. Examples of poorly chosen initial vertices are also shown and discussed. The student uroblem allows the student to solve a simulex optimization p;oblem by selecting the starting verticesand then seeine how the outimization uroceeds. The review section allowsUthestude; to see again the main concepts.

the use of computer programs to students of electrochemistry at university level. Aprogram of data treatment andsimulation of impedance diagrams has been prepared in BASIC for a HP-85 HewlettPackard microcomputer using also a 7225B Hewlett-Packard nlotter. The nroeram . ,. has two ontions. The first treats the experimental impedance diagram to obtain the parameters of thc Randleg cuuivalent circuit after adiustine these data to the theoretical equations: a semicirc1e"for hGh freauencies and a straieht line for low freauencies. Afterwards. the program a diagram with the experimental points and the optimized curve, on both the microcomputer screen and the plotter. The second option permits, after introducing the values of the different parameters involved in the Randles circuit, to elaborate the data and represent graphically the resulting curve. The program works with the approximated equations relating the imaginary, Zi,, and therealpart,Z,, of the impedance corres~ondineto a simnle electron-transfer reaction in iteadr state with semi-infinite linear diffusion, the oxidized and reduced snecies beine h t h soluble. In the hieh - freuuency limit,

-

and in the limit of low frequencies, Z,. = Z,

- R , - R,,+ 202C,

(2)

where Rn is the resistance of the solution, Rct the resistance of the charge transfer process, and Cd the capacity of the electrical double layer; a is a function of the bulk concentration and the diffusion coefficients of the oxidized and reduced species. The first option of the program (determination of the parameters) is illustrated in Figure 7. After input of the Zi, and the 2, values for each frequency the program determines the values of Rd, Rn, and Cd. the latter as a function of a. The algorithm used in this program cosists of applying the least-sauares nrocedure for the straieht line correspondine to the low fre&encies. With respect the semicircle part 2 hieh freauencies. a chanae of variables in order to obtain the equation of a straight line has been performed; then, the least-squares urocedure has also been applied for determining thepara&ters of the equivalent circuit. The second option (simulation), cf. Figure 8, permits one to obtain impedance diagrams according to the Randles equivalent circuit after introducing the values of Rn, RCt,Cd,

to

~lecirochemicalix~eriment' F. Amau, P. LI.

Cabot, M. Cortes, and J. M. Costa Universitat de Barcelona Av. Diagonal, 647, 08028 Barcelona, Spain

Nowadays, faradaic impedance measurements are being widely applied in order to study many electrochemical systems (7-9). These techniques provide useful information on the electrochemical double laver. , the kinetics of fast electron-transfer reactions and the adsorption of species on the electrodes. Valuable data on metal corrosion and film formation have also been obtained by studying impedance diaerams. This wide annlication has been enhanced bv the recent developmenth'f electronics that make i t possible to record ac uarameters under dvnamic conditions and work within a very sensitive timescale. The use of computers in this kind of measurements makes possible a meat economy of time as well as permitting one tisimulate