commit
ed4ecafd3d
@ -0,0 +1,83 @@ |
||||
import numpy as np |
||||
import matplotlib.pyplot as plt |
||||
from mpl_toolkits.mplot3d import Axes3D |
||||
import orthopoly |
||||
|
||||
def c2s(posicionescart): |
||||
''' |
||||
De cartesianas a esfericas |
||||
''' |
||||
x,y,z = posicionescart.T |
||||
r,theta,phi = orthopoly.spherical_harmonic.cart2sph(-x,-y,z) #Bug in library |
||||
return np.asarray([r,theta,phi]).T |
||||
|
||||
def fromdata_tomatrix(file_path): |
||||
|
||||
''' |
||||
Lee los archivos y los convierte a matriz |
||||
El formato de los arhcivos es: |
||||
5124 |
||||
20 20 20 0 |
||||
M -0.0928612 12.2444 6.01067 0 |
||||
Cuando barre todas las particulas vuelve a generar: |
||||
# numero de particulas |
||||
# 20 20 20 0 |
||||
# M (tipo de particula) x,y,z 0 |
||||
|
||||
--> Admite archivos txt,xyz,... |
||||
''' |
||||
|
||||
filtered_data = [] |
||||
|
||||
# Leer el archivo línea por línea |
||||
with open(file_path, 'r') as file: |
||||
lines = file.readlines() |
||||
|
||||
# Procesar cada línea |
||||
for line in lines: |
||||
if line.startswith('M'): |
||||
parts = line.split() |
||||
if len(parts) > 4: # Asegurar que tiene suficientes columnas |
||||
filtered_data.append([float(parts[1]), float(parts[2]), float(parts[3])]) |
||||
|
||||
return np.array(filtered_data) |
||||
|
||||
def calculo_cm(data): |
||||
''' |
||||
Para calcular el centro de masas |
||||
''' |
||||
|
||||
if data.shape[0] % 5124 != 0: |
||||
cociente = data.shape[0] // 5124 |
||||
data = data[0:int(cociente*5124)] |
||||
print("La trayectoria no se cargo COMPLETAMENTE, se calcula cm hasta el tiempo mas proximo") |
||||
|
||||
|
||||
v1 = int(data.shape[0]/2) # Numero de puntos |
||||
matrixcm = np.empty((v1,3)) |
||||
|
||||
matrixcm[0,:] = (data[0,:]+data[1,:])/2 |
||||
|
||||
for i in range(1,v1,1): |
||||
matrixcm[i,:] = (data[2*i,:]+data[2*i +1])/2 |
||||
|
||||
matrixcm_sph = c2s(matrixcm) |
||||
|
||||
datos_cart = matrixcm.reshape(int(v1/2562),-1,3) |
||||
datos_esf = matrixcm_sph.reshape(int(v1/2562),-1,3) |
||||
|
||||
return datos_cart,datos_esf |
||||
|
||||
# Se tiene que poner esto para cargar las trayectorias: |
||||
|
||||
file1 = "trajd_xi2_t06.xyz" |
||||
# file1 = "traj_0_00001_2.xyz" |
||||
# file1 = "trayectoriabase.xyz" |
||||
matriz = fromdata_tomatrix(file1) |
||||
|
||||
dcart,desf = calculo_cm(matriz) |
||||
|
||||
np.save('matrizcartd_xi2_t06', dcart) |
||||
# np.save('matrizcart_xi2_t0',dcart) |
||||
# np.save('trayectoria_base',dcart) |
||||
|
Loading…
Reference in new issue