<commit_before>import uuid

from simphony.core.cuba import CUBA
from simphony.core.data_container import DataContainer
from simphony.cuds.particles import Particle

from simlammps.config.domain import get_box
from simlammps.internal.particle_data_cache import ParticleDataCache
from simlammps.abc_data_manager import ABCDataManager
from simlammps.cuba_extension import CUBAExtension
from simlammps.config.script_writer import ScriptWriter


class _IDGenerator(object):
    """Class keeps track of what is next LAMMPS id

    TODO provide ids that can be reused (i.e. become available
     after deletions) or complains when we have used too many..

    """
    def __init__(self):
        self._next_id = 0

    def get_new_id(self):
        """ returns next lammps-id
        """
        self._next_id += 1
        return self._next_id


class LammpsInternalDataManager(ABCDataManager):
    """  Class managing LAMMPS data information using file-io

    The class performs communicating the data to and from LAMMPS using FILE-IO
    communications (i.e. through input and output files). The class manages
    data existing in LAMMPS (via LAMMPS data file) and allows this data to be
    queried and to be changed.

    Class maintains a cache of the particle information.  This information
    is read from file whenever the read() method is called and written to
    the file whenever the flush() method is called.

    Parameters
    ----------
    lammps :
        lammps python wrapper
    """
    def __init__(self, lammps):
        super(LammpsInternalDataManager, self).__init__()

        self._lammps = lammps

        dummy_bc = {}
        dummy_bc[CUBAExtension.BOX_FACES] = (
            "periodic", "periodic", "periodic")
        commands = "dimension 3\n"
        commands = "units lj\n"
        commands = ScriptWriter.get_initial_setup()

        commands += ScriptWriter.get_boundary(dummy_bc)
        for command in commands.splitlines():
            self._lammps.command(command)

        # TODO This is a hack as due to pc.data_extension
        # being empty at this point
        vectors = [(25.0, 0.0, 0.0),
                   (0.0, 22.0, 0.0),
                   (0.0, 0.0, 1.0)]
        dummy_data = {}
        dummy_data[CUBAExtension.BOX_VECTORS] = vectors
        dummy_data[CUBAExtension.BOX_ORIGIN] = (0.0, 0.0, 0.0)
        self._lammps.command(get_box([dummy_data], command_format=True))
        types = 3
        self._lammps.command("create_box {} box".format(types))

        self._id_generator = _IDGenerator()

        # map from lammps-id to simphony-uid
        # (note lammps-id is also the index)
        self._lammpsid_to_uid = {}

        # map from simphony-uid (with uname) to lammps-id
        self._uid_to_lammpsid = {}

        # map from lammpsid to index location of data
        self._lammpsid_to_index = {}

        # cache of coordinates and point data
        self._particle_data_cache = ParticleDataCache(lammps=self._lammps)

        # cache of particle containers's data
        self._pc_data = {}
        self._pc_data_extension = {}

        self._dummy_box = None

    def get_data(self, uname):
        """Returns data container associated with particle container

        Parameters
        ----------
        uname : string
            non-changing unique name of particles

        """
        return self._pc_data[uname]

    def set_data(self, data, uname):
        """Sets data container associated with particle container

        Parameters
        ----------
        uname : string
            non-changing unique name of particles

        """
        self._pc_data[uname] = data

    def get_data_extension(self, uname):
        """Returns data container extension associated with particle container

        Parameters
        ----------
        uname : string
            non-changing unique name of particles

        """
        return self._pc_data_extension[uname]

    def set_data_extension(self, data, uname):
        """Sets data container extension associated with particle container

        Parameters
        ----------
        uname : string
            non-changing unique name of particles

        """
        self._pc_data_extension[uname] = data

    def _handle_delete_particles(self, uname):
        """Handle when a Particles is deleted

        Parameters
        ----------
        uname : string
            non-changing unique name of particles

        """
        del self._pc_data[uname]
        del self._pc_data_extension[uname]

        # TODO delete id->uid info
        del self._uid_to_lammpsid[uname]

    def _handle_new_particles(self, uname, particles):
        """Add new particle container to this manager.


        Parameters
        ----------
        uname : string
            non-changing unique name of particles
        particles : ABCParticles
            particle container to be added

        """
        # create empty stand-alone particle container
        # to use as a cache of for input/output to LAMMPS

        self._uid_to_lammpsid[uname] = {}

        self._pc_data[uname] = DataContainer(particles.data)
        self._pc_data_extension[uname] = {}

        # This is a hack as due to pc.data_extension
        # being empty at this point
        vectors = [(25.0, 0.0, 0.0),
                   (0.0, 22.0, 0.0),
                   (0.0, 0.0, 1.0)]
        self._pc_data_extension[uname][CUBAExtension.BOX_VECTORS] = vectors
        self._pc_data_extension[uname][CUBAExtension.BOX_ORIGIN] = (0.0,
                                                                    0.0,
                                                                    0.0)<commit_msg>add hack for simulation box for simple_nve.py example<commit_after>import uuid

from simphony.core.cuba import CUBA
from simphony.core.data_container import DataContainer
from simphony.cuds.particles import Particle

