[gpaw-developers] [gpaw-svncheckins] [svn commit /var/www/svn/gpaw] r12125 - trunk/gpaw/pes

Tristan Maxson tgmaxson at gmail.com
Thu Oct 16 13:42:37 CEST 2014


Sorry,  I didn't review my code well enough to realize it would encounter
minor problems if people were inconsistent with spacing.  Here is the
revised code.

...

    def fix_e225(self, result):
        """Fix missing whitespace around operator."""
        target = self.source[result['line'] - 1]
        offset = result['column'] - 1
        #Ignore "**", tgmaxson at gmail.com
        if target[offset:offset+2] == '**' and result['id'] == "E226":
            return []
        if target[offset-2:offset] == '**' and result['id'] == "E225":
            return []
        fixed = target[:offset] + ' ' + target[offset:]

...

I put in a pull request for autopep8 so hopefully this gets fixed with my
patch,  or they decide to do something more elegant if possible.  For now
this should work for local copies.

https://github.com/tgmaxson/autopep8

Thanks Again,
Tristan Maxson


On Thu, Oct 16, 2014 at 7:21 AM, Tristan Maxson <tgmaxson at gmail.com> wrote:

> Well this was quite simple.  I have changed the fix_e225(self, result)
> function as follows.
>
>     def fix_e225(self, result):
>         """Fix missing whitespace around operator."""
>         target = self.source[result['line'] - 1]
>         offset = result['column'] - 1
>         #Ignore "**", tgmaxson at gmail.com
>         if target[offset:offset+2] == "**":
>          return []
>         fixed = target[:offset] + ' ' + target[offset:]
>
> I didn't save a copy of it beforehand so I don't have a .diff patch,  but
> its a matter of adding 2 lines of code (I have it marked off in case others
> see it locally,  but you can leave the comment out obviously.) so it should
> be doable quite easily.
>
> Tell me if you encounter any problems and I will work through them.
>
> Best,
> Tristan Maxson
>
> On Thu, Oct 16, 2014 at 6:37 AM, Tristan Maxson <tgmaxson at gmail.com>
> wrote:
>
>> I am also familiar with this tool and this quirk.  Maybe it is worth
>> seeing if I can make a patch to fix this behavior?  I will look into it in
>> a minute.
>>
>> Tristan Maxson
>>
>> On Thu, Oct 16, 2014 at 6:07 AM, Michael Walter <
>> Michael.Walter at fmf.uni-freiburg.de> wrote:
>>
>>> Hi Jens,
>>>
>>> as I wrote, I've used autopep8 (https://pypi.python.org/pypi/autopep8)
>>> to do it. I agree with you that a**2 looks better than a ** 2.
>>>
>>> It's nicer to use an automatic tool to do it, however. Maybe one can
>>> teach 'autopep8' to do this. Otherwise pep8 work is mostly tedious, and I
>>> would opt to accept the ugly a ** 2.
>>>
>>> Best,
>>> Michael
>>>
>>> 2014-10-16 11:37 GMT+02:00 <svn at mail.fysik.dtu.dk>:
>>>
>>>> Author: miwalter
>>>> Date: 2014-10-16 11:37:54 +0200 (Thu, 16 Oct 2014)
>>>> New Revision: 12125
>>>>
>>>> Modified:
>>>>    trunk/gpaw/pes/__init__.py
>>>>    trunk/gpaw/pes/continuum.py
>>>>    trunk/gpaw/pes/dos.py
>>>>    trunk/gpaw/pes/ds_beta.py
>>>>    trunk/gpaw/pes/state.py
>>>>    trunk/gpaw/pes/tddft.py
>>>> Log:
>>>> autopep8 corrections
>>>>
>>>> Modified: trunk/gpaw/pes/__init__.py
>>>> ===================================================================
>>>> --- trunk/gpaw/pes/__init__.py  2014-10-16 09:33:03 UTC (rev 12124)
>>>> +++ trunk/gpaw/pes/__init__.py  2014-10-16 09:37:54 UTC (rev 12125)
>>>> @@ -4,12 +4,13 @@
>>>>  from gpaw.lrtddft.spectrum import Writer
>>>>
>>>>  ds_prefactor = {
>>>> -    'Ang': Bohr**2,
>>>> +    'Ang': Bohr ** 2,
>>>>      'a.u.': 1.0,
>>>> -    'Mb': Bohr**2 * 100}
>>>> +    'Mb': Bohr ** 2 * 100}
>>>>
>>>>
>>>>  class PESpectrum(Writer):
>>>> +
>>>>      def __init__(self,
>>>>                   enlist,
>>>>                   folding='Gauss',
>>>> @@ -21,14 +22,15 @@
>>>>              self.fields += 'Spectroscopic factor'
>>>>          else:
>>>>              self.fields += 'Folded spectroscopic factor'
>>>> -
>>>> +
>>>>          self.energies = enlist[0]
>>>>          self.values = []
>>>>          for val in enlist[1]:
>>>>              self.values.append([val])
>>>>
>>>> -
>>>> +
>>>>  class BasePES:
>>>> +
>>>>      def save_folded_pes(self,
>>>>                          filename=None,
>>>>                          width=0.08,  # Gauss/Lorentz width
>>>>
>>>> Modified: trunk/gpaw/pes/continuum.py
>>>> ===================================================================
>>>> --- trunk/gpaw/pes/continuum.py 2014-10-16 09:33:03 UTC (rev 12124)
>>>> +++ trunk/gpaw/pes/continuum.py 2014-10-16 09:37:54 UTC (rev 12125)
>>>> @@ -10,7 +10,9 @@
>>>>
>>>>
>>>>  class PlaneWave(State):
>>>> +
>>>>      """Plane wave state."""
>>>> +
>>>>      def get_grid(self, k_c, r0=None):
>>>>          if r0 is None:
>>>>              r0_c = np.array([0., 0., 0.])
>>>> @@ -35,11 +37,12 @@
>>>>              _gpaw.plane_wave_grid(gd.beg_c, gd.end_c,
>>>>                                    gd.h_cv.diagonal().copy(),
>>>>                                    k_c, r0_c, pw_G)
>>>> -        pw_G /= (2 * pi)**(3. / 2.)
>>>> +        pw_G /= (2 * pi) ** (3. / 2.)
>>>>          return pw_G
>>>> -
>>>>
>>>> +
>>>>  class ZerothOrder1(State):
>>>> +
>>>>      def __init__(self, calculator):
>>>>          self.calculator = calculator
>>>>          State.__init__(self, calculator.gd)
>>>> @@ -83,6 +86,6 @@
>>>>
>>>>          corrt_G = self.gd.empty()
>>>>          self.poisson.solve(corrt_G, self.vt_G, charge=None)
>>>> -        corrt_G /= (2 * pi)**(5. / 2)
>>>> +        corrt_G /= (2 * pi) ** (5. / 2)
>>>>
>>>>          self.corrt_G = corrt_G
>>>>
>>>> Modified: trunk/gpaw/pes/dos.py
>>>> ===================================================================
>>>> --- trunk/gpaw/pes/dos.py       2014-10-16 09:33:03 UTC (rev 12124)
>>>> +++ trunk/gpaw/pes/dos.py       2014-10-16 09:37:54 UTC (rev 12125)
>>>> @@ -7,9 +7,11 @@
>>>>
>>>>
>>>>  class DOSPES(BasePES):
>>>> +
>>>>      """PES derived from density of states with shifted KS-energies.
>>>>
>>>>      """
>>>> +
>>>>      def __init__(self, mother, daughter=None, shift=False, vde=None,
>>>> f_min=0.1):
>>>>          self.c_m = mother
>>>>          self.c_d = daughter
>>>>
>>>> Modified: trunk/gpaw/pes/ds_beta.py
>>>> ===================================================================
>>>> --- trunk/gpaw/pes/ds_beta.py   2014-10-16 09:33:03 UTC (rev 12124)
>>>> +++ trunk/gpaw/pes/ds_beta.py   2014-10-16 09:37:54 UTC (rev 12125)
>>>> @@ -9,11 +9,12 @@
>>>>  from gpaw.pes.state import H1s
>>>>  from gpaw.pes.continuum import PlaneWave
>>>>
>>>> -#debug
>>>> -#from gpaw.mpi import rank
>>>> +# debug
>>>> +# from gpaw.mpi import rank
>>>>
>>>>
>>>>  class CrossSectionBeta:
>>>> +
>>>>      def __init__(self,
>>>>                   initial=None,
>>>>                   final=None,
>>>> @@ -44,7 +45,7 @@
>>>>
>>>>      def calculate(self, Ekin):
>>>>          """Calculate the necessary overlaps."""
>>>> -
>>>> +
>>>>          Ekin = Ekin / Hartree
>>>>          if self.Ekin == Ekin:
>>>>              return
>>>> @@ -52,15 +53,15 @@
>>>>
>>>>          # photoelectron momentum
>>>>          self.k = sqrt(2 * self.Ekin)
>>>> -
>>>> +
>>>>          for angle in ['x', 'phi', 'psi']:
>>>>              self.angle[angle] = self.gl[angle].get_x()[0]
>>>>          self.T20, self.T2m = self.gi_x()
>>>>
>>>>          # we need the average
>>>> -        self.T20 /= 8 * pi**2
>>>> -        self.T2m /= 8 * pi**2
>>>> -
>>>> +        self.T20 /= 8 * pi ** 2
>>>> +        self.T2m /= 8 * pi ** 2
>>>> +
>>>>      def get_omega(self):
>>>>          """Return the necessary photon energy."""
>>>>          return self.Ekin - self.initial.get_energy() / Hartree
>>>> @@ -97,14 +98,14 @@
>>>>  #        print "T2m:", T2mana, self.T2m
>>>>
>>>>          omega = self.get_omega()
>>>> -
>>>> +
>>>>          # integration over momentum agles
>>>>          pre *= self.k * 4 * pi
>>>>
>>>>  #        print omega, self.initial.get_ds(self.k, omega, self.form), \
>>>>  #            (self.k * 4 * pi * (2 * pi)**2 / 137.0359895 * self.T2m /
>>>> omega)
>>>>
>>>> -        return pre * ((2 * pi)**2 * alpha * self.T2m / omega)
>>>> +        return pre * ((2 * pi) ** 2 * alpha * self.T2m / omega)
>>>>
>>>>      def gauss_integrate(self, angle, function):
>>>>          T20 = 0.
>>>> @@ -135,7 +136,7 @@
>>>>
>>>>          # polarisation in the direction of vk
>>>>          costh = self.angle['x']
>>>> -        sinth = sqrt(1. - costh**2)
>>>> +        sinth = sqrt(1. - costh ** 2)
>>>>          sinphi = sin(self.angle['phi'])
>>>>          cosphi = cos(self.angle['phi'])
>>>>          eps0 = np.array([sinth * cosphi,
>>>> @@ -199,7 +200,7 @@
>>>>              me = me_c[0].imag
>>>>
>>>>              def ds(me):
>>>> -                return self.k / omega * me**2
>>>> +                return self.k / omega * me ** 2
>>>>
>>>>              print(omega, ds(me_analyt), ds(me), me_analyt, me)
>>>>  #        print 'analyt', self.initial.get_me_c(vk, self.form)
>>>>
>>>> Modified: trunk/gpaw/pes/state.py
>>>> ===================================================================
>>>> --- trunk/gpaw/pes/state.py     2014-10-16 09:33:03 UTC (rev 12124)
>>>> +++ trunk/gpaw/pes/state.py     2014-10-16 09:37:54 UTC (rev 12125)
>>>> @@ -6,8 +6,11 @@
>>>>  import _gpaw
>>>>  from gpaw.pes import ds_prefactor
>>>>
>>>> +
>>>>  class State:
>>>> +
>>>>      """Electronic state base class."""
>>>> +
>>>>      def __init__(self, gd):
>>>>          self.gd = gd
>>>>          self.r_c = []
>>>> @@ -31,9 +34,12 @@
>>>>          """Set the states energy in [eV]"""
>>>>          self.energy = energy / Hartree
>>>>
>>>> +
>>>>  class BoundState(State):
>>>> +
>>>>      """Bound state originating from a gpaw calculation."""
>>>> -    def __init__(self,
>>>> +
>>>> +    def __init__(self,
>>>>                   calculator,
>>>>                   s, n):
>>>>          self.gd = calculator.wfs.gd
>>>> @@ -41,15 +47,18 @@
>>>>          self.grid_g = self.kpt.psit_nG[n]
>>>>          self.energy = self.kpt.eps_n[n]
>>>>
>>>> +
>>>>  class H1s(State):
>>>> +
>>>>      """Analytic H1s state."""
>>>> +
>>>>      def __init__(self, gd=None, center=None, Z=1):
>>>>          if center is None:
>>>>              center = 0.5 * gd.n_c * gd.h_c
>>>>          else:
>>>>              self.center = center / Bohr
>>>>          self.Z = Z
>>>> -        self.energy = - Z**2 / 2.
>>>> +        self.energy = - Z ** 2 / 2.
>>>>          if gd is not None:
>>>>              self.grid_g = None
>>>>              State.__init__(self, gd)
>>>> @@ -61,17 +70,17 @@
>>>>              wf = gd.zeros(dtype=float)
>>>>              vr0 = np.array([0., 0., 0.])
>>>>              for i in range(gd.n_c[0]):
>>>> -                vr0[0] = (gd.beg_c[0] + i) * gd.h_cv[0,0]
>>>> +                vr0[0] = (gd.beg_c[0] + i) * gd.h_cv[0, 0]
>>>>                  for j in range(gd.n_c[1]):
>>>> -                    vr0[1] = (gd.beg_c[1] + j) * gd.h_cv[1,1]
>>>> +                    vr0[1] = (gd.beg_c[1] + j) * gd.h_cv[1, 1]
>>>>                      for k in range(gd.n_c[2]):
>>>> -                        vr0[2] = (gd.beg_c[2] + k) * gd.h_cv[2,2]
>>>> +                        vr0[2] = (gd.beg_c[2] + k) * gd.h_cv[2, 2]
>>>>                          vr = vr0 - self.center
>>>>                          r = sqrt(np.dot(vr, vr))
>>>>                          wf[i, j, k] = exp(-self.Z * r)
>>>> -            self.grid_g = wf * sqrt(self.Z**3 / pi)
>>>> +            self.grid_g = wf * sqrt(self.Z ** 3 / pi)
>>>>          return self.grid_g
>>>> -
>>>> +
>>>>      def get_me_c(self, k_c, form='L'):
>>>>          """Transition matrix element."""
>>>>          k = sqrt(np.dot(k_c, k_c))
>>>> @@ -81,7 +90,7 @@
>>>>              pre = 1j
>>>>          else:
>>>>              raise NonImplementedError
>>>> -        return  pre * k_c * self.FT(k)
>>>> +        return pre * k_c * self.FT(k)
>>>>
>>>>      def get_ds(self, Ekin, form='L', units='Mb'):
>>>>          """Angular averaged cross section.
>>>> @@ -94,7 +103,7 @@
>>>>          me_c = self.get_me_c(k_c, form)
>>>>          T2 = np.abs(np.dot(me_c, me_c)) / 3.
>>>>          pre = ds_prefactor[units]
>>>> -        return pre * (2 * pi)**2 * alpha * k * 4 * pi / omega * T2
>>>> -
>>>> +        return pre * (2 * pi) ** 2 * alpha * k * 4 * pi / omega * T2
>>>> +
>>>>      def FT(self, k):
>>>> -        return sqrt(8 * self.Z**5) / pi / (k**2 + self.Z**2)**2
>>>> +        return sqrt(8 * self.Z ** 5) / pi / (k ** 2 + self.Z ** 2) ** 2
>>>>
>>>> Modified: trunk/gpaw/pes/tddft.py
>>>> ===================================================================
>>>> --- trunk/gpaw/pes/tddft.py     2014-10-16 09:33:03 UTC (rev 12124)
>>>> +++ trunk/gpaw/pes/tddft.py     2014-10-16 09:37:54 UTC (rev 12125)
>>>> @@ -13,13 +13,14 @@
>>>>
>>>>
>>>>  class TDDFTPES(BasePES):
>>>> +
>>>>      def __init__(self, mother, excited_daughter, daughter=None,
>>>>                   shift=True, tolerance={}):
>>>>          self.tolerance = {
>>>>              'occupation': 1.e-10,
>>>>              'magnetic': 1.e-10,
>>>>              'grid': 0,
>>>> -            }
>>>> +        }
>>>>          for key in tolerance.keys():
>>>>              if not key in self.tolerance:
>>>>                  raise RuntimeError("Tolerance key '%s' not known."
>>>> @@ -34,14 +35,14 @@
>>>>          self.c_m = mother
>>>>          self.gd = self.c_m.wfs.gd
>>>>          self.lr_d = excited_daughter
>>>> -
>>>> +
>>>>          self.c_m.converge_wave_functions()
>>>>          self.c_d.converge_wave_functions()
>>>>          self.lr_d.diagonalize()
>>>> -
>>>> +
>>>>          self.check_systems()
>>>>          self.lr_d.jend = self.lr_d.kss[-1].j
>>>> -
>>>> +
>>>>          # Make good way for initialising these
>>>>
>>>>          kmax = 0
>>>> @@ -79,13 +80,13 @@
>>>>                                 (len(self.gs_m), len(self.gs_d)))
>>>>
>>>>      def _calculate(self):
>>>> -
>>>> +
>>>>          self.ks_overlaps()
>>>>          self.single_overlaps()
>>>>          self.full_overlap_matrix()
>>>>
>>>>          self._create_f()
>>>> -
>>>> +
>>>>      def ks_overlaps(self):
>>>>          """Evaluate KS overlaps of mother and daughter."""
>>>>          bands_m = self.c_m.get_number_of_bands()
>>>> @@ -101,10 +102,10 @@
>>>>
>>>>                  for j_d in range(bands_d):
>>>>                      k_d = spin_d * s_m
>>>> -
>>>> +
>>>>                      wf_d = self.c_d.wfs.kpt_u[k_d].psit_nG[j_d]
>>>>                      me = self.gd.integrate(wf_m * wf_d)
>>>> -
>>>> +
>>>>                      i = s_m * bands_m + i_m
>>>>                      j = s_m * bands_d + j_d
>>>>                      self.overlap[i, j] = me + self._nuc_corr(i_m, j_d,
>>>> @@ -153,8 +154,8 @@
>>>>                  for row in range(len(keep_row)):
>>>>                      d_i00[row, col] = self.overlap[keep_row[row],
>>>>                                                     keep_col[col]]
>>>> -
>>>> -            g0[i] = (-1)**(self.imax + i) * np.linalg.det(d_i00)
>>>> +
>>>> +            g0[i] = (-1) ** (self.imax + i) * np.linalg.det(d_i00)
>>>>          return g0
>>>>
>>>>      def full_overlap_matrix(self):
>>>> @@ -169,7 +170,7 @@
>>>>                  gi = 0
>>>>                  for kl in range(len(self.lr_d)):
>>>>                      gi += self.lr_d[I].f[kl] * self.singles[i, kl]
>>>> -                self.g_Ii[1 + I, i] = (-1.)**(self.imax + i) * gi
>>>> +                self.g_Ii[1 + I, i] = (-1.) ** (self.imax + i) * gi
>>>>
>>>>      def _create_f(self):
>>>>          self.f = (self.g_Ii * self.g_Ii).sum(axis=1)
>>>> @@ -179,19 +180,19 @@
>>>>                       self.c_m.get_potential_energy())
>>>>          else:
>>>>              shift = float(self.shift)
>>>> -
>>>> +
>>>>          self.be = (np.array([0] + list(self.lr_d.get_energies() *
>>>> Hartree)) +
>>>>                     shift)
>>>>
>>>>      def _nuc_corr(self, i_m, j_d, k_m, k_d):
>>>>          ma = 0
>>>> -
>>>> +
>>>>          for a, P_ni_m in self.c_m.wfs.kpt_u[k_m].P_ani.items():
>>>>              P_ni_d = self.c_d.wfs.kpt_u[k_d].P_ani[a]
>>>>              Pi_i = P_ni_m[i_m]
>>>>              Pj_i = P_ni_d[j_d]
>>>>              Delta_pL = self.c_m.wfs.setups[a].Delta_pL
>>>> -
>>>> +
>>>>              for i in range(len(Pi_i)):
>>>>                  for j in range(len(Pj_i)):
>>>>                      pij = Pi_i[i] * Pj_i[j]
>>>> @@ -200,7 +201,7 @@
>>>>
>>>>          self.gd.comm.sum(ma)
>>>>          return sqrt(4 * pi) * ma
>>>> -
>>>> +
>>>>      def check_systems(self):
>>>>          """Check that mother and daughter systems correspond to each
>>>> other.
>>>>
>>>> @@ -238,7 +239,7 @@
>>>>                  i -= nbands * int(i >= nbands)
>>>>                  morbitals_ig.append(self.c_m.wfs.kpt_u[k].psit_nG[i])
>>>>              self.morbitals_ig = np.array(morbitals_ig)
>>>> -
>>>> +
>>>>          dyson = State(self.gd)
>>>>          gridnn = self.gd.zeros()
>>>>          for i, g in enumerate(self.g_Ii[I]):
>>>>
>>>> _______________________________________________
>>>> gpaw-svncheckins mailing list
>>>> gpaw-svncheckins at listserv.fysik.dtu.dk
>>>> https://listserv.fysik.dtu.dk/mailman/listinfo/gpaw-svncheckins
>>>>
>>>
>>>
>>>
>>> --
>>> ------------------------------------------
>>> PD Dr Michael Walter
>>> Addresses:
>>> - Fraunhofer IWM, Wöhlerstrasse 11, D-79108 Freiburg i. Br., Germany
>>>   Tel.: +49 761 5142 296
>>> - Freiburg Materials Research Center, Stefan-Meier-Str. 21, D-79104
>>> Freiburg, Germany
>>>   Tel: +49 761 203 4758
>>> email: Michael.Walter at fmf.uni-freiburg.de
>>> www: http://omnibus.uni-freiburg.de/~mw767
>>> publications:
>>> http://scholar.google.com/citations?user=vlmryKEAAAAJ&hl=en
>>>
>>> _______________________________________________
>>> gpaw-developers mailing list
>>> gpaw-developers at listserv.fysik.dtu.dk
>>> https://listserv.fysik.dtu.dk/mailman/listinfo/gpaw-developers
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.fysik.dtu.dk/pipermail/gpaw-developers/attachments/20141016/58b7bed7/attachment-0001.html>


More information about the gpaw-developers mailing list