<commit_before>import copy

class Particle:

    #Particle properties
    _position = (0, 0, 0,)
    _previous_position = (0, 0, 0,)
    _velocity = (0, 0, 0,)
    _force = (0, 0, 0,)

    def __init__(self, position, velocity):
        """Initialize the particle with given position and velocity."""

        self._position = position
        self._velocity = velocity

    def set_force_to(self, force):
        self._force = force

    def update_position(self, dt):
        """Update the position of the particle according to the Verlet algorithm."""

        next_position = []
        next_velocity = []
        for n in len(self._position):
            dq = 2*self._position[n] - self._previous_position[n] + self._force[n]*dt**2
            dv = (dq - self._previous_position[n])/(2*dt)
            next_position.append(dq)
            next_velocity.append(dv)
        self._previous_position = copy.deepcopy(self._position)
        self._position = tuple(next_position)
        self._velocity = tuple(next_velocity)

    def get_squared_velocity(self):
        """Get the square of the velocity."""

        sumv2 = 0
        for n in len(self._velocity):
            sumv += self._velocity[n]**2
        return sumv2

class LJContainer:

    _particles = []

    def __init__(self, density, temperature):
        pass

    def initialize(self, atoms):
        #Place particles
        #Give random velocities
        #Update CoM velocity
        #Update total kinetic energy
        #Shift velocities so that CoM velocity is zero
        #Scale velocities according to the equipartition theorem
        pass

    def update_forces(self):
        #Loop over all pairs
        #Use PBC
        #Test cutoff
        #Update force according to LJ
        #Update energy
        pass
<commit_msg>Implement initial velocity generation<commit_after>import copy
import random
import math

class Particle:

    #Particle properties
    _position = (0, 0, 0,)
    _previous_position = (0, 0, 0,)
    _velocity = (0, 0, 0,)
    _force = (0, 0, 0,)

    def __init__(self, position, velocity):
        """Initialize the particle with given position and velocity."""

        self._position = position
        self._velocity = velocity

    def set_force_to(self, force):
        self._force = force

    def update_position(self, dt):
        """Update the position of the particle according to the Verlet algorithm."""

        next_position = []
        next_velocity = []
        for n in len(self._position):
            dq = 2*self._position[n] - self._previous_position[n] + self._force[n]*dt**2
            dv = (dq - self._previous_position[n])/(2*dt)
            next_position.append(dq)
            next_velocity.append(dv)
        self._previous_position = copy.deepcopy(self._position)
        self._position = tuple(next_position)
        self._velocity = tuple(next_velocity)

    def get_squared_velocity(self):
        """Get the square of the velocity."""

        sumv2 = 0
        for n in len(self._velocity):
            sumv += self._velocity[n]**2
        return sumv2

class LJContainer:

    _particles = []
    _temperature = 0
    _density = 0
    _length = 0

    def __init__(self, number_of_particles, density, temperature):
        self._length = (number_of_particles / density)**(1.0/3)
        self._temperature = temperature
        self._density = density
        #self.initialize(number_of_particles)
        self.generate_velocities(108)
        #print(self._length)

    def initialize(self, number_of_particles):
        """Initialize the container."""

        #Calculate the spacing between particles
        spacing = self._length / 6.0
        velocities = self.generate_velocities(number_of_particles)
        for n in range(number_of_particles):
            #Start with 3 layers of 6x6 particles
            x = (n%6 + 1) * spacing
            y = ((n-(n/36)*36)/6 + 1) * spacing
            z = (n/36 + 1) * spacing
            position = (x, y, z,)
            velocity = velocities.pop()
            particle = Particle(position, velocity)
            self._particles.append(particle)

    def generate_velocities(self, number_of_particles):
        """Generate an initial velocity distribution of number_of_particles velocities."""

        dimensions = 3

        velocities = []
        vtot = [0] * dimensions
        v2tot = [0] * dimensions
        fs = [0] * dimensions

        for i in range(number_of_particles):
            v = [0] * dimensions
            v2 = [0] * dimensions
            for d in range(dimensions):
                vn = random.uniform(-0.5, 0.5)
                v[d] = vn
                v2[d] = vn**2
                vtot[d] += vn
                v2tot[d] += vn**2
            velocities.append(v)
        for d in range(dimensions):
            vtot[d] = vtot[d] / number_of_particles
            v2tot[d] = v2tot[d] / number_of_particles
            fs[d] = math.sqrt(self._temperature / v2tot[d])
        for i in range(number_of_particles):
            vn = [0] * dimensions
            for d in range(dimensions):
                vn[d] = (velocities[i][d] - vtot[d]) * fs[d]
            velocities[i] = vn

        vtot = [0] * dimensions
        v2tot = [0] * dimensions
        for item in velocities:
            for dim in range(len(item)):
                vtot[dim] += item[dim]
                v2tot[dim] += item[dim]**2
        for dim in range(dimensions):
            v2tot[dim] = v2tot[dim] / number_of_particles
        print vtot, v2tot

    def update_forces(self):
        #Loop over all pairs
        #Use PBC
        #Test cutoff
        #Update force according to LJ
        #Update energy
        pass

{'fraction_non_alphanumeric': 0.09918478260869565, 'fraction_numerical': 0.01545516304347826, 'mean_word_length': 1.847678916827853, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2570425', 'n_tokens_mistral': 1885, 'n_tokens_neox': 1637, 'n_words': 454}