from simlammps.config.domain import get_box
from simlammps.internal.particle_data_cache import ParticleDataCache
from simlammps.abc_data_manager import ABCDataManager
from simlammps.cuba_extension import CUBAExtension
from simlammps.config.script_writer import ScriptWriter


class _IDGenerator(object):
    """Class keeps track of what is next LAMMPS id

    TODO provide ids that can be reused (i.e. become available
     after deletions) or complains when we have used too many..

    """
    def __init__(self):
        self._next_id = 0

    def get_new_id(self):
        """ returns next lammps-id
        """
        self._next_id += 1
        return self._next_id


class LammpsInternalDataManager(ABCDataManager):
    """  Class managing LAMMPS data information using file-io

    The class performs communicating the data to and from LAMMPS using FILE-IO
    communications (i.e. through input and output files). The class manages
    data existing in LAMMPS (via LAMMPS data file) and allows this data to be
    queried and to be changed.

    Class maintains a cache of the particle information.  This information
    is read from file whenever the read() method is called and written to
    the file whenever the flush() method is called.

    Parameters
    ----------
    lammps :
        lammps python wrapper
    """
    def __init__(self, lammps):
        super(LammpsInternalDataManager, self).__init__()

        self._lammps = lammps

        dummy_bc = {}
        dummy_bc[CUBAExtension.BOX_FACES] = (
            "periodic", "periodic", "periodic")
        commands = "dimension 3\n"
        commands = "units lj\n"
        commands = ScriptWriter.get_initial_setup()

        commands += ScriptWriter.get_boundary(dummy_bc)
        for command in commands.splitlines():
            self._lammps.command(command)

        # TODO This is a hack as due to pc.data_extension
        # being empty at this point (we choose a vectors
        # that corresponds with the dimensions used in our
        # unit testing and in simple_nve.py
        vectors = [(25.0, 0.0, 0.0),
                   (0.0, 22.0, 0.0),
                   (0.0, 0.0, 6.196)]
        dummy_data = {}
        dummy_data[CUBAExtension.BOX_VECTORS] = vectors
        dummy_data[CUBAExtension.BOX_ORIGIN] = (0.0, 0.0, 0.0)
        self._lammps.command(get_box([dummy_data], command_format=True))
        types = 3
        self._lammps.command("create_box {} box".format(types))

        self._id_generator = _IDGenerator()

        # map from lammps-id to simphony-uid
        # (note lammps-id is also the index)
        self._lammpsid_to_uid = {}

        # map from simphony-uid (with uname) to lammps-id
        self._uid_to_lammpsid = {}

        # map from lammpsid to index location of data
        self._lammpsid_to_index = {}

        # cache of coordinates and point data
        self._particle_data_cache = ParticleDataCache(lammps=self._lammps)

        # cache of particle containers's data
        self._pc_data = {}
        self._pc_data_extension = {}

        self._dummy_box = None

    def get_data(self, uname):
        """Returns data container associated with particle container

        Parameters
        ----------
        uname : string
            non-changing unique name of particles

        """
        return self._pc_data[uname]

    def set_data(self, data, uname):
        """Sets data container associated with particle container

        Parameters
        ----------
        uname : string
            non-changing unique name of particles

        """
        self._pc_data[uname] = data

    def get_data_extension(self, uname):
        """Returns data container extension associated with particle container

        Parameters
        ----------
        uname : string
            non-changing unique name of particles

        """
        return self._pc_data_extension[uname]

    def set_data_extension(self, data, uname):
        """Sets data container extension associated with particle container

        Parameters
        ----------
        uname : string
            non-changing unique name of particles

        """
        self._pc_data_extension[uname] = data

    def _handle_delete_particles(self, uname):
        """Handle when a Particles is deleted

        Parameters
        ----------
        uname : string
            non-changing unique name of particles

        """
        del self._pc_data[uname]
        del self._pc_data_extension[uname]

        # TODO delete id->uid info
        del self._uid_to_lammpsid[uname]

    def _handle_new_particles(self, uname, particles):
        """Add new particle container to this manager.


        Parameters
        ----------
        uname : string
            non-changing unique name of particles
        particles : ABCParticles
            particle container to be added

        """
        # create empty stand-alone particle container
        # to use as a cache of for input/output to LAMMPS

        self._uid_to_lammpsid[uname] = {}

        self._pc_data[uname] = DataContainer(particles.data)
        self._pc_data_extension[uname] = {}

        # TODO This is a hack as due to pc.data_extension
        # being empty at this point (we choose a vectors
        # that corresponds with the dimensions used in our
        # unit testing and in simple_nve.py
        vectors = [(25.0, 0.0, 0.0),
                   (0.0, 22.0, 0.0),
                   (0.0, 0.0, 6.196)]
        self._pc_data_extension[uname][CUBAExtension.BOX_VECTORS] = vectors
        self._pc_data_extension[uname][CUBAExtension.BOX_ORIGIN] = (0.0,
                                                                    0.0,
                                                                    0.0)
{'fraction_non_alphanumeric': 0.08535228148274976, 'fraction_numerical': 0.009930656621864566, 'mean_word_length': 2.029564315352697, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6265576', 'n_tokens_mistral': 3360, 'n_tokens_neox': 3180, 'n_words': 963}