The Nuts and Bolts of FirstPrinciples Simulation 4
The Nuts and Bolts of First-Principles Simulation 4: The New CASTEP Durham, 6 th-13 th December 2001 Nuts and Bolts 2001 CASTEP Developers’ Group with support from the ESF k Network Lecture 4: Introduction to New CASTEP
Lecture 4: New CAmbridge Serial Total Energy Package An introduction… The Nuts and Bolts of Durham, Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP First-Principles Simulation 6 th-13 th December 2001
What New CASTEP is not r It’s not just CAmbridge r It’s not just r It’s doesn’t just calculate Total Energies r However, it is still a Package! Nuts and Bolts 2001 Serial Lecture 4: Introduction to New CASTEP� 3
So, What is it Then? Introduction to the CASTEP Developer’s Group r The goals of the New CASTEP project r A brief history of New CASTEP r The features of the package r How to use the code (command line) r Philosophy and design of the code r The future of New CASTEP r Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 4
The CASTEP Developers Group Mike Payne (Cambridge) r Matt Probert (York) r Chris Pickard (Cambridge) r Stewart Clark (Durham) r Phil Hasnip (Cambridge) r Phil Lindan (Kent at Canterbury) r Matt Segall (Cambridge, Camitro UK Ltd. ) r Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 5
The Goals of New CASTEP Ease of maintenance r Ease of future development r Portability r Efficiency r These goals are sometimes conflicting, therefore a compromise must be found Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 6
A Brief History of New CASTEP r r r July ‘ 99: A meeting of interested parties. Is there a need for a new PW pseudopotential code? July ’ 99 -> Jan. ’ 00: Informal specification group outlines the spec. of a new code. Feb. ’ 00: Implementation of new code begins. CDG formed. May ’ 01: Agreement reached with MSI (Now Accelrys) to commercialise New CASTEP. Dec. ’ 01: Code freeze on first version of New CASTEP. Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 7
New CASTEP Features Parallel, portable code r Geometry Optimisation r l l r Molecular Dynamics l l r BFGS Damped MD NVE NVT Linear Response for Phonon spectra Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 8
CASTEP Features Continued r Transition state search l r LST/QST Electronic properties l l l Optical Spectra DOS Population Analysis Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 9
CASTEP Technical Features r Ultrasoft/Norm-conserving pseudopotentials l Pseudopotential generation on-the-fly Double grid technique for charge/potential grid r Multiple electronic minimisers r l l All-bands CG RMM/DIIS Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 10
Technical Features Cont… r Metals treated by l l r Exchange-Correlation Potentials l l l r Density mixing Ensemble DFT LDA Perdew-Wang `91 GGA PBE/RPBE GGA Non-linear core corrections Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 11
How to Use the Code: The Cell File ! Example cell file for primitive Si. C %block LATTICE_ABC 3. 074500 60. 0 %endblock LATTICE_ABC 3. 074500 60. 0 %block POSITIONS_FRAC Si 0. 0000 C 0. 2500 %endblock POSITIONS_FRAC Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 12
More Cell File Keywords KPOINTS_MP_GRID 4 4 4 %block SYMMETRY_OPS … %endblock SYMMETRY_OPS %block SPECIES_POT C my_C_pot. usp %endblock SPECIES_POT Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 13
Controlling the Calculation: The Parameter File Task : Geometry. Optimization XC_functional PW 91 Basis_precision Precise Electronic_minimiser CG Elec_energy_tol = 0. 000001 e. V Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 14
More Parameters… Geom_method BFGS Geom_force_tol : 0. 01 hartree/bohr Fix_occupancies = TRUE Continuation = my_last_run. check Energy_unit = kcal/mol Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 15
Example Output [Summary of cell and parameters input] -----------------------------------SCF loop Energy gain Timer per atom (sec) -----------------------------------Initial 6. 99675047 E+002 4. 22 1 -8. 56371636 E+002 1. 94505835 E+002 23. 70 2 -8. 57260747 E+002 1. 11138925 E-001 42. 59 3 -8. 57286394 E+002 3. 20580434 E-003 62. 00 4 -8. 57286462 E+002 8. 55207285 E-006 80. 91 5 -8. 57286463 E+002 3. 12287085 E-008 98. 20 ------------------------------------ <-<-<-<-<-<-- SCF SCF SCF [Forces, stresses, Gemoetry optimisation, MD run…] Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 16
Design Philosophy of New CASTEP Written specification, prior to coding! r Implemented in FORTRAN 90 r Modular approach (F 90 not truly object oriented) r Data abstraction using derived data types r Overloading for simple, clear subroutine names r Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 17
Why FORTRAN 90? A language for numerical codes r ‘Designed’ with optimisation in mind good numerical efficiency r ‘Modern’ high level language r l l Modules (classes) Interfaces (prototypes) Memory allocation Derived types Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 18
Code Structure (Overview) Functional Modules • The ‘Physics’ • High-level Fundamental Modules • The building blocks • Define types and operations Utility Modules • Machine-dependant • Low-level algorithms Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 19
Utility Modules Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 20
Utility modules provide: Fundamental constants r API for parallel execution r I/O r l l r Basic operations, e. g. opening and closing files Freeform file I/O Generic algorithms l l l FFTs Matrix inversion Random numbers Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 21
Fundamental Modules Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 22
Example type: Wavefunction type, public : : wavefunction integer : : nbands integer : : nkpts integer : : nspins ! Max no. bands ! No. of kpts ! No. of spins represented complex(kind=dp), dimension(: , : , : ), pointer : : coeffs logical : : paged integer : : page_unit ! Is the wavefn paged to disc? ! Iff paged: ! the unit no. of the pagefile . . . end type wavefunction N. B. This has been simplified for illustrative purposes! Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 23
Example Operations: wavefunction_allocate(wvfn) wavefunction_deallocate(wvfn) wavefunction_initialise(wvfn, method) wavefunction_copy(wvfn 1, wvfn 2) wavefunction_add(wvfn 2, wvfn_out) wavefunction_dot(wvfn 1, wvfn 2, products) wavefunction_orthogonalise(wvfn) wavefunction_recip_to_real(wvfn, nb, nk, ns, real_bnd) Overloading: wavefunction_add(wvfn 1, wvfn 2, wvfn_out, c 1, c 2) wavefunction_add(bnd, wvfn, nb, nk, ns) Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 24
Functional Modules Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 25
Use of Fundamental Building Blocks (e. g. Calculating H ) ! Apply kinetic energy operator to wvfn call wave_kinetic_energy(wvfn, ek, H_wvfn) ! Calculate the charge density call density_calculate(wvfn, occ, dens) ! Calculate the local potential call locpot_calculate(dens, local_pot) ! Apply the local potential to the wavefunction call pot_apply(local_pot, wvfn_temp) ! Add Vloc|psi> to kinetic energy contribution call wave_add(wvfn_temp, H_wvfn) ! Apply the non-local potential to the wavefunction call nlpot_apply(wvfn, …, wvfn_temp) ! Add Vnl|psi> to get final H|psi> call wave_add(wvfn_temp, H_wvfn) Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 26
Coding Style r Clear code l l l r Meaningful variable and subroutine names Lots of comments Good structure Care with performance issues l l Some features of FORTRAN 90 sub-optimal Use BLAS/LAPACK where applicable Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 27
Example problem with F 90 ! Finding the trace of a sub-array real, dimension(N, N) : : A ! Pass a sub-array of A of dimension m tr = bad_trace(A(1: m, 1: m), m) !Pass the whole array with dimension of sub-array tr = good_trace(A, m, N) Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 28
Timings for bad_trace Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 29
Timings for good_trace Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 30
The Future of New CASTEP NPT Molecular Dynamics r Free-energy integration for reaction barriers r New non-local XC functionals r NMR chemical shifts r EELS r Raman spectroscopy r Self-consistent pseudopotentials r Etc… r Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 31
Summary New CASTEP code designed and implemented by an academic group r Sound software design r Modern implementation r State-of-the-art features r Good performance r The future is bright! r Nuts and Bolts 2001 Lecture 4: Introduction to New CASTEP� 32
- Slides: 32