/*-----------------------------tb_force.c------------------------------
  This evaluates the forces on the atoms by numerically differentiating
  the Tersoff-Brenner potential. This software was written by Stephen
  Jordan.
  ---------------------------------------------------------------------*/

#include "cell.h"                //for Cell  
#include "abcio.h"               //for loadabc
#include "potential.h"           //for energy
#include <stdio.h>               //for printf, fopen, FILE
#include <stdlib.h>              //for EXIT_SUCCESS and EXIT_FAILURE


int main(int argc, char *argv[]) {
  FILE *infile;
  int loaded;
  int atom;
  cell C;
  if(argc != 2) {
    printf("Usage: tb_force molecule.abc\n");
    return EXIT_FAILURE;
  }
  infile = fopen(argv[1],"r");
  if(infile == NULL) {
    printf("Unable to open %s\n", argv[1]);
    return EXIT_FAILURE;
  }
  loadabc(infile, &C, 0);          //load structure + allocate RAM
  tbinit(&C, 0);                   //prepare bond_array
  nftb(&C);                        //calculate the tersoff-brenner forces
  for(atom = 0; atom < C.atoms; atom++) {
    printf("tb force\t%i\t%f\t%f\t%f\n", atom, C.atom_array[atom].f_tb[0],
                                               C.atom_array[atom].f_tb[1],
                                               C.atom_array[atom].f_tb[2]);
  }
  fclose(infile);            
  destroy_cell(&C);                    //de-allocate memory
  return EXIT_SUCCESS;
}






