/*----------------------------cell.h-------------------------------
  This file defines data structures used throughout the tbtools
  package. This software was written by Stephen Jordan.
  -----------------------------------------------------------------*/

#ifndef _CELL_H

//this contains the information loaded from the abc file
typedef struct {
  int type;                   //(carbon = 1, hydrogen = 2)
  int neighbs;                //the number of atoms connected
  int neighbs2;               //number of 1st + 2nd neighbors
  int neighb_i[5];            //the other atoms it is connected to
  struct bnd *neighb_b[5];    //the bonds to those atoms
  struct bnd *neighb_b2[25];  //also second neighbors
  double *x;                  //position
  double *f_tb;               //tersoff-brenner force
  double *f_x;                //external force
}atom;

//It is assumed that no atom has more than 5 bonds. Thus the bond has a total of
//no more than 8 external bonds.
typedef struct bnd {
  //Basic information that is calculated only once------------------------------- 
  atom *bond_atom[2];         //an array of two pointers to the two atoms
  int neighbs[3];             //number of bonds of atom [0 = i, 1 = j, 2 = total]
  atom *neighb_a[3][5];       //[0 = atom i, 1 = atom j, 2 = total][neighbor #]
  struct bnd *neighb_b[3][5]; //[0 = atom i, 1 = atom j, 2 = total][neighbor #]
  //Constants that depend only on types (Carbon, Hydrogen)-----------------------
  double Dmin;                //for fc
  double Dmax;                //for fc
  double Q;                   //for VR
  double A;                   //for VR
  double alpha;               //for VR
  double B[3];                //for VA
  double beta[3];             //for VA
  double XDB[2][4];           //[0 = i, 1 = j][neighbor #], from thesis
  double REG[2][4];           //[0 = i, 1 = j][neighbor #], from thesis
  //Information that changes only if fc changes---------------------------------
  double N[2][3];             //[0 = i, 1 = j][0 = T, 1 = C, 2 = H]
  double Nconj;               //bond conjugation
  double F[2];                //conjugation cutoff for each atom
  double Pij[2];              //[0 = ij, 1 = ji], spline
  double Fij;                 //spline
  double Tij;                 //spline
  //Information that changes as the atoms move----------------------------------
  double dx[3];               //difference in position vectors of the two atoms
  double r;                   //bond length
  double fc;                  //cutoff function
  double theta[4][4];         //[neighb # of i][neighb # of j]
  double bDH;                 //an energy dependent on the bond twist 
  double bpi;                 //one component of the bond order
  double W[2][4];             //[0 = i][1 = j][neighbor #], from thesis
  double costh[2][4];         //cosines of bond angles with neighboring bonds
  double S[2];                //[0 = ij, 1 = ji]from thesis
  double G[2][4];             //[0 = i, 1 = j][neighb #], spline
  double bsigmapi[2];         //[0 = ij, 1, = ji] b super sigma-pi
  double bbar;                //the bond order
  double VR;                  //repulsive potential
  double VA;                  //attractive potential
  double E;                   //the energy
}bond;

typedef struct {
  int atoms;       // # of atoms in the cell
  int bonds;       // # of chemical bonds
  int allocated;   // 1 = yes, 0 = no
  atom *atom_array;
  bond *bond_array;
  double *x;
  double *f_tb;
  double *f_x;
}cell;

#endif
#define _CELL_H
