git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@7017 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
@ -13,9 +13,7 @@
|
|||||||
|
|
||||||
// Convert a LAMMPS binary restart file into an ASCII text data file
|
// Convert a LAMMPS binary restart file into an ASCII text data file
|
||||||
//
|
//
|
||||||
// Syntax: restart2data switch arg ... restart-file data-file (input-file)
|
// Syntax: restart2data restart-file data-file (input-file)
|
||||||
// optional switch = -s
|
|
||||||
// arg = suffix to remove from style names
|
|
||||||
// restart-file and data-file are mandatory
|
// restart-file and data-file are mandatory
|
||||||
// input-file is optional
|
// input-file is optional
|
||||||
// if specified it will contain LAMMPS input script commands
|
// if specified it will contain LAMMPS input script commands
|
||||||
@ -80,7 +78,6 @@ class Data {
|
|||||||
|
|
||||||
char *version;
|
char *version;
|
||||||
int size_smallint,size_tagint,size_bigint;
|
int size_smallint,size_tagint,size_bigint;
|
||||||
char *suffix;
|
|
||||||
bigint ntimestep;
|
bigint ntimestep;
|
||||||
int nprocs;
|
int nprocs;
|
||||||
char *unit_style;
|
char *unit_style;
|
||||||
@ -316,7 +313,7 @@ int atom_molecular(double *, Data &, int);
|
|||||||
int atom_peri(double *, Data &, int);
|
int atom_peri(double *, Data &, int);
|
||||||
int atom_sphere(double *, Data &, int);
|
int atom_sphere(double *, Data &, int);
|
||||||
|
|
||||||
void strip_suffix(char *, char *);
|
void strip_suffix(char *);
|
||||||
|
|
||||||
int read_int(FILE *fp);
|
int read_int(FILE *fp);
|
||||||
double read_double(FILE *fp);
|
double read_double(FILE *fp);
|
||||||
@ -331,29 +328,16 @@ int main (int narg, char **arg)
|
|||||||
{
|
{
|
||||||
// process command-line args
|
// process command-line args
|
||||||
|
|
||||||
char *suffix = NULL;
|
|
||||||
|
|
||||||
int iarg = 1;
|
int iarg = 1;
|
||||||
while (iarg < narg) {
|
if (strcmp(arg[iarg],"-h") == 0) {
|
||||||
if (strcmp(arg[iarg],"-h") == 0) {
|
printf("Syntax: restart2data switch arg ... "
|
||||||
printf("Syntax: restart2data switch arg ... "
|
"restart-file data-file (input-file)\n");
|
||||||
"restart-file data-file (input-file)\n");
|
printf(" restart-file and data-file are mandatory");
|
||||||
printf(" optional switch = -s");
|
printf(" input-file is optional");
|
||||||
printf(" arg = suffix to remove from style names");
|
printf(" if specified it will contain LAMMPS input script commands");
|
||||||
printf(" restart-file and data-file are mandatory");
|
printf(" for mass and force field info");
|
||||||
printf(" input-file is optional");
|
printf(" only a few force field styles support this option");
|
||||||
printf(" if specified it will contain LAMMPS input script commands");
|
return 0;
|
||||||
printf(" for mass and force field info");
|
|
||||||
printf(" only a few force field styles support this option");
|
|
||||||
} else if (strcmp(arg[iarg],"-s") == 0) {
|
|
||||||
if (iarg+2 > narg) {
|
|
||||||
printf("Syntax: restart2data switch arg ... "
|
|
||||||
"restart-file data-file (input-file)\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
suffix = arg[iarg+1];
|
|
||||||
iarg += 2;
|
|
||||||
} else break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((narg-iarg != 2) && (narg-iarg != 3)) {
|
if ((narg-iarg != 2) && (narg-iarg != 3)) {
|
||||||
@ -377,7 +361,7 @@ int main (int narg, char **arg)
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
int multiproc = 0;
|
int multiproc = 0;
|
||||||
if (ptr = strchr(restartfile,'%')) {
|
if ( (ptr = strchr(restartfile,'%')) ) {
|
||||||
multiproc = 1;
|
multiproc = 1;
|
||||||
char *basefile = new char[strlen(restartfile) + 16];
|
char *basefile = new char[strlen(restartfile) + 16];
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
@ -399,12 +383,6 @@ int main (int narg, char **arg)
|
|||||||
|
|
||||||
Data data;
|
Data data;
|
||||||
|
|
||||||
if (suffix) {
|
|
||||||
int n = strlen(suffix) + 1;
|
|
||||||
data.suffix = new char[n];
|
|
||||||
strcpy(data.suffix,suffix);
|
|
||||||
} else data.suffix = NULL;
|
|
||||||
|
|
||||||
header(fp,data);
|
header(fp,data);
|
||||||
if (data.size_smallint != sizeof(int) ||
|
if (data.size_smallint != sizeof(int) ||
|
||||||
data.size_tagint != sizeof(tagint) ||
|
data.size_tagint != sizeof(tagint) ||
|
||||||
@ -500,7 +478,7 @@ int main (int narg, char **arg)
|
|||||||
|
|
||||||
void header(FILE *fp, Data &data)
|
void header(FILE *fp, Data &data)
|
||||||
{
|
{
|
||||||
char *version = "25 Jun 2011";
|
char *version = "19 Aug 2011";
|
||||||
|
|
||||||
data.triclinic = 0;
|
data.triclinic = 0;
|
||||||
|
|
||||||
@ -551,7 +529,7 @@ void header(FILE *fp, Data &data)
|
|||||||
data.style_molecular = data.style_peri = data.style_sphere = 0;
|
data.style_molecular = data.style_peri = data.style_sphere = 0;
|
||||||
|
|
||||||
data.atom_style = read_char(fp);
|
data.atom_style = read_char(fp);
|
||||||
strip_suffix(data.atom_style,data.suffix);
|
strip_suffix(data.atom_style);
|
||||||
set_style(data.atom_style,data,1);
|
set_style(data.atom_style,data,1);
|
||||||
|
|
||||||
if (strcmp(data.atom_style,"hybrid") == 0) {
|
if (strcmp(data.atom_style,"hybrid") == 0) {
|
||||||
@ -641,7 +619,6 @@ void groups(FILE *fp)
|
|||||||
{
|
{
|
||||||
int ngroup = read_int(fp);
|
int ngroup = read_int(fp);
|
||||||
|
|
||||||
int n;
|
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
// use count to not change restart format with deleted groups
|
// use count to not change restart format with deleted groups
|
||||||
@ -698,23 +675,23 @@ void force_fields(FILE *fp, Data &data)
|
|||||||
|
|
||||||
if (flag == PAIR) {
|
if (flag == PAIR) {
|
||||||
data.pair_style = read_char(fp);
|
data.pair_style = read_char(fp);
|
||||||
strip_suffix(data.pair_style,data.suffix);
|
strip_suffix(data.pair_style);
|
||||||
pair(fp,data,data.pair_style,1);
|
pair(fp,data,data.pair_style,1);
|
||||||
} else if (flag == BOND) {
|
} else if (flag == BOND) {
|
||||||
data.bond_style = read_char(fp);
|
data.bond_style = read_char(fp);
|
||||||
strip_suffix(data.bond_style,data.suffix);
|
strip_suffix(data.bond_style);
|
||||||
bond(fp,data);
|
bond(fp,data);
|
||||||
} else if (flag == ANGLE) {
|
} else if (flag == ANGLE) {
|
||||||
data.angle_style = read_char(fp);
|
data.angle_style = read_char(fp);
|
||||||
strip_suffix(data.angle_style,data.suffix);
|
strip_suffix(data.angle_style);
|
||||||
angle(fp,data);
|
angle(fp,data);
|
||||||
} else if (flag == DIHEDRAL) {
|
} else if (flag == DIHEDRAL) {
|
||||||
data.dihedral_style = read_char(fp);
|
data.dihedral_style = read_char(fp);
|
||||||
strip_suffix(data.dihedral_style,data.suffix);
|
strip_suffix(data.dihedral_style);
|
||||||
dihedral(fp,data);
|
dihedral(fp,data);
|
||||||
} else if (flag == IMPROPER) {
|
} else if (flag == IMPROPER) {
|
||||||
data.improper_style = read_char(fp);
|
data.improper_style = read_char(fp);
|
||||||
strip_suffix(data.improper_style,data.suffix);
|
strip_suffix(data.improper_style);
|
||||||
improper(fp,data);
|
improper(fp,data);
|
||||||
} else {
|
} else {
|
||||||
printf("ERROR: Invalid flag in force fields section of restart file %d\n",
|
printf("ERROR: Invalid flag in force fields section of restart file %d\n",
|
||||||
@ -3330,7 +3307,7 @@ void Data::write(FILE *fp, FILE *fp2)
|
|||||||
fprintf(fp,"\nAtoms\n\n");
|
fprintf(fp,"\nAtoms\n\n");
|
||||||
|
|
||||||
int ix,iy,iz;
|
int ix,iy,iz;
|
||||||
for (uint64_t i = 0; i < natoms; i++) {
|
for (bigint i = 0; i < natoms; i++) {
|
||||||
|
|
||||||
ix = (image[i] & 1023) - 512;
|
ix = (image[i] & 1023) - 512;
|
||||||
iy = (image[i] >> 10 & 1023) - 512;
|
iy = (image[i] >> 10 & 1023) - 512;
|
||||||
@ -3371,7 +3348,7 @@ void Data::write(FILE *fp, FILE *fp2)
|
|||||||
|
|
||||||
if (natoms) {
|
if (natoms) {
|
||||||
fprintf(fp,"\nVelocities\n\n");
|
fprintf(fp,"\nVelocities\n\n");
|
||||||
for (uint64_t i = 0; i < natoms; i++)
|
for (bigint i = 0; i < natoms; i++)
|
||||||
|
|
||||||
if (style_hybrid == 0) {
|
if (style_hybrid == 0) {
|
||||||
if (style_angle) write_vel_angle(fp,i);
|
if (style_angle) write_vel_angle(fp,i);
|
||||||
@ -3406,7 +3383,7 @@ void Data::write(FILE *fp, FILE *fp2)
|
|||||||
|
|
||||||
if (nellipsoids) {
|
if (nellipsoids) {
|
||||||
fprintf(fp,"\nEllipsoids\n\n");
|
fprintf(fp,"\nEllipsoids\n\n");
|
||||||
for (uint64_t i = 0; i < natoms; i++) {
|
for (bigint i = 0; i < natoms; i++) {
|
||||||
if (ellipsoid[i])
|
if (ellipsoid[i])
|
||||||
fprintf(fp,"%d %-1.16e %-1.16e %-1.16e "
|
fprintf(fp,"%d %-1.16e %-1.16e %-1.16e "
|
||||||
"%-1.16e %-1.16e %-1.16e %-1.16e \n",
|
"%-1.16e %-1.16e %-1.16e %-1.16e \n",
|
||||||
@ -3417,21 +3394,21 @@ void Data::write(FILE *fp, FILE *fp2)
|
|||||||
|
|
||||||
if (nbonds) {
|
if (nbonds) {
|
||||||
fprintf(fp,"\nBonds\n\n");
|
fprintf(fp,"\nBonds\n\n");
|
||||||
for (uint64_t i = 0; i < nbonds; i++)
|
for (bigint i = 0; i < nbonds; i++)
|
||||||
fprintf(fp,BIGINT_FORMAT " %d %d %d\n",
|
fprintf(fp,BIGINT_FORMAT " %d %d %d\n",
|
||||||
i+1,bond_type[i],bond_atom1[i],bond_atom2[i]);
|
i+1,bond_type[i],bond_atom1[i],bond_atom2[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nangles) {
|
if (nangles) {
|
||||||
fprintf(fp,"\nAngles\n\n");
|
fprintf(fp,"\nAngles\n\n");
|
||||||
for (uint64_t i = 0; i < nangles; i++)
|
for (bigint i = 0; i < nangles; i++)
|
||||||
fprintf(fp,BIGINT_FORMAT " %d %d %d %d\n",
|
fprintf(fp,BIGINT_FORMAT " %d %d %d %d\n",
|
||||||
i+1,angle_type[i],angle_atom1[i],angle_atom2[i],angle_atom3[i]);
|
i+1,angle_type[i],angle_atom1[i],angle_atom2[i],angle_atom3[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ndihedrals) {
|
if (ndihedrals) {
|
||||||
fprintf(fp,"\nDihedrals\n\n");
|
fprintf(fp,"\nDihedrals\n\n");
|
||||||
for (uint64_t i = 0; i < ndihedrals; i++)
|
for (bigint i = 0; i < ndihedrals; i++)
|
||||||
fprintf(fp,BIGINT_FORMAT " %d %d %d %d %d\n",
|
fprintf(fp,BIGINT_FORMAT " %d %d %d %d %d\n",
|
||||||
i+1,dihedral_type[i],dihedral_atom1[i],dihedral_atom2[i],
|
i+1,dihedral_type[i],dihedral_atom1[i],dihedral_atom2[i],
|
||||||
dihedral_atom3[i],dihedral_atom4[i]);
|
dihedral_atom3[i],dihedral_atom4[i]);
|
||||||
@ -3439,7 +3416,7 @@ void Data::write(FILE *fp, FILE *fp2)
|
|||||||
|
|
||||||
if (nimpropers) {
|
if (nimpropers) {
|
||||||
fprintf(fp,"\nImpropers\n\n");
|
fprintf(fp,"\nImpropers\n\n");
|
||||||
for (uint64_t i = 0; i < nimpropers; i++)
|
for (bigint i = 0; i < nimpropers; i++)
|
||||||
fprintf(fp,BIGINT_FORMAT " %d %d %d %d %d\n",
|
fprintf(fp,BIGINT_FORMAT " %d %d %d %d %d\n",
|
||||||
i+1,improper_type[i],improper_atom1[i],improper_atom2[i],
|
i+1,improper_type[i],improper_atom1[i],improper_atom2[i],
|
||||||
improper_atom3[i],improper_atom4[i]);
|
improper_atom3[i],improper_atom4[i]);
|
||||||
@ -3509,7 +3486,7 @@ void Data::write_atom_molecular(FILE *fp, int i, int ix, int iy, int iz)
|
|||||||
|
|
||||||
void Data::write_atom_peri(FILE *fp, int i, int ix, int iy, int iz)
|
void Data::write_atom_peri(FILE *fp, int i, int ix, int iy, int iz)
|
||||||
{
|
{
|
||||||
fprintf(fp,"%d %d %-1.16e %-1.16e %-1.16e %-1.16e %-1.16e %-1.16e %d %d %d",
|
fprintf(fp,"%d %d %-1.16e %-1.16e %-1.16e %-1.16e %-1.16e %d %d %d",
|
||||||
tag[i],type[i],vfrac[i],rmass[i],x[i],y[i],z[i],ix,iy,iz);
|
tag[i],type[i],vfrac[i],rmass[i],x[i],y[i],z[i],ix,iy,iz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3562,7 +3539,7 @@ void Data::write_atom_molecular_extra(FILE *fp, int i)
|
|||||||
|
|
||||||
void Data::write_atom_peri_extra(FILE *fp, int i)
|
void Data::write_atom_peri_extra(FILE *fp, int i)
|
||||||
{
|
{
|
||||||
fprintf(fp," %-1.16e %-1.16e %-1.16e",vfrac[i],rmass[i]);
|
fprintf(fp," %-1.16e %-1.16e",vfrac[i],rmass[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
@ -3649,17 +3626,26 @@ void Data::write_vel_molecular_extra(FILE *fp, int i) {}
|
|||||||
void Data::write_vel_peri_extra(FILE *fp, int i) {}
|
void Data::write_vel_peri_extra(FILE *fp, int i) {}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// strip suffix from style name if suffix is defined
|
// strip known accelerator suffixes from style name
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
void strip_suffix(char *style, char *suffix)
|
void strip_suffix(char *style)
|
||||||
{
|
{
|
||||||
if (!suffix) return;
|
char *slash = strrchr(style,'/');
|
||||||
int n = strlen(suffix) + 2;
|
if (slash == NULL) return;
|
||||||
char *esuffix = new char[n];
|
|
||||||
sprintf(esuffix,"/%s",suffix);
|
int i=0;
|
||||||
char *ptr = strstr(style,esuffix);
|
|
||||||
if (ptr && ptr-style+1+strlen(suffix) == strlen(style)) *ptr = '\0';
|
const char *suffix_list[] = { "/opt", "/gpu", "/cuda", "/omp", NULL };
|
||||||
|
const char *suffix = suffix_list[0];
|
||||||
|
while (suffix != NULL) {
|
||||||
|
if (strcmp(slash,suffix) == 0) {
|
||||||
|
*slash = '\0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
suffix = suffix_list[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user