<commit_before>from __future__ import print_function, division, unicode_literals

from Datum import Datum

from nushellx_lpt.Shell import Shell
from nushellx_lpt.parser import mass_to_header_data_map as mhd_map
from nushellx_lpt.parser import mass_to_n_to_body_data_map as mnbd_map
from nushellx_lpt.parser import mass_to_zbt_map as mass_zbt_map


class DatumLpt(Datum):
    """Stores data maps from *.lpt files and methods for generating new maps
    from these.
    """
    def __init__(self, directory, exp, files):
        super(DatumLpt, self).__init__(directory=directory, exp=exp,
                                       files=files)
        self._mass_header_map = None
        self._mass_n_body_map = None
        self._mass_zbt_map = None

        self._set_maps()

    def _set_maps(self):
        self._set_mass_header_map()
        self._set_mass_n_body_map()
        self._set_mass_zbt_map()

    def _set_mass_header_map(self):
        try:
            self._mass_header_map = mhd_map(self.files)
        except ValueError:
            self._mass_header_map = None

    def _set_mass_n_body_map(self):
        mass_n_body_map = mnbd_map(self.files)
        d = dict()
        for m, nb_map in mass_n_body_map.iteritems():
            if m not in d and len(nb_map) > 0:
                d[m] = dict()
            for n, b in nb_map.iteritems():
                d[m][n] = Shell(*b)
        self._mass_n_body_map = d

    def _set_mass_zbt_map(self):
        self._mass_zbt_map = mass_zbt_map(filtered_filepaths_lpt=self.files)

    def mass_header_map(self):
        if self._mass_header_map is not None:
            return dict(self._mass_header_map)
        else:
            return None

    def mass_n_body_map(self):
        return dict(self._mass_n_body_map)

    def mass_zbt_map(self):
        return dict(self._mass_zbt_map)

    def mass_n_energy_map(self):
        d = dict()
        for m, nb_map in self._mass_n_body_map.iteritems():
            d[m] = {n: b.E for n, b in nb_map.iteritems()}
        return d

    def mass_lowest_energy_map(self):
        try:
            return {k: v[1] for k, v in self.mass_n_energy_map().iteritems()}
        except KeyError:
            mne_map = self.mass_n_energy_map()
            for k, v in mne_map.iteritems():
                print('mass = {}'.format(k))
                for kk, vv in v.iteritems():
                    print('n = {:2} : e = {}'.format(kk, vv))

    def mass_n_excitation_map(self):
        d = dict()
        for m, nb_map in self._mass_n_body_map.iteritems():
            d[m] = {n: b.Ex for n, b in nb_map.iteritems()}
        return d

    def n_mass_energy_map(self):
        d = dict()
        mne_map = self.mass_n_energy_map()
        for m, ne_map in mne_map.iteritems():
            for n, e in ne_map.iteritems():<commit_msg>New method for lpt datum, which combines zero body term and lowest energy to given total ground state energy<commit_after>from __future__ import print_function, division, unicode_literals

from Datum import Datum

from nushellx_lpt.Shell import Shell
from nushellx_lpt.parser import mass_to_header_data_map as mhd_map
from nushellx_lpt.parser import mass_to_n_to_body_data_map as mnbd_map
from nushellx_lpt.parser import mass_to_zbt_map as mass_zbt_map


class DatumLpt(Datum):
    """Stores data maps from *.lpt files and methods for generating new maps
    from these.
    """
    def __init__(self, directory, exp, files):
        super(DatumLpt, self).__init__(directory=directory, exp=exp,
                                       files=files)
        self._mass_header_map = None
        self._mass_n_body_map = None
        self._mass_zbt_map = None

        self._set_maps()

    def _set_maps(self):
        self._set_mass_header_map()
        self._set_mass_n_body_map()
        self._set_mass_zbt_map()

    def _set_mass_header_map(self):
        try:
            self._mass_header_map = mhd_map(self.files)
        except ValueError:
            self._mass_header_map = None

    def _set_mass_n_body_map(self):
        mass_n_body_map = mnbd_map(self.files)
        d = dict()
        for m, nb_map in mass_n_body_map.iteritems():
            if m not in d and len(nb_map) > 0:
                d[m] = dict()
            for n, b in nb_map.iteritems():
                d[m][n] = Shell(*b)
        self._mass_n_body_map = d

    def _set_mass_zbt_map(self):
        self._mass_zbt_map = mass_zbt_map(filtered_filepaths_lpt=self.files)

    def mass_header_map(self):
        if self._mass_header_map is not None:
            return dict(self._mass_header_map)
        else:
            return None

    def mass_n_body_map(self):
        return dict(self._mass_n_body_map)

    def mass_zbt_map(self):
        return dict(self._mass_zbt_map)

    def mass_n_energy_map(self):
        d = dict()
        for m, nb_map in self._mass_n_body_map.iteritems():
            d[m] = {n: b.E for n, b in nb_map.iteritems()}
        return d

    def mass_lowest_energy_map(self):
        return {k: v[1] for k, v in self.mass_n_energy_map().iteritems()}

    def mass_ground_energy_map(self):
        mzbt = self.mass_zbt_map()
        me0 = self.mass_lowest_energy_map()
        mg = dict()
        for k in mzbt:
            if k in me0:
                mg[k] = mzbt[k] + me0[k]
        return mg

    def mass_n_excitation_map(self):
        d = dict()
        for m, nb_map in self._mass_n_body_map.iteritems():
            d[m] = {n: b.Ex for n, b in nb_map.iteritems()}
        return d

    def n_mass_energy_map(self):
        d = dict()
        mne_map = self.mass_n_energy_map()
        for m, ne_map in mne_map.iteritems():
            for n, e in ne_map.iteritems():
{'fraction_non_alphanumeric': 0.08926692388635567, 'fraction_numerical': 0.0014030164854437039, 'mean_word_length': 2.2965317919075146, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2986000', 'n_tokens_mistral': 2018, 'n_tokens_neox': 1976, 'n_words': 452}