# Path: vaspy/atomco.py
# class XdatCar(AtomCo):
#     def __init__(self, filename='XDATCAR'):
#         """
#         Class to generate XDATCAR objects.
# 
#         Example:
# 
#         >>> a = XdatCar()
# 
#         Class attributes descriptions
#         =======================================================================
#           Attribute      Description
#           ============  =======================================================
#           filename       string, name of the file the direct coordiante data
#                          stored in
#           bases_const    float, lattice bases constant
#           bases          np.array, bases of POSCAR
#           natom          int, the number of total atom number
#           atom_types     list of strings, atom types
#           tf             list of list, T&F info of atoms
#           info_nline     int, line numbers of lattice info
#           ============  =======================================================
#         """
#         AtomCo.__init__(self, filename)
#         self.info_nline = 7  # line numbers of lattice info
#         self.load()
# 
#     def load(self):
#         with open(self.filename, 'r') as f:
#             # read lattice info
#             self.system = f.readline().strip()
#             self.bases_const = float(f.readline().strip())
# 
#             # lattice basis
#             self.bases = []
#             for i in range(3):
#                 basis = line2list(f.readline())
#                 self.bases.append(basis)
# 
#             # atom info
#             self.atom_types = str2list(f.readline())
#             atoms_num = str2list(f.readline())
#             self.atom_numbers = [int(i) for i in atoms_num]
#             self.natom = sum(self.atom_numbers)
# 
#     def __iter__(self):
#         """ Make the XdatCar object iterable.
#         """
#         # Define namedtuple for the item in iteration.
#         XdatCarItem = namedtuple("XdatCarItem", ["step", "coordinates"])
# 
#         with open(self.filename, 'r') as f:
#             # pass info lines
#             for i in range(self.info_nline):
#                 f.readline()
#             prompt = f.readline().strip()
#             while '=' in prompt:
#                 step = int(prompt.split('=')[-1])
#                 data = []
#                 for i in range(self.natom):
#                     data_line = f.readline()
#                     data.append(line2list(data_line))
#                 prompt = f.readline().strip()
# 
#                 yield XdatCarItem._make([step, np.array(data)])
# 
# Path: vaspy/functions.py
# def get_angle(v1, v2):
#     "Get included angle of vectors v1 and v2."
#     l1, l2 = np.linalg.norm(v1), np.linalg.norm(v2)
#     cos_angle = np.dot(v1, v2)/(l1*l2)
#     angle = np.arccos(cos_angle)*180/np.pi
# 
#     return angle


import numpy as np
from vaspy.atomco import XdatCar
from vaspy.functions import get_angle
#!/usr/bin/env python

'''
    Script to convert XDATCAR to *.arc file to display in Material Studio.
'''


xdatcar = XdatCar()

x, y, z = xdatcar.bases
# lattice info
# angles
alpha = get_angle(y, z)

# Path: vaspy/atomco.py
# class XdatCar(AtomCo):
#     def __init__(self, filename='XDATCAR'):
#         """
#         Class to generate XDATCAR objects.
# 
#         Example:
# 
#         >>> a = XdatCar()
# 
#         Class attributes descriptions
#         =======================================================================
#           Attribute      Description
#           ============  =======================================================
#           filename       string, name of the file the direct coordiante data
#                          stored in
#           bases_const    float, lattice bases constant
#           bases          np.array, bases of POSCAR
#           natom          int, the number of total atom number
#           atom_types     list of strings, atom types
#           tf             list of list, T&F info of atoms
#           info_nline     int, line numbers of lattice info
#           ============  =======================================================
#         """
#         AtomCo.__init__(self, filename)
#         self.info_nline = 7  # line numbers of lattice info
#         self.load()
# 
#     def load(self):
#         with open(self.filename, 'r') as f:
#             # read lattice info
#             self.system = f.readline().strip()
#             self.bases_const = float(f.readline().strip())
# 
#             # lattice basis
#             self.bases = []
#             for i in range(3):
#                 basis = line2list(f.readline())
#                 self.bases.append(basis)
# 
#             # atom info
#             self.atom_types = str2list(f.readline())
#             atoms_num = str2list(f.readline())
#             self.atom_numbers = [int(i) for i in atoms_num]
#             self.natom = sum(self.atom_numbers)
# 
#     def __iter__(self):
#         """ Make the XdatCar object iterable.
#         """
#         # Define namedtuple for the item in iteration.
#         XdatCarItem = namedtuple("XdatCarItem", ["step", "coordinates"])
# 
#         with open(self.filename, 'r') as f:
#             # pass info lines
#             for i in range(self.info_nline):
#                 f.readline()
#             prompt = f.readline().strip()
#             while '=' in prompt:
#                 step = int(prompt.split('=')[-1])
#                 data = []
#                 for i in range(self.natom):
#                     data_line = f.readline()
#                     data.append(line2list(data_line))
#                 prompt = f.readline().strip()
# 
#                 yield XdatCarItem._make([step, np.array(data)])
# 
# Path: vaspy/functions.py
# def get_angle(v1, v2):
#     "Get included angle of vectors v1 and v2."
#     l1, l2 = np.linalg.norm(v1), np.linalg.norm(v2)
#     cos_angle = np.dot(v1, v2)/(l1*l2)
#     angle = np.arccos(cos_angle)*180/np.pi
# 
#     return angle


# Path: scripts/xdatcar_to_arc.py
import numpy as np
from vaspy.atomco import XdatCar
from vaspy.functions import get_angle

#!/usr/bin/env python

'''
    Script to convert XDATCAR to *.arc file to display in Material Studio.
'''


xdatcar = XdatCar()

x, y, z = xdatcar.bases
# lattice info
# angles
alpha = get_angle(y, z)

beta = get_angle(x, z)