<commit_before>import atomstest
import numpy as np
import derivative
import correlation
import matplotlib.pyplot as plt


def obtain_velocity_from_positions(cell,trajectory,time):
    velocity = trajectory.copy()

    for i in range(trajectory.shape[1]):
        velocity [:,i,:] = derivative.derivative(cell, trajectory[:,i,:], time)
#        plt.plot(velocity[:,i,:])
#        plt.show()

    print('Velocity obtained from trajectory derivative')
    return velocity


def obtain_velocity_from_positions2(trajectory):
    velocity = trajectory.copy()
    for i in range(trajectory.shape[1]):
        for j in range(trajectory.shape[2]):
#            print(i,j)
    #        velocity[:,i,j] = np.gradient(position[:,i,j])
 #           print(trajectory[:,i,j])
            velocity [:,i,j] =  np.resize( np.diff(trajectory[:,i,j],n=4), velocity.shape[0])
#            print(velocity)
    print('Velocity obtained from trajectory derivative')
    return velocity


class Dynamics:

    def __init__(self,
                 structure=atomstest.Structure,
                 trajectory=None,
                 velocity=None,
                 energy = None,
                 time=None):


        self._time=time
        self._trajectory = trajectory
        self._energy = energy
        self._time_step_average = None
        self._velocity_mass_average = None

        if structure:
            self._structure = structure
        else:
            print('Warining: Initalization without structure')
            self._structure = None

        if velocity is None:
            print('No velocity provided')
            self._velocity = obtain_velocity_from_positions(self._structure.get_big_cell(),self._trajectory,self._time)
        else:
            self._velocity = velocity


    def set_trajectory(self,trajectory):
        self._trajectory = trajectory

    def get_trajectory(self):
        return self._trajectory

    def set_time(self, time):
        self._time = time

    def get_time(self):
        return self._time

    def get_energy(self):
        return  self._energy

    def get_time_step_average(self):

        if self._time_step_average :
            return self._time_step_average
        else:
            self._time_step_average = 0
            for i in range(self._time.shape[0]-1):
                self._time_step_average += self._time[i+1] - self._time[i]
            self._time_step_average /= (self._time.shape[0]-1)
            return self._time_step_average

    def set_structure(self, structure):
        self._structure = structure

    def get_velocity(self):
        return self._velocity

    def get_velocity_mass_average(self,):

        if self._velocity_mass_average is None:
            self._velocity_mass_average = np.copy(self._velocity)

        ######################## To be improved ######################
            super_cell=[self.structure.get_super_cell_matrix()[i][i] for i in range (self.structure.get_number_of_dimensions())]
        ##############################################################

            for i in range(self._structure.get_number_of_atoms()):
                self._velocity_mass_average[:,i,:] = self._velocity[:,i,:] /np.sqrt(self._structure.get_masses(super_cell=super_cell)[i])

        return np.array(self._velocity_mass_average)

    @property
    def structure(self):
        return self._structure

    @property
    def velocity(self):
        return self._velocity

    @velocity.setter
    def velocity(self,velocity):
        self._velocity = velocity<commit_msg>Minor corrections related to dynamics class<commit_after>import atomstest
import numpy as np
import derivative
import correlation
import matplotlib.pyplot as plt


def obtain_velocity_from_positions(cell,trajectory,time):
    velocity = np.empty_like(trajectory)

    for i in range(trajectory.shape[1]):
        velocity [:,i,:] = derivative.derivative(cell, trajectory[:,i,:], time)
#        plt.plot(velocity[:,i,:])
#        plt.show()

    print('Velocity obtained from trajectory derivative')
    return velocity


def obtain_velocity_from_positions2(trajectory):
    velocity = trajectory.copy()
    for i in range(trajectory.shape[1]):
        for j in range(trajectory.shape[2]):
#            print(i,j)
    #        velocity[:,i,j] = np.gradient(position[:,i,j])
 #           print(trajectory[:,i,j])
            velocity [:,i,j] =  np.resize( np.diff(trajectory[:,i,j],n=4), velocity.shape[0])
#            print(velocity)
    print('Velocity obtained from trajectory derivative')
    return velocity


class Dynamics:

    def __init__(self,
                 structure=atomstest.Structure,
                 trajectory=None,
                 velocity=None,
                 energy = None,
                 time=None):


        self._time=time
        self._trajectory = trajectory
        self._energy = energy
        self._velocity = velocity
        self._time_step_average = None
        self._velocity_mass_average = None

        if structure:
            self._structure = structure
        else:
            print('Warining: Initalization without structure')
            self._structure = None


    def set_trajectory(self,trajectory):
        self._trajectory = trajectory

    def get_trajectory(self):
        return self._trajectory

    def set_time(self, time):
        self._time = time

    def get_time(self):
        return self._time

    def get_energy(self):
        return  self._energy

    def get_time_step_average(self):

        if self._time_step_average :
            return self._time_step_average
        else:
            self._time_step_average = 0
            for i in range(self._time.shape[0]-1):
                self._time_step_average += self._time[i+1] - self._time[i]
            self._time_step_average /= (self._time.shape[0]-1)
            return self._time_step_average

    def set_structure(self, structure):
        self._structure = structure

    def get_velocity_mass_average(self,):

        if self._velocity_mass_average is None:
            self._velocity_mass_average = np.empty_like(self.velocity)

        ######################## To be improved ######################
            super_cell=[self.structure.get_super_cell_matrix()[i][i] for i in range (self.structure.get_number_of_dimensions())]
        ##############################################################

            for i in range(self._structure.get_number_of_atoms()):
                self._velocity_mass_average[:,i,:] = self.velocity[:,i,:] /np.sqrt(self.structure.get_masses(super_cell=super_cell)[i])

        return np.array(self._velocity_mass_average)

    @property
    def structure(self):
        return self._structure

    @property
    def velocity(self):
        if self._velocity is None:
            print('No velocity provided! calculating it!')
            self._velocity = obtain_velocity_from_positions(self.structure.get_big_cell(),self.get_trajectory(),self.get_time())
        return self._velocity

    @velocity.setter
    def velocity(self,velocity):
        self._velocity = velocity
{'fraction_non_alphanumeric': 0.12758766370933672, 'fraction_numerical': 0.0033798056611744824, 'mean_word_length': 2.5814422592032273, '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': '5173416', 'n_tokens_mistral': 2123, 'n_tokens_neox': 1963, 'n_words': 397}