def row_to_dict(self, row): if len(row) == 26: row = self._old2new(row) dct = { 'id': row[0], 'unique_id': row[1], 'ctime': row[2], 'mtime': row[3], 'user': row[4], 'numbers': deblob(row[5], np.int32), 'positions': deblob(row[6], shape=(-1, 3)), 'cell': deblob(row[7], shape=(3, 3)), 'pbc': (row[8] & np.array([1, 2, 4])).astype(bool) } if row[9] is not None: dct['initial_magmoms'] = deblob(row[9]) if row[10] is not None: dct['initial_charges'] = deblob(row[10]) if row[11] is not None: dct['masses'] = deblob(row[11]) if row[12] is not None: dct['tags'] = deblob(row[12], np.int32) if row[13] is not None: dct['momenta'] = deblob(row[13], shape=(-1, 3)) if row[14] is not None: dct['constraints'] = decode(row[14]) if row[15] is not None: dct['calculator'] = row[15] dct['calculator_parameters'] = decode(row[16]) if row[17] is not None: dct['energy'] = row[17] if row[18] is not None: dct['free_energy'] = row[18] if row[19] is not None: dct['forces'] = deblob(row[19], shape=(-1, 3)) if row[20] is not None: dct['stress'] = deblob(row[20]) if row[21] is not None: dct['dipole'] = deblob(row[21]) if row[22] is not None: dct['magmoms'] = deblob(row[22]) if row[23] is not None: dct['magmom'] = deblob(row[23])[0] if row[24] is not None: dct['charges'] = deblob(row[24]) for key, column in zip(['keywords', 'key_value_pairs', 'data'], row[25:28]): x = decode(column) if x: dct[key] = x return dct
def row_to_dict(self, row): if len(row) == 26: row = self._old2new(row) dct = {'id': row[0], 'unique_id': row[1], 'ctime': row[2], 'mtime': row[3], 'user': row[4], 'numbers': deblob(row[5], np.int32), 'positions': deblob(row[6], shape=(-1, 3)), 'cell': deblob(row[7], shape=(3, 3)), 'pbc': (row[8] & np.array([1, 2, 4])).astype(bool)} if row[9] is not None: dct['initial_magmoms'] = deblob(row[9]) if row[10] is not None: dct['initial_charges'] = deblob(row[10]) if row[11] is not None: dct['masses'] = deblob(row[11]) if row[12] is not None: dct['tags'] = deblob(row[12], np.int32) if row[13] is not None: dct['momenta'] = deblob(row[13], shape=(-1, 3)) if row[14] is not None: dct['constraints'] = decode(row[14]) if row[15] is not None: dct['calculator'] = row[15] dct['calculator_parameters'] = decode(row[16]) if row[17] is not None: dct['energy'] = row[17] if row[18] is not None: dct['free_energy'] = row[18] if row[19] is not None: dct['forces'] = deblob(row[19], shape=(-1, 3)) if row[20] is not None: dct['stress'] = deblob(row[20]) if row[21] is not None: dct['dipole'] = deblob(row[21]) if row[22] is not None: dct['magmoms'] = deblob(row[22]) if row[23] is not None: dct['magmom'] = deblob(row[23])[0] if row[24] is not None: dct['charges'] = deblob(row[24]) for key, column in zip(['keywords', 'key_value_pairs', 'data'], row[25:28]): x = decode(column) if x: dct[key] = x return dct
def _old2new(self, row): if not self._allow_reading_old_format: raise IOError('Please convert to new format. ' + 'Use: python -m ase.db.convert ' + self.filename) if len(row) == 26: extra = decode(row[25]) return row[:-1] + (encode( extra['keywords']), encode( extra['key_value_pairs']), encode(extra['data']), 42) else: keywords = decode(row[-4]) kvp = decode(row[-3]) kvp.update(dict((keyword, 1) for keyword in keywords)) return row[:-4] + (encode(kvp), ) + row[-2:]
def _old2new(self, row): if not self._allow_reading_old_format: raise IOError('Please convert to new format. ' + 'Use: python -m ase.db.convert ' + self.filename) if len(row) == 26: extra = decode(row[25]) return row[:-1] + (encode(extra['keywords']), encode(extra['key_value_pairs']), encode(extra['data']), 42) else: keywords = decode(row[-4]) kvp = decode(row[-3]) kvp.update(dict((keyword, 1) for keyword in keywords)) return row[:-4] + (encode(kvp),) + row[-2:]
def _old2new(self, row): if not self._allow_reading_old_format: raise IOError('Please convert to new format. ' + 'Use: python -m ase.db.convert ' + self.filename) extra = decode(row[25]) return row[:-1] + (encode( extra['keywords']), encode( extra['key_value_pairs']), encode(extra['data']), 42)
def _old2new(self, row): if not self._allow_reading_old_format: raise IOError('Please convert to new format. ' + 'Use: python -m ase.db.convert ' + self.filename) extra = decode(row[25]) return row[:-1] + (encode(extra['keywords']), encode(extra['key_value_pairs']), encode(extra['data']), 42)
def _read_data(self, item): self.fd.seek(self.offsets[item]) size = np.fromfile(self.fd, np.int64, 1)[0] data = decode(self.fd.read(size).decode()) return data