text_plain_output_1.png
import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

df_train = pd.read_csv('../input/train.csv')
df_test = pd.read_csv('../input/test.csv')

def get_xyz_data(filename):
    pos_data = []
    lat_data = []
    with open(filename) as f:
        for line in f.readlines():
            x = line.split()
            if x[0] == 'atom':
                pos_data.append([np.array(x[1:4], dtype=np.float), x[4]])
            elif x[0] == 'lattice_vector':
                lat_data.append(np.array(x[1:4], dtype=np.float))
    return (pos_data, np.array(lat_data))

def length(v):
    return np.linalg.norm(v)
def unit_vector(vector):
    return vector / length(vector)
def angle_between(v1, v2):
    v1_u = unit_vector(v1)
    v2_u = unit_vector(v2)
    return np.arccos(np.clip(np.dot(v1_u, v2_u), -1.0, 1.0))
def angle_deg_between(v1, v2):
    return np.degrees(angle_between(v1, v2))
def get_lattice_constants(lattice_vectors):
    lat_const_series = pd.Series()
    for i in range(3):
        lat_const_series['lattice_vector_' + str(i + 1) + '_ang'] = length(lattice_vectors[i])
    lat_const_series['lattice_angle_alpha_degree'] = angle_deg_between(lattice_vectors[1], lattice_vectors[2])
    lat_const_series['lattice_angle_beta_degree'] = angle_deg_between(lattice_vectors[2], lattice_vectors[0])
    lat_const_series['lattice_angle_gamma_degree'] = angle_deg_between(lattice_vectors[0], lattice_vectors[1])
    return lat_const_series

get_lattice_constants(train_lat)