### Use print as a function

parent 043bc0eb
 ... ... @@ -48,7 +48,7 @@ Common sources of bugs return a x = np.ones(5) print double(x) # x[:] is now 2. print(double(x)) # x[:] is now 2. - Forgetting a n += 1 statement in a for loop:: ... ...
 ... ... @@ -7,7 +7,7 @@ Debugging Python debugging ================ Even though some debugging can done just with print statements, a real Even though some debugging can done just with the print function, a real debugger offers several advantages. It is possible, for example, to set breakpoints in certain files or functions, execute the code step by step, examine and change values of variables. Python contains a standard debugger ... ...
 ... ... @@ -8,9 +8,9 @@ Delta Self-Consistent Field Linear expansion Delta Self-Consistent Field -------------------------------------------- The method of linear expansion Delta Self-Consistent Field \ [#delscf]_ adds the density of a specified orbital \varphi_a(r) to the total density in each step of the self-consistency cycle. The extra charge The method of linear expansion Delta Self-Consistent Field \ [#delscf]_ adds the density of a specified orbital \varphi_a(r) to the total density in each step of the self-consistency cycle. The extra charge is usually taken from the fermi level to keep the system neutral: .. math:: ... ... @@ -18,12 +18,12 @@ is usually taken from the fermi level to keep the system neutral: n(r) = \sum_nf_{N-1}(T,\varepsilon_n)|\varphi_n(r)|^2 + |\varphi_a(r)|^2. with N being the total number of electrons and f_{N-1}(T,\varepsilon_n) is the Fermi-Dirac distribution of the N-1 electron system . To get the is the Fermi-Dirac distribution of the N-1 electron system . To get the band energy right \varphi_a(r) needs to be expanded in Kohn-Sham orbitals: .. math:: |\varphi_a\rangle = \sum_nc_{na}|\varphi_n\rangle, |\varphi_a\rangle = \sum_nc_{na}|\varphi_n\rangle, \qquad c_{na} = \langle\varphi_n|\varphi_a\rangle and the band energy of the orbital becomes ... ... @@ -33,23 +33,23 @@ and the band energy of the orbital becomes \varepsilon_a = \sum_n|c_{na}|^2\varepsilon_n. The method is a generalization of traditional Delta Self-Consistent Field where only the occupation numbers are modified and it will reduce to that, where only the occupation numbers are modified and it will reduce to that, if only one (normalized) term is included in the expansion of \varphi_a(r). ---------------- Simple molecules ---------------- The example below calculates the excitation energy of the 5\sigma\rightarrow2\pi transition in CO. We only specify that the 2\pi orbital should be occupied ([[1.0, lumo, 1]] means 1.0 electrons in lumo with spin 1) and the method will take the electron from highest The example below calculates the excitation energy of the 5\sigma\rightarrow2\pi transition in CO. We only specify that the 2\pi orbital should be occupied ([[1.0, lumo, 1]] means 1.0 electrons in lumo with spin 1) and the method will take the electron from highest occupied orbital which in this case is 5\sigma. The lumo is an instance of the class AEOrbital which calculates the The lumo is an instance of the class AEOrbital which calculates the expansion of the saved 2\pi state in each iteration step. In order to obtain the all-electron overlaps \langle\varphi_n|2\pi\rangle we need to supply the projector overlaps in addition to the In order to obtain the all-electron overlaps \langle\varphi_n|2\pi\rangle we need to supply the projector overlaps in addition to the pseudowavefunction. Exciting the LUMO in CO:: ... ... @@ -98,54 +98,54 @@ Exciting the LUMO in CO:: E_es = CO.get_potential_energy() print 'Excitation energy: ', E_es-E_gs print('Excitation energy: ', E_es - E_gs) The commented line lumo = dscf.Molecular... uses another class to specify the 2\pi orbital of CO which does not require a ground state calculation of the molecule. In the simple example above the two methods give identical results, but for more complicated systems the AEOrbital class should be used \ [#des]_. When using the AEOrbital class The commented line lumo = dscf.Molecular... uses another class to specify the 2\pi orbital of CO which does not require a ground state calculation of the molecule. In the simple example above the two methods give identical results, but for more complicated systems the AEOrbital class should be used \ [#des]_. When using the AEOrbital class a new calculator object must be constructed for the dscf calculation. In the example above we only specify a single state, but the function dscf.dscf_calculation takes a list of orbitals as input and we could for example have given the argument [[1.0, lumo, 1], [-1.0, pi, 0]] which would force the electron to be taken from the \pi orbital with spin 0. The pi In the example above we only specify a single state, but the function dscf.dscf_calculation takes a list of orbitals as input and we could for example have given the argument [[1.0, lumo, 1], [-1.0, pi, 0]] which would force the electron to be taken from the \pi orbital with spin 0. The pi should of course be another instance of the AEOrbital class. --------------------- Exciting an adsorbate --------------------- The method of linear expansion Delta Self-Consistent Field was designed for calculations with strongly hybridized orbitals. For example molecules chemisorbed on transition metals. In such cases the for calculations with strongly hybridized orbitals. For example molecules chemisorbed on transition metals. In such cases the traditional Delta Self-Consistent Field breaks down since the orbital to be occupied is no longer well described by a single Kohn-Sham state. The script :git:~doc/documentation/dscf/homo.py calculates The script :git:~doc/documentation/dscf/homo.py calculates the HOMO energy of CO adsorbed on-top Pt(111). The script starts from scratch, but usually one would start from an optimized configuration saved in a file gs.gpw. The script only calculates the total energy of the excited state so the excitation energy is obtained as the difference saved in a file gs.gpw. The script only calculates the total energy of the excited state so the excitation energy is obtained as the difference between ground and excited state energies. First a calculation of gas-phase CO is performed and the HOMO pseudo-wavefunctions and the projector overlaps are saved. The First a calculation of gas-phase CO is performed and the HOMO pseudo-wavefunctions and the projector overlaps are saved. The energy range [-100.0, 0.0] means we only include states below the Fermi level (default is states above). The script :git:~doc/documentation/dscf/lumo.py calculates the LUMO energy of the same system, but is slightly more complicated due to the degeneracy of the 2\pi orbital. We would like to occupy the 2\pi_y orbital and we need to figure out which band (5 or 6) this orbital the LUMO energy of the same system, but is slightly more complicated due to the degeneracy of the 2\pi orbital. We would like to occupy the 2\pi_y orbital and we need to figure out which band (5 or 6) this orbital corresponds to in each k-point before we start the slab calculation. .. [#delscf] J. Gavnholt, T. Olsen, M. Engelund and J. Schiøtz, Delta Self-Consistent Field as a method to obtain potential energy surfaces of excited molecules on surfaces, energy surfaces of excited molecules on surfaces, *Phys. Rev. B* **78**, 075441 (2008) .. [#des] T. Olsen, J. Gavnholt and J. Schiøtz, Hot electron mediated desorption rates calculated from excited state potential energy surfaces, state potential energy surfaces, *Phys. Rev. B* **79**, 035403 (2009)
 ... ... @@ -1029,7 +1029,7 @@ at a later time, this can be done as follows: >>> from gpaw import * >>> atoms, calc = restart('H2.gpw') >>> print atoms.get_potential_energy() >>> print(atoms.get_potential_energy()) Everything will be just as before we wrote the :file:H2.gpw file. Often, one wants to restart the calculation with one or two parameters ... ... @@ -1037,14 +1037,14 @@ changed slightly. This is very simple to do. Suppose you want to change the number of grid points: >>> atoms, calc = restart('H2.gpw', gpts=(20, 20, 20)) >>> print atoms.get_potential_energy() >>> print(atoms.get_potential_energy()) .. tip:: There is an alternative way to do this, that can be handy sometimes: >>> atoms, calc = restart('H2.gpw') >>> calc.set(gpts=(20, 20, 20)) >>> print atoms.get_potential_energy() >>> print(atoms.get_potential_energy()) More details can be found on the :ref:restart_files page. ... ...
 ... ... @@ -67,7 +67,7 @@ makes thing available. Lets try an example: * and in file :file:program.py, put:: from stuff import constant, function print 'result =', function(constant) print('result =', function(constant)) * Now run the script :file:program.py and watch the output. ... ...
 ... ... @@ -4,14 +4,14 @@ Electron transport ================== This exercise shows how to use the ase transport module for performing This exercise shows how to use the ase transport module for performing electron transport calculations in nanoscale contacts. :class:~ase.transport.calculators.TransportCalculator is used to calculate transmission functions at two different levels, namely: * Tight-binding (TB) description: parametrize the system using tight-binding model. tight-binding model. * DFT description: extract realistic description of the system using the GPAW DFT-LCAO mode. ... ... @@ -70,7 +70,7 @@ neighbor hopping energy of -1, and second nearest neighbor hopping of [-1. , 0. , -1. , 0.2], [ 0.2, -1. , 0. , -1. ], [ 0. , 0.2, -1. , 0. ]]) Next, the Hamiltonian for the scattering region should be constructed. Assuming the Hydrogen molecule can be described by the Hamiltonian: ... ... @@ -86,7 +86,7 @@ hopping energy of 0.2: Write down the explicit scattering Hamiltonian (it is a 6 \times 6 matrix). You are now ready to initialize the TransportCalculator:: from ase.transport.calculators import TransportCalculator tcalc = TransportCalculator(h=H_scat, # Scattering Hamiltonian ... ... @@ -108,7 +108,7 @@ can be calculated using:: tcalc.set(pdos=[0, 1]) pdos_ne = tcalc.get_pdos() Note that all indices in TransportCalculator refers to the scattering region minus the mandatory principal layer on each side. Why do you think the pdos of each the hydrogen TB sites has two peaks? ... ... @@ -125,7 +125,7 @@ again. What happpened? You can try to remove the coupling to the bonding state and calculate the calculate the transmission function:: tcalc.cutcupling_bfs() T_cut_bonding_e = tcalc.get_transmission() ... ... @@ -152,7 +152,7 @@ this :download:pt_h2_lcao_manual.py: .. literalinclude:: pt_h2_lcao_manual.py You should now have the files scat_hs.pickle, lead1_hs.pickle and lead2_hs.pickle in your directory. lead2_hs.pickle in your directory. You are now ready to initialize the TransportCalculator: The script can be found here: ... ... @@ -161,7 +161,7 @@ Below we will work through the script. The pickle files can be loaded and used in the TransportCalculator:: from ase.transport.calculators import TransportCalculator import pickle ... ... @@ -177,10 +177,10 @@ the TransportCalculator:: In SZP there are 4 basis functions per H atom, and 9 per Pt atom. Does the size of the different matrices match your expectations? What is the conductance? Does it agree with the experimental value? We will now try to investigate transport properties in more detail. Try to subdiagonalize the molecular subspace:: Pt_N = 5 Pt_nbf = 9 # number of bf per Pt atom (basis=szp) H_nbf = 4 # number of bf per H atom (basis=szp) ... ... @@ -188,10 +188,10 @@ Try to subdiagonalize the molecular subspace:: bfs = range(bf_H1, bf_H1 + 2 * H_nbf) h_rot, s_rot, eps_n, vec_jn = tcalc.subdiagonalize_bfs(bfs) for n in range(len(eps_n)): print 'bf %i correpsonds to the eigenvalue %.2f eV' % (bfs[n],eps_n[n]) print('bf %i correpsonds to the eigenvalue %.2f eV' % (bfs[n],eps_n[n])) Argue that vec_jn[:,0] and vec_jn[:,1] corresponds to the bonding and anti-bonding molecular hydrogen orbitals, respectively. Argue that vec_jn[:,0] and vec_jn[:,1] corresponds to the bonding and anti-bonding molecular hydrogen orbitals, respectively. What is the calculated band-gap of the hydrogen-molecule? ... ...
 ... ... @@ -191,7 +191,7 @@ Test python/numpy:: from numpy.core.multiarray import dot b = numpy.ones(13, numpy.complex) d = dot(b, b) print 'Hello' print('Hello') numpy.test() EOF ... ...
 ... ... @@ -23,7 +23,7 @@ Setup the root directory:: mkdir -p ${APPHOME} cd${APPHOME} export GPAW_PLATFORM=python -c "from distutils import util, sysconfig; print util.get_platform()+'-'+sysconfig.get_python_version()" export GPAW_PLATFORM=python -c "from distutils import util, sysconfig; print(util.get_platform()+'-'+sysconfig.get_python_version())" Download software:: ... ...
 ... ... @@ -24,7 +24,7 @@ Setup the root directory:: mkdir -p ${HOMESOFTS} cd${HOMESOFTS} setenv GPAW_PLATFORM python -c "from distutils import util, sysconfig; print util.get_platform()+'-'+sysconfig.get_python_version()" setenv GPAW_PLATFORM python -c "from distutils import util, sysconfig; print(util.get_platform()+'-'+sysconfig.get_python_version())" Set the versions:: ... ... @@ -39,7 +39,7 @@ Set the versions:: set ase=3.5.1.2175 set gpaw=0.8.0.8092 set setups=0.8.7929 and create startup scripts:: cat < ${HOMESOFTS}/acml-${acml}-1.cshrc ... ...
 ... ... @@ -27,13 +27,13 @@ Set the versions:: export ase=3.5.1.2175 export gpaw=0.8.0.8092 export setups=0.8.7929 and create sh startup script:: cat < ${HOME}/opt/campos.sh #!/bin/sh # export GPAW_PLATFORM=python -c "from distutils import util, sysconfig; print util.get_platform()+'-'+sysconfig.get_python_version()" export GPAW_PLATFORM=python -c "from distutils import util, sysconfig; print(util.get_platform()+'-'+sysconfig.get_python_version())" # export LD_LIBRARY_PATH=\${HOME}/opt/acml-${acml}/gfortran64/lib:\${LD_LIBRARY_PATH} export LD_LIBRARY_PATH=\${HOME}/opt/CBLAS.acml-${acml}/lib:\\${LD_LIBRARY_PATH} # if cblas used ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment