zerothi / sisl

Electronic structure Python package for post analysis and large scale tight-binding DFT/NEGF calculations
https://zerothi.github.io/sisl
Mozilla Public License 2.0
181 stars 58 forks source link

tutorial 09: KeyError: Right #83

Closed mbarbry closed 5 years ago

mbarbry commented 5 years ago

Hi,

I'm new in sisl, tbtrans and transiesta. I'm following the tutorials from https://github.com/zerothi/ts-tbt-sisl-tutorial/

In the tutorial 9, everythings works fine until the end to get the current.

I[i] = sisl.get_sile('TBT_{:.1f}/siesta.TBT.nc'.format(v)).current()

I get the following error,

sisl/io/sile.pyc in _variables(n, name, tree)
    777                 g = g.groups[t]
    778         else:
--> 779             g = g.groups[tree]
    780 
    781         return g.variables[name]

KeyError: u'Right'

effectively, printing the dictionary g, I get,

OrderedDict([(u'Left', <type 'netCDF4._netCDF4.Group'>
group /Left:
    dimensions(sizes): 
    variables(dimensions): float64 mu(one), float64 kT(one), float32 Right.T(nkpt,ne)
    groups: 
)])
OrderedDict([(u'Left', <type 'netCDF4._netCDF4.Group'>
group /Left:
    dimensions(sizes): 
    variables(dimensions): float64 mu(one), float64 kT(one), float32 Right.T(nkpt,ne)
    groups: 
)])
OrderedDict([(u'Left', <type 'netCDF4._netCDF4.Group'>
 group /Left:
    dimensions(sizes): 
    variables(dimensions): float64 mu(one), float64 kT(one), float32 Right.T(nkpt,ne)
    groups: 
 )])
 OrderedDict([(u'Left', <type 'netCDF4._netCDF4.Group'>
 group /Left:
     dimensions(sizes): 
     variables(dimensions): float64 mu(one), float64 kT(one), float32 Right.T(nkpt,ne)
     groups: 
 )])

the key Right is clearly missing. Do you have an idea of what I did wrong?

zerothi commented 5 years ago

Could you try and add this:

print(sisl.get_sile('TBT_{:.1f}/siesta.TBT.nc'.format(v)).elecs)
print(sisl.get_sile('TBT_{:.1f}/siesta.TBT.nc'.format(v))._elec(0))
print(sisl.get_sile('TBT_{:.1f}/siesta.TBT.nc'.format(v))._elec(1))

and give me the output?

mbarbry commented 5 years ago

The prints seem to give the expected values

print(sisl.get_sile('TBT_{:.1f}/siesta.TBT.nc'.format(v)).elecs)
['Left', 'Right']

print(sisl.get_sile('TBT_{:.1f}/siesta.TBT.nc'.format(v))._elec(0))
Left

print(sisl.get_sile('TBT_{:.1f}/siesta.TBT.nc'.format(v))._elec(1))
Right

But I still get the same error when calculating the current.

zerothi commented 5 years ago

Could you print print(sisl.__version__)

zerothi commented 5 years ago

Also do you have a full stacktrace of the error?

mbarbry commented 5 years ago

the sisl version I'm using is 0.9.4

the full error is


KeyError Traceback (most recent call last)

in 3 I = np.empty([len(V)]) 4 for i, v in enumerate(V): ----> 5 I[i] = sisl.get_sile('TBT_{:.1f}/siesta.TBT.nc'.format(v)).current() 6 plt.plot(V, I * 1e6); 7 plt.xlabel('Bias [V]'); plt.ylabel(r'Current [$\mu\mathrm{A}$]'); /usr/local/lib/python3.6/dist-packages/sisl/io/tbtrans/tbt.py in current(self, elec_from, elec_to, kavg) 644 mu_f = self.chemical_potential(elec_from) 645 kt_f = self.kT(elec_from) --> 646 mu_t = self.chemical_potential(elec_to) 647 kt_t = self.kT(elec_to) 648 return self.current_parameter(elec_from, mu_f, kt_f, /usr/local/lib/python3.6/dist-packages/sisl/io/tbtrans/tbt.py in chemical_potential(self, elec) 229 def chemical_potential(self, elec): 230 """ Return the chemical potential associated with the electrode `elec` """ --> 231 return self._value('mu', self._elec(elec))[0] * Ry2eV 232 mu = chemical_potential 233 /usr/local/lib/python3.6/dist-packages/sisl/io/sile.py in _value(self, name, tree) 746 This method returns the value of the variable. 747 """ --> 748 return self._variable(name, tree)[:] 749 750 @staticmethod /usr/local/lib/python3.6/dist-packages/sisl/io/sile.py in _variable(self, name, tree) 739 if name in self._data: 740 return self._data[name] --> 741 return self._variables(self, name, tree=tree) 742 743 def _value(self, name, tree=None): /usr/local/lib/python3.6/dist-packages/sisl/io/sile.py in _variables(n, name, tree) 759 g = g.groups[t] 760 else: --> 761 g = g.groups[tree] 762 763 return g.variables[name] KeyError: 'Right'
mbarbry commented 5 years ago

I installed sisl using pip

zerothi commented 5 years ago

Ah, yes, this is because the latest sisl version requires the coming 4.1-b4 which adds this information. So nothing is wrong ;)

zerothi commented 5 years ago

I am gonna close this issue. Thanks for reporting.

mbarbry commented 5 years ago

Works fine with the development version of Siesta, thanks!