def create_ase_object(objtype, dct): # We just try each object type one after another and instantiate # them manually, depending on which kind it is. # We can formalize this later if it ever becomes necessary. if objtype == 'cell': from ase.cell import Cell dct.pop('pbc', None) # compatibility; we once had pbc obj = Cell(**dct) elif objtype == 'bandstructure': from ase.spectrum.band_structure import BandStructure obj = BandStructure(**dct) elif objtype == 'bandpath': from ase.dft.kpoints import BandPath obj = BandPath(path=dct.pop('labelseq'), **dct) elif objtype == 'atoms': from ase import Atoms obj = Atoms.fromdict(dct) elif objtype == 'vibrationsdata': from ase.vibrations import VibrationsData obj = VibrationsData.fromdict(dct) else: raise ValueError('Do not know how to decode object type {} ' 'into an actual object'.format(objtype)) assert obj.ase_objtype == objtype return obj
def test_dict_indices(self, n2_vibdata, indices, expected_mask): vib_data_dict = n2_vibdata.todict() vib_data_dict['indices'] = indices # Reduce size of Hessian if necessary if indices is not None: n_active = len(indices) vib_data_dict['hessian'] = (np.asarray( vib_data_dict['hessian'])[:n_active, :, :n_active, :].tolist()) vib_data_fromdict = VibrationsData.fromdict(vib_data_dict) assert_array_almost_equal(vib_data_fromdict.get_mask(), expected_mask)
def test_dict_roundtrip(self, n2_vibdata): vib_data_dict = n2_vibdata.todict() vib_data_roundtrip = VibrationsData.fromdict(vib_data_dict) for getter in ('get_atoms', ): assert (getattr(n2_vibdata, getter)() == getattr(vib_data_roundtrip, getter)()) for array_getter in ('get_hessian', 'get_hessian_2d', 'get_mask', 'get_indices'): assert_array_almost_equal( getattr(n2_vibdata, array_getter)(), getattr(vib_data_roundtrip, array_getter)())