Esempio n. 1
0
    def test_sampling(self, data, args, result):
        dos = RawDOSData(data[0], data[1])
        weights = dos._sample(*args[:-1], **args[-1])
        assert np.allclose(weights, result)

        with pytest.raises(ValueError):
            dos._sample([1], smearing="Gauss's spherical cousin")
Esempio n. 2
0
 def sparse_dos(self):
     return RawDOSData([1.2, 3.4, 5.], [3., 2.1, 0.],
                       info={
                           'symbol': 'H',
                           'number': '1',
                           'food': 'egg'
                       })
Esempio n. 3
0
 def get_dos(self, kpts=(10, 10, 10), npts=1000, delta=1e-3, indices=None):
     from ase.spectrum.dosdata import RawDOSData
     # dos = self.dos(kpts, npts, delta, indices)
     kpts_kc = monkhorst_pack(kpts)
     omega_w = self.band_structure(kpts_kc).ravel()
     dos = RawDOSData(omega_w, np.ones_like(omega_w))
     return dos
Esempio n. 4
0
    def from_data(cls,
                  energies: Sequence[float],
                  weights: Sequence[Sequence[float]],
                  info: Sequence[Info] = None) -> 'DOSCollection':
        """Create a DOSCollection from data sharing a common set of energies

        This is a convenience method to be used when all the DOS data in the
        collection has a common energy axis. There is no performance advantage
        in using this method for the generic DOSCollection, but for
        GridDOSCollection it is more efficient.

        Args:
            energy: common set of energy values for input data
            weights: array of DOS weights with rows corresponding to different
                datasets
            info: sequence of info dicts corresponding to weights rows.

        Returns:
            Collection of DOS data (in RawDOSData format)
        """

        info = cls._check_weights_and_info(weights, info)

        return cls(
            RawDOSData(energies, row_weights, row_info)
            for row_weights, row_info in zip(weights, info))
Esempio n. 5
0
 def test_sum_all(self, collection_data, collection_info, expected):
     dc = DOSCollection([
         RawDOSData(*item, info=info)
         for item, info in zip(collection_data, collection_info)
     ])
     summed_dc = dc.sum_all()
     energies, weights, ref_info = expected
     assert np.allclose(summed_dc.get_energies(), energies)
     assert np.allclose(summed_dc.get_weights(), weights)
     assert summed_dc.info == ref_info
Esempio n. 6
0
 def test_total(self, collection_data, collection_info):
     dc = DOSCollection([
         RawDOSData(*item, info=info)
         for item, info in zip(collection_data, collection_info)
     ])
     summed = dc.sum_all()
     total = dc.total()
     assert np.allclose(summed.get_energies(), total.get_energies())
     assert np.allclose(summed.get_weights(), total.get_weights())
     assert (set(total.info.items()) - set(summed.info.items()) == set([
         ('label', 'Total')
     ]))
Esempio n. 7
0
 def test_init_errors(self, griddos):
     with pytest.raises(TypeError):
         GridDOSCollection([RawDOSData([1.], [1.])])
     with pytest.raises(ValueError):
         energies = np.linspace(1, 10, 7) + 1
         GridDOSCollection(
             [griddos, GridDOSData(energies, np.sin(energies))])
     with pytest.raises(ValueError):
         energies = np.linspace(1, 10, 6)
         GridDOSCollection(
             [griddos, GridDOSData(energies, np.sin(energies))])
     with pytest.raises(ValueError):
         GridDOSCollection([], energies=None)
     with pytest.raises(ValueError):
         GridDOSCollection([griddos], energies=np.linspace(1, 10, 6))
Esempio n. 8
0
    def get_pdos(self) -> DOSCollection:
        """Phonon DOS, including atomic contributions"""
        energies = self.get_energies()
        masses = self._atoms[self.get_mask()].get_masses()

        # Get weights as N_moving_atoms x N_modes array
        vectors = self.get_modes() / masses[np.newaxis, :, np.newaxis]**-0.5
        all_weights = (np.linalg.norm(vectors, axis=-1)**2).T

        mask = self.get_mask()
        all_info = [{
            'index': i,
            'symbol': a.symbol
        } for i, a in enumerate(self._atoms) if mask[i]]

        return DOSCollection([
            RawDOSData(energies, weights, info=info)
            for weights, info in zip(all_weights, all_info)
        ])
Esempio n. 9
0
    def test_select(self, select_info, select_query, select_result,
                    select_not_result, sum_by_result):
        dc = DOSCollection(
            [RawDOSData([0.], [0.], info=info) for info in select_info])

        if select_result is None:
            assert dc.select(**select_query)._almost_equals(DOSCollection([]))
        else:
            assert select_result == [
                data.info for data in dc.select(**select_query)
            ]

        if select_not_result is None:
            assert (dc.select_not(**select_query)._almost_equals(
                DOSCollection([])))
        else:
            assert select_not_result == [
                data.info for data in dc.select_not(**select_query)
            ]

        assert sum_by_result == [
            data.info for data in dc.sum_by(*sorted(select_query.keys()))
        ]
Esempio n. 10
0
 def test_init(self):
     with pytest.raises(ValueError):
         RawDOSData([1, 2, 3], [4, 5], info={'symbol': 'H'})
Esempio n. 11
0
 def another_sparse_dos(self):
     return RawDOSData([8., 2., 2., 5.], [1., 1., 1., 1.],
                       info={
                           'symbol': 'H',
                           'number': '2'
                       })
Esempio n. 12
0
 def test_equality(self, data_1, data_2, isequal):
     assert (RawDOSData(*data_1[:2], info=data_1[2])._almost_equals(
         RawDOSData(*data_2[:2], info=data_2[2]))) == isequal
Esempio n. 13
0
 def get_dos(self) -> RawDOSData:
     """Total phonon DOS"""
     energies = self.get_energies()
     return RawDOSData(energies, np.ones_like(energies))
Esempio n. 14
0
 def another_rawdos(self):
     return RawDOSData([3., 2., 5.], [1., 0., 2.],
                       info={'other_key': 'other_value'})
Esempio n. 15
0
 def rawdos(self):
     return RawDOSData([1., 2., 4.], [2., 3., 2.],
                       info={'my_key': 'my_value'})