Use print as a function

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