git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@10150 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp 2013-06-28 16:55:37 +00:00
parent 388c4d9cd6
commit 737e5e6c3d
22 changed files with 159 additions and 23 deletions

View File

@ -545,7 +545,7 @@ void PairADP::read_file(char *filename)
char line[MAXLINE];
if (me == 0) {
fp = fopen(filename,"r");
fp = open_potential(filename);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open ADP potential file %s",filename);

View File

@ -3333,7 +3333,7 @@ void PairAIREBO::read_file(char *filename)
// read file on proc 0
if (me == 0) {
FILE *fp = fopen(filename,"r");
FILE *fp = open_potential(filename);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open AIREBO potential file %s",filename);

View File

@ -8210,7 +8210,7 @@ void PairBOP::read_file(char *filename)
rcore=0.1;
if (me == 0) {
FILE *fp = fopen(filename,"r");
FILE *fp = open_potential(filename);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open BOP potential file %s",filename);
@ -8270,7 +8270,7 @@ void PairBOP::read_file(char *filename)
if (me == 0) {
words = new char*[bop_types];
for(i=0;i<bop_types;i++) words[i]=NULL;
FILE *fp = fopen(filename,"r");
FILE *fp = open_potential(filename);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open BOP potential file %s",filename);
@ -8434,7 +8434,7 @@ void PairBOP::read_table(char *filename)
MPI_Comm_rank(world,&me);
if (me == 0) {
FILE *fp = fopen(filename,"r");
FILE *fp = open_potential(filename);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open BOP potential file %s",filename);
@ -8483,7 +8483,7 @@ void PairBOP::read_table(char *filename)
allocate();
if (me == 0) {
FILE *fp = fopen(filename,"r");
FILE *fp = open_potential(filename);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open BOP potential file %s",filename);

View File

@ -572,7 +572,7 @@ void PairComb::read_file(char *file)
FILE *fp;
if (comm->me == 0) {
fp = fopen(file,"r");
fp = open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open COMB potential file %s",file);

View File

@ -439,7 +439,7 @@ void PairEAM::read_file(char *filename)
char line[MAXLINE];
if (me == 0) {
fptr = fopen(filename,"r");
fptr = open_potential(filename);
if (fptr == NULL) {
char str[128];
sprintf(str,"Cannot open EAM potential file %s",filename);

View File

@ -122,7 +122,7 @@ void PairEAMAlloy::read_file(char *filename)
char line[MAXLINE];
if (me == 0) {
fptr = fopen(filename,"r");
fptr = open_potential(filename);
if (fptr == NULL) {
char str[128];
sprintf(str,"Cannot open EAM potential file %s",filename);

View File

@ -122,7 +122,7 @@ void PairEAMFS::read_file(char *filename)
char line[MAXLINE];
if (me == 0) {
fptr = fopen(filename,"r");
fptr = open_potential(filename);
if (fptr == NULL) {
char str[128];
sprintf(str,"Cannot open EAM potential file %s",filename);

View File

@ -457,7 +457,7 @@ void PairEIM::read_file(char *filename)
FILE *fptr;
if (me == 0) {
fptr = fopen(filename,"r");
fptr = open_potential(filename);
if (fptr == NULL) {
char str[128];
sprintf(str,"Cannot open EIM potential file %s",filename);

View File

@ -984,7 +984,7 @@ void PairLCBOP::read_file(char *filename)
// read file on proc 0
if (me == 0) {
FILE *fp = fopen(filename,"r");
FILE *fp = open_potential(filename);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open LCBOP potential file %s",filename);

View File

@ -336,7 +336,7 @@ void PairSW::read_file(char *file)
FILE *fp;
if (comm->me == 0) {
fp = fopen(file,"r");
fp = open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open Stillinger-Weber potential file %s",file);

View File

@ -376,7 +376,7 @@ void PairTersoff::read_file(char *file)
FILE *fp;
if (comm->me == 0) {
fp = fopen(file,"r");
fp = open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open Tersoff potential file %s",file);

View File

@ -74,7 +74,7 @@ void PairTersoffZBL::read_file(char *file)
FILE *fp;
if (comm->me == 0) {
fp = fopen(file,"r");
fp = open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open Tersoff potential file %s",file);

View File

@ -461,7 +461,7 @@ void PairCDEAM::read_h_coeff(char *filename)
FILE *fp;
char line[MAXLINE];
char nextline[MAXLINE];
fp = fopen(filename,"r");
fp = open_potential(filename);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open EAM potential file %s", filename);

View File

@ -879,7 +879,7 @@ void PairEDIP::read_file(char *file)
FILE *fp;
if (comm->me == 0) {
fp = fopen(file,"r");
fp = open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open EDIP potential file %s",file);

View File

@ -434,7 +434,7 @@ void PairMEAMSpline::coeff(int narg, char **arg)
void PairMEAMSpline::read_file(const char* filename)
{
if(comm->me == 0) {
FILE *fp = fopen(filename, "r");
FILE *fp = open_potential(filename);
if(fp == NULL) {
char str[1024];
sprintf(str,"Cannot open spline MEAM potential file %s", filename);

View File

@ -463,7 +463,7 @@ void PairMEAMSWSpline::coeff(int narg, char **arg)
void PairMEAMSWSpline::read_file(const char* filename)
{
if(comm->me == 0) {
FILE *fp = fopen(filename, "r");
FILE *fp = open_potential(filename);
if(fp == NULL) {
char str[1024];
sprintf(str,"Cannot open spline MEAM potential file %s", filename);

View File

@ -857,7 +857,7 @@ void PairTersoffTable::read_file(char *file)
FILE *fp;
if (comm->me == 0) {
fp = fopen(file,"r");
fp = open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open Tersoff potential file %s",file);

View File

@ -121,7 +121,7 @@ void PairEAMAlloyOMP::read_file(char *filename)
char line[MAXLINE];
if (me == 0) {
fptr = fopen(filename,"r");
fptr = open_potential(filename);
if (fptr == NULL) {
char str[128];
sprintf(str,"Cannot open EAM potential file %s",filename);

View File

@ -121,7 +121,7 @@ void PairEAMFSOMP::read_file(char *filename)
char line[MAXLINE];
if (me == 0) {
fptr = fopen(filename,"r");
fptr = open_potential(filename);
if (fptr == NULL) {
char str[128];
sprintf(str,"Cannot open EAM potential file %s",filename);

View File

@ -94,7 +94,7 @@ void PairTersoffZBLOMP::read_file(char *file)
FILE *fp;
if (comm->me == 0) {
fp = fopen(file,"r");
fp = open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open Tersoff potential file %s",file);

View File

@ -16,6 +16,7 @@
------------------------------------------------------------------------- */
#include "mpi.h"
#include "ctype.h"
#include "float.h"
#include "limits.h"
#include "math.h"
@ -1613,6 +1614,71 @@ void Pair::init_bitmap(double inner, double outer, int ntablebits,
masklo = rsq_lookup.i & ~(nmask);
}
/* ----------------------------------------------------------------------
open a potential file as specified
failing that, search in dir specified by env variable LAMMPS_POTENTIALS
------------------------------------------------------------------------- */
FILE *Pair::open_potential(const char *name)
{
FILE *fp;
// attempt to open file directly
// if successful, return ptr
fp = fopen(name,"r");
if (fp) return fp;
// try the environment variable directory
const char *path = getenv("LAMMPS_POTENTIALS");
if (path == NULL) return NULL;
const char *pot = potname(name);
size_t len1 = strlen(path);
size_t len2 = strlen(pot);
char *newpath = new char[len1+len2];
strcpy(newpath,path);
#if defined(_WIN32)
newpath[len1] = '\\';
newpath[len1+1] = 0;
#else
newpath[len1] = '/';
newpath[len1+1] = 0;
#endif
strcat(newpath,pot);
fp = fopen(newpath,"r");
delete[] newpath;
return fp;
}
/* ----------------------------------------------------------------------
strip off leading part of path, return just the filename
------------------------------------------------------------------------- */
const char *Pair::potname(const char *path)
{
const char *pot;
#if defined(_WIN32)
// skip over the disk drive part of windows pathnames
if (isalpha(path[0]) && path[1] == ':')
path += 2;
#endif
for (pot = path; *path != '\0'; ++path) {
#if defined(_WIN32)
if ((*path == '\\') || (*path == '/')) pot = path + 1;
#else
if (*path == '/') pot = path + 1;
#endif
}
return pot;
}
/* ---------------------------------------------------------------------- */
double Pair::memory_usage()
@ -1621,3 +1687,68 @@ double Pair::memory_usage()
bytes += comm->nthreads*maxvatom*6 * sizeof(double);
return bytes;
}
/* ---------------------------------------------------------------------- */
// helper function to strip off leading part of the path
#include <ctype.h>
static const char *potname(const char *path)
{
const char *pot;
#if defined(_WIN32)
/* Skip over the disk drive part in windows pathnames */
if (isalpha(path[0]) && path[1] == ':')
path += 2;
#endif
for (pot = path; *path != NULL; ++path) {
#if defined(_WIN32)
if ((*path == '\\') || (*path == '/'))
pot = path + 1;
#else
if (*path == '/')
pot = path + 1;
#endif
}
return pot;
}
/* this subroutine will try to fopen(3) a potential file in the provided
path, but failing that, it will search in a directory pointed to by
the environment variable LAMMPS_POTENTIALS */
FILE *LAMMPS_NS::open_potential(const char *name)
{
FILE *fp;
// try to open file directly and return pointer, if successful.
fp = fopen(name,"r");
if (fp) return fp;
// direct open failed, now try the directory from the environment.
const char *path = getenv("LAMMPS_POTENTIALS");
if (path == NULL) return NULL;
const char *pot = potname(name);
size_t len1 = strlen(path);
size_t len2 = strlen(pot);
char *newpath = new char[len1+len2];
strcpy(newpath,path);
#if defined(_WIN32)
newpath[len1] = '\\';
newpath[len1+1] = 0;
#else
newpath[len1] = '/';
newpath[len1+1] = 0;
#endif
strcat(newpath,pot);
// now try new path.
fp = fopen(newpath,"r");
delete[] newpath;
return fp;
}

View File

@ -208,11 +208,16 @@ class Pair : protected Pointers {
double, double, double, double, double, double);
void virial_fdotr_compute();
FILE *open_potential(const char *);
const char *potname(const char *);
inline int sbmask(int j) {
return j >> SBBITS & 3;
}
};
// fopen wrapper that also looks in $LAMMPS_POTENTIALS for potential files
FILE *open_potential(const char *);
}
#endif