Exemplo n.º 1
0
def read_hdf5(fid,
              variables=[
                  'geo_info', 'geo_spec_all', 'ao_spec', 'ao_spherical',
                  'mo_coeff_all', 'mo_energy_all', 'mo_occ_all', 'sym',
                  'index_list'
              ]):
    '''Reads all variables specified in :literal:`variables` from an HDF5 file
  created with :literal:`write_hdf5` and appends this data to the globals() of 
  this module. 
  '''

    from orbkit.output import hdf5_open, hdf52dict

    # Read HDF5 File
    display('Reading Hierarchical Data Format file (HDF5) File from %s' % fid)
    data_stored = []
    for HDF5_file in hdf5_open(fid, mode='r'):
        for i in variables:
            try:
                globals()[i] = hdf52dict(i, HDF5_file)
                data_stored.append(i)
                if i == 'sym':
                    s = dict(globals()[i])
                    globals()[i] = {}
                    for k, l in s.items():
                        globals()[i][k] = int(l)
            except KeyError:
                pass

    if not data_stored:
        raise IOError(
            'Could not find any data in `%s` for the selected `variables`.' %
            fid)

    display('\tFound: ' + ', '.join(data_stored))
Exemplo n.º 2
0
 def hdf5_read(self,fid='out.h5',group='/ci:0'):
   from orbkit.output import hdf5_open,hdf52dict
   for hdf5_file in hdf5_open(fid,mode='r'):
     for key in self.__dict__.keys():
       try:
         self.__dict__[key] = hdf52dict('%s/%s' % (group,key),hdf5_file)
       except KeyError:
         self.__dict__[key] = hdf5_file['%s' % group].attrs[key]
     self.__dict__['info'] = dict(self.__dict__['info'])