<commit_before># Copyright (c) 2009-2019 The Regents of the University of Michigan
# This file is part of the HOOMD-blue project, released under the BSD 3-Clause License.

# Maintainer: joaander / All Developers are free to add commands for new features

R""" Write out simulation and environment context metadata.

Metadata is stored in form of key-value pairs in a JSON file and used
to summarize the per-run simulation parameters so that they can be easily
taken up by other scripts and stored in a database.

Example::

    metadata = meta.dump_metadata()
    meta.dump_metadata(filename = "metadata.json", user = {'debug': True}, indent=2)

"""

import hoomd;
import json, collections;
import time
import datetime
import copy

from collections import OrderedDict
from collections import Mapping

## \internal
class _Operation:

    _cpp_obj = None
    _param_dict = dict()

    def __getattr__(self, attr):
        if self._cpp_obj is not None:
            return getattr(self._cpp_obj, attr)
        else:
            return self._param_dict[attr]

    def __setattr__(self, attr, value):
        if attr in self._param_dict.keys():
            if self._cpp_obj is not None:
                try:
                    setattr(self._cpp_obj, attr, value)
                except (AttributeError):
                    raise AttributeError("{} cannot be set after cpp"
                                         " initialization".format(attr))
            self._param_dict[attr] = value
        else:
            self.__dict__[attr] = value

    def detach(self):
        for key in self._param_dict.keys():
            self._param_dict[key] = getattr(self, key)
        self._cpp_obj = None
        return self

    def attach(self):
        raise NotImplementedError

    def cache_types(self, types):
        pass


# \brief A Mixin to facilitate storage of simulation metadata
class _metadata(object):
    def __init__(self):
        # No metadata provided per default
        self.metadata_fields = []

    ## \internal
    # \brief Return the metadata
    def get_metadata(self):
        data = OrderedDict()

        for m in self.metadata_fields:
            data[m] = getattr(self, m)

        return data

class _metadata_from_dict:<commit_msg>Make _Operations detach raise a NotImplementedError<commit_after># Copyright (c) 2009-2019 The Regents of the University of Michigan
# This file is part of the HOOMD-blue project, released under the BSD 3-Clause License.

# Maintainer: joaander / All Developers are free to add commands for new features

R""" Write out simulation and environment context metadata.

Metadata is stored in form of key-value pairs in a JSON file and used
to summarize the per-run simulation parameters so that they can be easily
taken up by other scripts and stored in a database.

Example::

    metadata = meta.dump_metadata()
    meta.dump_metadata(filename = "metadata.json", user = {'debug': True}, indent=2)

"""

import hoomd;
import json, collections;
import time
import datetime
import copy

from collections import OrderedDict
from collections import Mapping

## \internal
class _Operation:

    _cpp_obj = None
    _param_dict = dict()

    def __getattr__(self, attr):
        if self._cpp_obj is not None:
            return getattr(self._cpp_obj, attr)
        else:
            return self._param_dict[attr]

    def __setattr__(self, attr, value):
        if attr in self._param_dict.keys():
            if self._cpp_obj is not None:
                try:
                    setattr(self._cpp_obj, attr, value)
                except (AttributeError):
                    raise AttributeError("{} cannot be set after cpp"
                                         " initialization".format(attr))
            self._param_dict[attr] = value
        else:
            self.__dict__[attr] = value

    def detach(self):
        raise NotImplementedError

    def attach(self):
        raise NotImplementedError

    def cache_types(self, types):
        pass


# \brief A Mixin to facilitate storage of simulation metadata
class _metadata(object):
    def __init__(self):
        # No metadata provided per default
        self.metadata_fields = []

    ## \internal
    # \brief Return the metadata
    def get_metadata(self):
        data = OrderedDict()

        for m in self.metadata_fields:
            data[m] = getattr(self, m)

        return data

class _metadata_from_dict:
{'fraction_non_alphanumeric': 0.07362240289069558, 'fraction_numerical': 0.004516711833785004, 'mean_word_length': 2.462861610633307, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1491113', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1159, 'n_words': 441}