/*-----------------------------tb_energy.c-----------------------------
  This simply evaluates the potential energy of a structure according
  to the Tersoff-Brenner potential and outputs the answer to standard
  output. 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;
  double nrg;
  cell C;
  if(argc != 2) {
    printf("Usage: energy 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
  nrg = energy(C.bond_array, C.bonds);
  printf("tb_energy\t%s\t%f\n", argv[1], nrg);
  fclose(infile);            
  destroy_cell(&C);                    //de-allocate memory
  return EXIT_SUCCESS;
}






