# Path: vasppy/poscar.py
# def parity( list ):
# def swap_axes( matrix, axes ):
#     def __init__( self ):
#     def coordinates_by_species( self, species ):
#     def range_by_species( self, species ):
#     def atom_number_by_species( self, species ):
#     def sorted( self, species ):
#     def read_from( self, filename ):
#     def from_file( cls, filename ):
#     def in_bohr( self ):
#     def coords_are_fractional( self ): 
#     def coords_are_cartesian( self ):
#     def fractional_coordinates( self ):
#     def cartesian_coordinates( self ):
#     def select_coordinates( self, coordinate_type='Direct' ):
#     def output_coordinates_only( self, coordinate_type='Direct', opts=None ):
#     def output( self, coordinate_type='Direct', opts=None ):
#     def output_header( self, coordinate_type='Direct', opts=None ):
#     def write_to( self, filename, coordinate_type='Direct', opts=None ):
#     def output_as_xtl( self ):
#     def output_as_cif( self, symprec = None ):
#     def output_as_pimaim( self, to_bohr = True ):
#     def cell_coordinates( self ):
#     def labels( self ):
#     def replicate( self, h, k, l, group=False ):
#     def cell_lengths( self ):
#     def cell_angles( self ):
#     def to_configuration( self ):
#     def swap_axes( self, axes ):
#     def to_pymatgen_structure( self ):
#     def stoichiometry( self ):
# class Poscar:
# 
# Path: vasppy/cell.py
# def angle( x, y ):
# def rotation_matrix(axis, theta):
#     def __init__( self, matrix ):
#     def dr( self, r1, r2, cutoff=None ):
#     def nearest_image( self, origin, point ):
#     def minimum_image( self, r1, r2 ):
#     def minimum_image_dr( self, r1, r2, cutoff=None ):
#     def lengths( self ):
#     def angles( self ):
#     def cartesian_to_fractional_coordinates( self, coordinates ):
#     def fractional_to_cartesian_coordinates( self, coordinates ):
#     def inside_cell( self, r ):
#     def volume( self ):
#     def unit_vectors( self ):
#     def rotate( self, axis, theta ):
# class Cell:


import numpy as np  # type: ignore
import sys
import math
from vasppy import poscar, cell

def trilinear_interpolation( cube, r ):
    return( interpolate ( 
                interpolate( 
                    interpolate( cube[ 0, 0, 0 ], cube[ 1, 0, 0 ], r[ 0 ] ), # trilinear interpolation => http://en.wikipedia.org/wiki/Trilinear_interpolation
                    interpolate( cube[ 0, 1, 0 ], cube[ 1, 1, 0 ], r[ 0 ] ), 
                    r[ 1 ] ),
                interpolate( 
                    interpolate( cube[ 0, 0, 1 ], cube[ 1, 0, 1 ], r[ 0 ] ),
                    interpolate( cube[ 0, 1, 1 ], cube[ 1, 1, 1 ], r[ 0 ] ), 
                    r[ 1 ] ), 
                r[ 2 ] ) 
            )

class Grid:

    projections = { 'x' : 0, 'y' : 1, 'z' : 2 }

    def __init__( self, dimensions = [ 1, 1, 1 ] ):
        self.filename = None
        self.poscar = poscar.Poscar()
        self.number_of_header_lines = 0
        self.dimensions = dimensions
        self.spacing = np.array( [ 1.0 / number_of_points for number_of_points in self.dimensions ] )
        self.grid = np.zeros( self.dimensions )

    def read_from_filename( self, filename ):
        self.filename = filename
        self.poscar = poscar.Poscar()
        self.poscar.read_from( self.filename )

# Path: vasppy/poscar.py
# def parity( list ):
# def swap_axes( matrix, axes ):
#     def __init__( self ):
#     def coordinates_by_species( self, species ):
#     def range_by_species( self, species ):
#     def atom_number_by_species( self, species ):
#     def sorted( self, species ):
#     def read_from( self, filename ):
#     def from_file( cls, filename ):
#     def in_bohr( self ):
#     def coords_are_fractional( self ): 
#     def coords_are_cartesian( self ):
#     def fractional_coordinates( self ):
#     def cartesian_coordinates( self ):
#     def select_coordinates( self, coordinate_type='Direct' ):
#     def output_coordinates_only( self, coordinate_type='Direct', opts=None ):
#     def output( self, coordinate_type='Direct', opts=None ):
#     def output_header( self, coordinate_type='Direct', opts=None ):
#     def write_to( self, filename, coordinate_type='Direct', opts=None ):
#     def output_as_xtl( self ):
#     def output_as_cif( self, symprec = None ):
#     def output_as_pimaim( self, to_bohr = True ):
#     def cell_coordinates( self ):
#     def labels( self ):
#     def replicate( self, h, k, l, group=False ):
#     def cell_lengths( self ):
#     def cell_angles( self ):
#     def to_configuration( self ):
#     def swap_axes( self, axes ):
#     def to_pymatgen_structure( self ):
#     def stoichiometry( self ):
# class Poscar:
# 
# Path: vasppy/cell.py
# def angle( x, y ):
# def rotation_matrix(axis, theta):
#     def __init__( self, matrix ):
#     def dr( self, r1, r2, cutoff=None ):
#     def nearest_image( self, origin, point ):
#     def minimum_image( self, r1, r2 ):
#     def minimum_image_dr( self, r1, r2, cutoff=None ):
#     def lengths( self ):
#     def angles( self ):
#     def cartesian_to_fractional_coordinates( self, coordinates ):
#     def fractional_to_cartesian_coordinates( self, coordinates ):
#     def inside_cell( self, r ):
#     def volume( self ):
#     def unit_vectors( self ):
#     def rotate( self, axis, theta ):
# class Cell:


# Path: vasppy/grid.py
import numpy as np  # type: ignore
import sys
import math
from vasppy import poscar, cell


def trilinear_interpolation( cube, r ):
    return( interpolate ( 
                interpolate( 
                    interpolate( cube[ 0, 0, 0 ], cube[ 1, 0, 0 ], r[ 0 ] ), # trilinear interpolation => http://en.wikipedia.org/wiki/Trilinear_interpolation
                    interpolate( cube[ 0, 1, 0 ], cube[ 1, 1, 0 ], r[ 0 ] ), 
                    r[ 1 ] ),
                interpolate( 
                    interpolate( cube[ 0, 0, 1 ], cube[ 1, 0, 1 ], r[ 0 ] ),
                    interpolate( cube[ 0, 1, 1 ], cube[ 1, 1, 1 ], r[ 0 ] ), 
                    r[ 1 ] ), 
                r[ 2 ] ) 
            )

class Grid:

    projections = { 'x' : 0, 'y' : 1, 'z' : 2 }

    def __init__( self, dimensions = [ 1, 1, 1 ] ):
        self.filename = None
        self.poscar = poscar.Poscar()
        self.number_of_header_lines = 0
        self.dimensions = dimensions
        self.spacing = np.array( [ 1.0 / number_of_points for number_of_points in self.dimensions ] )
        self.grid = np.zeros( self.dimensions )

    def read_from_filename( self, filename ):
        self.filename = filename
        self.poscar = poscar.Poscar()
        self.poscar.read_from( self.filename )

        self.number_of_header_lines = sum( self.poscar.atom_numbers ) + poscar.Poscar.lines_offset