improved whitespace handling in msi2lmp for force fields and topologies

This commit is contained in:
Axel Kohlmeyer
2016-10-06 11:16:59 -04:00
parent 4921dc18a0
commit 22ce671804
5 changed files with 27 additions and 17 deletions

View File

@ -1,13 +1,18 @@
Axel Kohlmeyer is the current maintainer of the msi2lmp tool. Axel Kohlmeyer is the current maintainer of the msi2lmp tool.
Please send any inquiries about msi2lmp to the lammps-users mailing list. Please send any inquiries about msi2lmp to the lammps-users mailing list.
06 Oct 2016 Axel Kohlmeyer <akohlmey@gmail.com>
Improved whitespace handling in parsing topology and force field
files to avoid bogus warnings about type name truncation.
24 Oct 2015 Axel Kohlmeyer <akohlmey@gmail.com> 24 Oct 2015 Axel Kohlmeyer <akohlmey@gmail.com>
Added check to make certain that force field files Added check to make certain that force field files
are consistent with the notation of non-bonded parameters are consistent with the notation of non-bonded parameters
that the msi2lmp code expects. For Class 1 and OPLS-AA that the msi2lmp code expects. For Class 1 and OPLS-AA
the A-B notation with geometric mixing is expected and for the A-B notation with geometric mixing is expected and for
Class 2 the r-eps notation with sixthpower mixing.( Class 2 the r-eps notation with sixthpower mixing.
11 Sep 2014 Axel Kohlmeyer <akohlmey@gmail.com> 11 Sep 2014 Axel Kohlmeyer <akohlmey@gmail.com>

View File

@ -74,9 +74,9 @@ void ReadMdfFile(void)
at_end = 1; at_end = 1;
} else if (strncmp(line,"@column",7) == 0) { } else if (strncmp(line,"@column",7) == 0) {
temp_string = strtok(line," "); temp_string = strtok(line,WHITESPACE);
col_no = strtok(NULL," "); col_no = strtok(NULL,WHITESPACE);
col_name = strtok(NULL," "); col_name = strtok(NULL,WHITESPACE);
if (strncmp(col_name,"charge",6) == 0) { if (strncmp(col_name,"charge",6) == 0) {
if (strlen(col_name) < 8) { if (strlen(col_name) < 8) {
q_col_no = atoi(col_no); q_col_no = atoi(col_no);
@ -285,7 +285,7 @@ int get_molecule(char *line, int connect_col_no, int q_col_no,
/* Get atom name */ /* Get atom name */
cur_field = strtok(line,":"); cur_field = strtok(line,":");
sscanf(cur_field, "%s", atoms[*counter].residue_string); sscanf(cur_field, "%s", atoms[*counter].residue_string);
cur_field = strtok(NULL," "); cur_field = strtok(NULL,WHITESPACE);
/* Compare atom name with that in .car file */ /* Compare atom name with that in .car file */
if (strcmp(atoms[*counter].name, cur_field)) { if (strcmp(atoms[*counter].name, cur_field)) {
printf("Names %s from .car file and %s from .mdf file do not match\n", printf("Names %s from .car file and %s from .mdf file do not match\n",
@ -297,18 +297,18 @@ int get_molecule(char *line, int connect_col_no, int q_col_no,
/* Skip unwanted fields until charge column, then update charge */ /* Skip unwanted fields until charge column, then update charge */
for (i=1; i < q_col_no; i++) strtok(NULL," "); for (i=1; i < q_col_no; i++) strtok(NULL,WHITESPACE);
cur_field = strtok(NULL, " "); cur_field = strtok(NULL, WHITESPACE);
atoms[*counter].q = atof(cur_field); atoms[*counter].q = atof(cur_field);
/* Continue skipping unwanted fields until connectivity records begin */ /* Continue skipping unwanted fields until connectivity records begin */
for ( i = (q_col_no + 1); i < connect_col_no; i++) strtok(NULL," "); for ( i = (q_col_no + 1); i < connect_col_no; i++) strtok(NULL,WHITESPACE);
/* Process connections */ /* Process connections */
connect_no = 0; /* reset connections counter */ connect_no = 0; /* reset connections counter */
while ((cur_field = strtok(NULL," ")) && (connect_no < MAX_CONNECTIONS)) { while ((cur_field = strtok(NULL,WHITESPACE)) && (connect_no < MAX_CONNECTIONS)) {
sscanf(cur_field, "%s", atoms[*counter].connections[connect_no++]); sscanf(cur_field, "%s", atoms[*counter].connections[connect_no++]);
} }
atoms[*counter].no_connect = connect_no; atoms[*counter].no_connect = connect_no;

View File

@ -45,9 +45,9 @@ const char *SearchAndCheck(const char *keyword)
exit(1); exit(1);
} }
if (line[0] == '@') { if (line[0] == '@') {
if (string_match(strtok(line+1," '\t\n'("),keyword)) { if (string_match(strtok(line+1," '\t\n\r\f("),keyword)) {
got_it = 1; got_it = 1;
status = strtok(NULL," '\t\n("); status = strtok(NULL," '\t\n\r\f(");
if (status != NULL) if (status != NULL)
return strdup(status); return strdup(status);
} }
@ -79,7 +79,7 @@ void SearchAndFill(struct FrcFieldItem *item)
exit(1); exit(1);
} }
if (line[0] == '#') { if (line[0] == '#') {
if (string_match(strtok(line," '\t'("),item->keyword)) got_it = 1; if (string_match(strtok(line," '\t\r\n("),item->keyword)) got_it = 1;
} }
/* if (strncmp(line, item->keyword,strlen(item->keyword))==0) got_it = 1; */ /* if (strncmp(line, item->keyword,strlen(item->keyword))==0) got_it = 1; */
} }
@ -132,13 +132,13 @@ void SearchAndFill(struct FrcFieldItem *item)
/* version number and reference number */ /* version number and reference number */
version = atof(strtok(line, " ")); version = atof(strtok(line, WHITESPACE));
reference = atoi(strtok(NULL, " ")); reference = atoi(strtok(NULL, WHITESPACE));
/* equivalences */ /* equivalences */
for(i = 0; i < item->number_of_members; i++ ) { for(i = 0; i < item->number_of_members; i++ ) {
charptr = strtok(NULL, " "); charptr = strtok(NULL, WHITESPACE);
if (strlen(charptr) > 4) { if (strlen(charptr) > 4) {
fprintf(stderr,"Warning: type name overflow for '%s'. " fprintf(stderr,"Warning: type name overflow for '%s'. "
"Truncating to 4 characters.\n",charptr); "Truncating to 4 characters.\n",charptr);
@ -150,7 +150,7 @@ void SearchAndFill(struct FrcFieldItem *item)
endbontor have to be treated carefully */ endbontor have to be treated carefully */
for( i = 0; i < item->number_of_parameters; i++ ) { for( i = 0; i < item->number_of_parameters; i++ ) {
charptr = strtok(NULL, " "); charptr = strtok(NULL, WHITESPACE);
if(charptr == NULL) { if(charptr == NULL) {
for ( j = i; j < item->number_of_parameters; j++ ) for ( j = i; j < item->number_of_parameters; j++ )
parameters[j] = parameters[j-i]; parameters[j] = parameters[j-i];

View File

@ -2,6 +2,9 @@
* *
* msi2lmp.exe * msi2lmp.exe
* *
* v3.9.8 AK- Improved whitespace handling in parsing topology and force
* field files to avoid bogus warnings about type name truncation
*
* v3.9.7 AK- Add check to enforce that Class1/OPLS-AA use A-B parameter * v3.9.7 AK- Add check to enforce that Class1/OPLS-AA use A-B parameter
* conventions in force field file and Class2 us r-eps conventions * conventions in force field file and Class2 us r-eps conventions
* *

View File

@ -36,7 +36,7 @@
# include <stdio.h> # include <stdio.h>
#define MSI2LMP_VERSION "v3.9.7 / 24 Oct 2015" #define MSI2LMP_VERSION "v3.9.8 / 06 Oct 2016"
#define PI_180 0.01745329251994329576 #define PI_180 0.01745329251994329576
@ -45,6 +45,8 @@
#define MAX_STRING 64 #define MAX_STRING 64
#define MAX_NAME 16 #define MAX_NAME 16
#define WHITESPACE " \t\r\n\f"
#define MAX_ATOM_TYPES 100 #define MAX_ATOM_TYPES 100
#define MAX_BOND_TYPES 200 #define MAX_BOND_TYPES 200
#define MAX_ANGLE_TYPES 300 #define MAX_ANGLE_TYPES 300