--- trunk/mdtools/interface_implementation/TraPPE_ExFF.cpp 2002/11/14 22:00:39 175 +++ trunk/mdtools/interface_implementation/TraPPE_ExFF.cpp 2002/11/14 22:00:44 176 @@ -7,13 +7,13 @@ using namespace std; #include "ForceFields.hpp" #include "SRI.hpp" +#include "simError.h" #ifdef IS_MPI #include "mpiForceField.h" -int myNode; // Declare the structures that will be passed by MPI @@ -26,7 +26,6 @@ typedef struct{ int isDipole; int last; // 0 -> default // 1 -> tells nodes to stop listening - // -1 -> an error has occured. (handled in mpiForceField) } atomStruct; MPI_Datatype mpiAtomStructType; @@ -37,7 +36,6 @@ typedef struct{ double d0; int last; // 0 -> default // 1 -> tells nodes to stop listening - // -1 -> an error has occured. (handled in mpiForceField) } bondStruct; MPI_Datatype mpiBondStructType; @@ -49,7 +47,6 @@ typedef struct{ double k1, k2, k3, t0; int last; // 0 -> default // 1 -> tells nodes to stop listening - // -1 -> an error has occured. (handled in mpiForceField) } bendStruct; MPI_Datatype mpiBendStructType; @@ -62,8 +59,7 @@ typedef struct{ double k1, k2, k3, k4; int last; // 0 -> default // 1 -> tells nodes to stop listening - // -1 -> an error has occured. (handled in mpiForceField) -} TorsionStruct; +} torsionStruct; MPI_Datatype mpiTorsionStructType; #endif @@ -80,12 +76,8 @@ TraPPE_ExFF::TraPPE_ExFF(){ #ifdef IS_MPI int i; - int mpiError; - int cleanOpen = 0; - mpiError = MPI_Comm_rank(MPI_COMM_WORLD,&myNode); - - // ********************************************************************** + // ********************************************************************** // Init the atomStruct mpi type atomStruct atomProto; // mpiPrototype @@ -93,8 +85,6 @@ TraPPE_ExFF::TraPPE_ExFF(){ MPI_Aint atomDspls[3]; // displacements MPI_Datatype atomMbrTypes[3]; // member mpi types - - MPI_Address(&atomProto.name, &atomDspls[0]); MPI_Address(&atomProto.mass, &atomDspls[1]); MPI_Address(&atomProto.isDipole, &atomDspls[2]); @@ -177,7 +167,7 @@ TraPPE_ExFF::TraPPE_ExFF(){ // *********************************************************************** - if( myNode == 0 ){ + if( worldRank == 0 ){ #endif // generate the force file name @@ -195,16 +185,13 @@ TraPPE_ExFF::TraPPE_ExFF(){ ffPath = getenv( ffPath_env ); if( ffPath == NULL ) { - sprintf( errMsg, + sprintf( painCave.errMsg, "Error opening the force field parameter file: %s\n" "Have you tried setting the FORCE_PARAM_PATH environment " "vairable?\n", fileName ); -#ifdef IS_MPI - cleanOpen = 0; - mpiError = MPI_Bcast(cleanOpen,1,MPI_INT,0,MPI_COMM_WORLD); -#endif - ffError( errMsg ); + painCave.isFatal = 1; + simError(); } @@ -217,31 +204,37 @@ TraPPE_ExFF::TraPPE_ExFF(){ if( frcFile == NULL ){ - sprintf( errMsg, + sprintf( painCave.errMsg, "Error opening the force field parameter file: %s\n" "Have you tried setting the FORCE_PARAM_PATH environment " "vairable?\n", fileName ); -#ifdef IS_MPI - cleanOpen = 0; - mpiError = MPI_Bcast(cleanOpen,1,MPI_INT,0,MPI_COMM_WORLD); -#endif - ffError( errMsg ); + painCave.isFatal = 1; + simError(); } } - cleanOpen = 1; + #ifdef IS_MPI } - - mpiError = MPI_Bcast(cleanOpen,1,MPI_INT,0,MPI_COMM_WORLD); - if( !cleanOpen ) fferror( NULL ); -#endif + + sprintf( checkPointMsg, "TraPPE_ExFF file opened sucessfully." ); + MPIcheckPoint(); + +#endif // is_mpi } TraPPE_ExFF::~TraPPE_ExFF(){ - - fclose( frcFile ); + +#ifdef IS_MPI + if( worldRank == 0 ){ +#endif // is_mpi + + fclose( frcFile ); + +#ifdef IS_MPI + } +#endif // is_mpi } void TraPPE_ExFF::initializeAtoms( void ){ @@ -302,8 +295,8 @@ void TraPPE_ExFF::initializeAtoms( void ){ #ifdef IS_MPI atomStruct info; - info.last = -1; // initialize last to have the error set. - // if things go well, last will be set to 0 + info.last = 1; // initialize last to have the last set. + // if things go well, last will be set to 0 #endif @@ -313,7 +306,6 @@ void TraPPE_ExFF::initializeAtoms( void ){ int foundAtom = 0; int lineNum = 0; int i; - char errMsg[1000]; ////////////////////////////////////////////////// @@ -357,7 +349,7 @@ void TraPPE_ExFF::initializeAtoms( void ){ #ifdef IS_MPI - if( myNode == 0 ){ + if( worldRank == 0 ){ #endif // read in the atom types. @@ -369,11 +361,9 @@ void TraPPE_ExFF::initializeAtoms( void ){ eof_test = fgets( readLine, sizeof(readLine), frcFile ); lineNum++; if( eof_test == NULL ){ - sprintf( errMsg, "Error in reading Atoms from force file.\n" ); -#ifdef IS_MPI - sendFrcStruct( &info, mpiAtomStructType ); -#endif - ffError(errMsg); + sprintf( painCave.errMsg, "Error in reading Atoms from force file.\n" ); + painCave.isFatal = 1; + simError(); } @@ -383,13 +373,11 @@ void TraPPE_ExFF::initializeAtoms( void ){ lineNum++; } if( eof_test == NULL ){ - sprintf( errMsg, + sprintf( painCave.errMsg, "Error in reading Atoms from force file at line %d.\n", lineNum ); -#ifdef IS_MPI - sendFrcStruct( &info, mpiAtomStructType ); -#endif - ffError(errMsg); + painCave.isFatal = 1; + simError(); } the_token = strtok( readLine, " ,;\t#\n" ); @@ -400,13 +388,11 @@ void TraPPE_ExFF::initializeAtoms( void ){ lineNum++; if( eof_test == NULL ){ - sprintf( errMsg, + sprintf( painCave.errMsg, "Error in reading Atoms from force file at line %d.\n", lineNum ); -#ifdef IS_MPI - sendFrcStruct( &info, mpiAtomStructType ); -#endif - ffError(errMsg); + painCave.isFatal = 1; + simError(); } } } @@ -417,13 +403,11 @@ void TraPPE_ExFF::initializeAtoms( void ){ lineNum++; if( eof_test == NULL ){ - sprintf( errMsg, + sprintf( painCave.errMsg, "Error in reading Atoms from force file at line %d.\n", lineNum ); -#ifdef IS_MPI - sendFrcStruct( &info, mpiAtomStructType ); -#endif - ffError(errMsg); + painCave.isFatal = 1; + simError(); } while( readLine[0] != '#' && eof_test != NULL ){ @@ -436,53 +420,48 @@ void TraPPE_ExFF::initializeAtoms( void ){ strcpy( currentAtomType->name, the_token ); if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - sprintf( errMsg, "Error parseing AtomTypes: line %d\n", lineNum ); -#ifdef IS_MPI - sendFrcStruct( &info, mpiAtomStructType ); -#endif - ffError(errMsg); + sprintf( painCave.errMsg, + "Error parseing AtomTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); } sscanf( the_token, "%d", ¤tAtomType->isDipole ); if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - sprintf( errMsg, "Error parseing AtomTypes: line %d\n", lineNum ); -#ifdef IS_MPI - sendFrcStruct( &info, mpiAtomStructType ); -#endif - ffError(errMsg); + sprintf( painCave.errMsg, + "Error parseing AtomTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); } sscanf( the_token, "%lf", ¤tAtomType->mass ); if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - sprintf( errMsg, "Error parseing AtomTypes: line %d\n", lineNum ); -#ifdef IS_MPI - sendFrcStruct( &info, mpiAtomStructType ); -#endif - ffError(errMsg); + sprintf( painCave.errMsg, + "Error parseing AtomTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); } sscanf( the_token, "%lf", ¤tAtomType->epslon ); if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - sprintf( errMsg, "Error parseing AtomTypes: line %d\n", lineNum ); -#ifdef IS_MPI - sendFrcStruct( &info, mpiAtomStructType ); -#endif - ffError(errMsg); + sprintf( painCave.errMsg, + "Error parseing AtomTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); } sscanf( the_token, "%lf", ¤tAtomType->sigma ); if( currentAtomType->isDipole ){ if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - sprintf( errMsg, "Error parseing AtomTypes: line %d\n", + sprintf( painCave.errMsg, + "Error parseing AtomTypes: line %d\n", lineNum ); -#ifdef IS_MPI - sendFrcStruct( &info, mpiAtomStructType ); -#endif - ffError(errMsg); + painCave.isFatal = 1; + simError(); } sscanf( the_token, "%lf", ¤tAtomType->dipole ); @@ -501,7 +480,11 @@ void TraPPE_ExFF::initializeAtoms( void ){ #ifdef IS_MPI // send out the linked list to all the other processes - + + sprintf( checkPointMsg, + "TraPPE_Ex atom structures read successfully." ); + MPIcheckPoint(); + currentAtomType = headAtomType; while( currentAtomType != NULL ){ currentAtomType->duplicate( info ); @@ -516,6 +499,8 @@ void TraPPE_ExFF::initializeAtoms( void ){ else{ // listen for node 0 to send out the force params + + MPIcheckPoint(); headAtomType = new LinkedType; recieveFrcStruct( &info, mpiAtomStructType ); @@ -524,12 +509,8 @@ void TraPPE_ExFF::initializeAtoms( void ){ headAtomType->add( info ); recieveFrcStruct( &info, mpiAtomStructType ); } - - if( info.last < 0 ) ffError( NULL ); // an error has occured, exit quietly. - - } -#endif +#endif // is_mpi // initialize the atoms @@ -540,9 +521,11 @@ void TraPPE_ExFF::initializeAtoms( void ){ currentAtomType = headAtomType->find( the_atoms[i]->getType() ); if( currentAtomType == NULL ){ - sprintf( errMsg, "AtomType error, %s not found in force file.\n", + sprintf( painCave.errMsg, + "AtomType error, %s not found in force file.\n", the_atoms[i]->getType() ); - ffError(errMsg); + painCave.isFatal = 1; + simError(); } the_atoms[i]->setMass( currentAtomType->mass ); @@ -569,30 +552,32 @@ void TraPPE_ExFF::initializeAtoms( void ){ dAtom->setSSD( 0 ); } else{ - sprintf(errMsg, + sprintf(painCave.errMsg, "AtmType error, %s does not have a moment of inertia set.\n", the_atoms[i]->getType() ); - ffError(errMsg); + painCave.isFatal = 1; + simError(); } entry_plug->n_dipoles++; } else{ - sprintf( errMsg, + sprintf( painCave.errMsg, "TraPPE_ExFF error: Atom \"%s\" is a dipole, yet no standard" " orientation was specifed in the BASS file.\n", currentAtomType->name ); - - ffError(errMsg); + painCave.isFatal = 1; + simError(); } } else{ if( the_atoms[i]->isDirectional() ){ - sprintf( errMsg, + sprintf( painCave.errMsg, "TraPPE_ExFF error: Atom \"%s\" was given a standard" "orientation in the BASS file, yet it is not a dipole.\n", currentAtomType->name); - ffError(errMsg); + painCave.isFatal = 1; + simError(); } } } @@ -601,6 +586,12 @@ void TraPPE_ExFF::initializeAtoms( void ){ // clean up the memory delete headAtomType; + +#ifdef IS_MPI + sprintf( checkPointMsg, "TraPPE_Ex atoms initialized succesfully" ); + MPIcheckPoint(); +#endif // is_mpi + } void TraPPE_ExFF::initializeBonds( bond_pair* the_bonds ){ @@ -659,6 +650,12 @@ void TraPPE_ExFF::initializeBonds( bond_pair* the_bond LinkedType* currentBondType; LinkedType* tempBondType; +#ifdef IS_MPI + bondStruct info; + info.last = 1; // initialize last to have the last set. + // if things go well, last will be set to 0 +#endif + char readLine[500]; char* the_token; char* eof_test; @@ -675,111 +672,162 @@ void TraPPE_ExFF::initializeBonds( bond_pair* the_bond the_atoms = entry_plug->atoms; nBonds = entry_plug->n_bonds; - // read in the bond types. - - rewind( frcFile ); - headBondType = new LinkedType; - currentBondType = headBondType; - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - if( eof_test == NULL ){ - fprintf( stderr, "Error in reading Bonds from force file.\n" ); - exit(8); - } - - - while( !foundBond ){ - while( eof_test != NULL && readLine[0] != '#' ){ - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - } +#ifdef IS_MPI + if( worldRank == 0 ){ +#endif + + // read in the bond types. + + rewind( frcFile ); + headBondType = new LinkedType; + currentBondType = headBondType; + + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; if( eof_test == NULL ){ - fprintf( stderr, - "Error in reading Bonds from force file at line %d.\n", - lineNum ); - exit(8); + sprintf( painCave.errMsg, "Error in reading Bonds from force file.\n" ); + painCave.isFatal = 1; + simError(); } - - the_token = strtok( readLine, " ,;\t#\n" ); - foundBond = !strcmp( "BondTypes", the_token ); - if( !foundBond ){ - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - + + while( !foundBond ){ + while( eof_test != NULL && readLine[0] != '#' ){ + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; + } if( eof_test == NULL ){ - fprintf( stderr, + sprintf( painCave.errMsg, "Error in reading Bonds from force file at line %d.\n", lineNum ); - exit(8); - } - } - } - - // we are now at the BondTypes section. - - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - - if( eof_test == NULL ){ - fprintf( stderr, - "Error in reading Bonds from force file at line %d.\n", - lineNum ); - exit(8); - } - - while( readLine[0] != '#' && eof_test != NULL ){ - - if( readLine[0] != '!' ){ + painCave.isFatal = 1; + simError(); + } - the_token = strtok( readLine, " \n\t,;" ); - if( the_token != NULL ){ + the_token = strtok( readLine, " ,;\t#\n" ); + foundBond = !strcmp( "BondTypes", the_token ); + + if( !foundBond ){ + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; - strcpy( currentBondType->nameA, the_token ); + if( eof_test == NULL ){ + sprintf( painCave.errMsg, + "Error in reading Bonds from force file at line %d.\n", + lineNum ); + painCave.isFatal = 1; + simError(); + } + } + } + + // we are now at the BondTypes section. + + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; + + if( eof_test == NULL ){ + sprintf( painCave.errMsg, + "Error in reading Bonds from force file at line %d.\n", + lineNum ); + painCave.isFatal = 1; + simError(); + } + + while( readLine[0] != '#' && eof_test != NULL ){ + + if( readLine[0] != '!' ){ - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing BondTypes: line %d\n", lineNum ); - exit(8); - } - - strcpy( currentBondType->nameB, the_token ); - - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing BondTypes: line %d\n", lineNum ); - exit(8); - } - - strcpy( currentBondType->type, the_token ); - - if( !strcmp( currentBondType->type, "fixed" ) ){ + the_token = strtok( readLine, " \n\t,;" ); + if( the_token != NULL ){ + + strcpy( currentBondType->nameA, the_token ); + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing BondTypes: line %d\n", lineNum ); - exit(8); + sprintf( painCave.errMsg, + "Error parseing BondTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); } - sscanf( the_token, "%lf", ¤tBondType->d0 ); + strcpy( currentBondType->nameB, the_token ); + + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing BondTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } + + strcpy( currentBondType->type, the_token ); + + if( !strcmp( currentBondType->type, "fixed" ) ){ + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing BondTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } + + sscanf( the_token, "%lf", ¤tBondType->d0 ); + } + + else{ + sprintf( painCave.errMsg, + "Unknown TraPPE_Ex bond type \"%s\" at line %d\n", + currentBondType->type, + lineNum ); + painCave.isFatal = 1; + simError(); + } } - - else{ - fprintf(stderr, - "Unknown TraPPE_Ex bond type \"%s\" at line %d\n", - currentBondType->type, - lineNum ); - exit(8); - } } + + tempBondType = new LinkedType; + currentBondType->next = tempBondType; + currentBondType = tempBondType; + + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; } - tempBondType = new LinkedType; - currentBondType->next = tempBondType; - currentBondType = tempBondType; +#ifdef IS_MPI - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; + // send out the linked list to all the other processes + + sprintf( checkPointMsg, + "TraPPE_Ex bond structures read successfully." ); + MPIcheckPoint(); + + currentBondType = headBondType; + while( currentBondType != NULL ){ + currentBondType->duplicate( info ); + sendFrcStruct( &info, mpiBondStructType ); + currentBondType = currentBondType->next; + } + info.last = 1; + sendFrcStruct( &info, mpiBondStructType ); + } + else{ + + // listen for node 0 to send out the force params + + MPIcheckPoint(); + + headBondType = new LinkedType; + recieveFrcStruct( &info, mpiBondStructType ); + while( !info.last ){ + + headBondType->add( info ); + recieveFrcStruct( &info, mpiBondStructType ); + } + } +#endif // is_mpi + // initialize the Bonds @@ -792,9 +840,11 @@ void TraPPE_ExFF::initializeBonds( bond_pair* the_bond atomB = the_atoms[b]->getType(); currentBondType = headBondType->find( atomA, atomB ); if( currentBondType == NULL ){ - fprintf( stderr, "BondType error, %s - %s not found in force file.\n", + sprintf( painCave.errMsg, + "BondType error, %s - %s not found in force file.\n", atomA, atomB ); - exit(8); + painCave.isFatal = 1; + simError(); } if( !strcmp( currentBondType->type, "fixed" ) ){ @@ -811,6 +861,11 @@ void TraPPE_ExFF::initializeBonds( bond_pair* the_bond delete headBondType; +#ifdef IS_MPI + sprintf( checkPointMsg, "TraPPE_Ex bonds initialized succesfully" ); + MPIcheckPoint(); +#endif // is_mpi + } void TraPPE_ExFF::initializeBends( bend_set* the_bends ){ @@ -864,7 +919,7 @@ void TraPPE_ExFF::initializeBends( bend_set* the_bends info.last = 0; } -#endif +#endif // is_mpi char nameA[15]; char nameB[15]; @@ -879,6 +934,12 @@ void TraPPE_ExFF::initializeBends( bend_set* the_bends LinkedType* currentBendType; LinkedType* tempBendType; +#ifdef IS_MPI + bendStruct info; + info.last = 1; // initialize last to have the last set. + // if things go well, last will be set to 0 +#endif + char readLine[500]; char* the_token; char* eof_test; @@ -897,138 +958,196 @@ void TraPPE_ExFF::initializeBends( bend_set* the_bends the_atoms = entry_plug->atoms; nBends = entry_plug->n_bends; - // read in the bend types. - rewind( frcFile ); - headBendType = new LinkedType; - currentBendType = headBendType; - - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - if( eof_test == NULL ){ - fprintf( stderr, "Error in reading Bends from force file.\n" ); - exit(8); - } +#ifdef IS_MPI + if( worldRank == 0 ){ +#endif + // read in the bend types. + + rewind( frcFile ); + headBendType = new LinkedType; + currentBendType = headBendType; - while( !foundBend ){ - while( eof_test != NULL && readLine[0] != '#' ){ - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - } + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; if( eof_test == NULL ){ - fprintf( stderr, - "Error in reading Bends from force file at line %d.\n", - lineNum ); - exit(8); + sprintf( painCave.errMsg, "Error in reading Bends from force file.\n" ); + painCave.isFatal = 1; + simError(); } - the_token = strtok( readLine, " ,;\t#\n" ); - foundBend = !strcmp( "BendTypes", the_token ); - - if( !foundBend ){ - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - + + while( !foundBend ){ + while( eof_test != NULL && readLine[0] != '#' ){ + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; + } if( eof_test == NULL ){ - fprintf( stderr, + sprintf( painCave.errMsg, "Error in reading Bends from force file at line %d.\n", lineNum ); - exit(8); - } + painCave.isFatal = 1; + simError(); + } + + the_token = strtok( readLine, " ,;\t#\n" ); + foundBend = !strcmp( "BendTypes", the_token ); + + if( !foundBend ){ + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; + + if( eof_test == NULL ){ + sprintf( painCave.errMsg, + "Error in reading Bends from force file at line %d.\n", + lineNum ); + painCave.isFatal = 1; + simError(); + } + } } - } - // we are now at the BendTypes section. + // we are now at the BendTypes section. - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; - if( eof_test == NULL ){ - fprintf( stderr, - "Error in reading Bends from force file at line %d.\n", - lineNum ); - exit(8); - } + if( eof_test == NULL ){ + sprintf( painCave.errMsg, + "Error in reading Bends from force file at line %d.\n", + lineNum ); + painCave.isFatal = 1; + simError(); + } - while( readLine[0] != '#' && eof_test != NULL ){ + while( readLine[0] != '#' && eof_test != NULL ){ - if( readLine[0] != '!' ){ + if( readLine[0] != '!' ){ - the_token = strtok( readLine, " \n\t,;" ); - if( the_token != NULL ){ + the_token = strtok( readLine, " \n\t,;" ); + if( the_token != NULL ){ - strcpy( currentBendType->nameA, the_token ); + strcpy( currentBendType->nameA, the_token ); - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum ); - exit(8); - } + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing BendTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } - strcpy( currentBendType->nameB, the_token ); + strcpy( currentBendType->nameB, the_token ); - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum ); - exit(8); - } + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing BendTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } - strcpy( currentBendType->nameC, the_token ); + strcpy( currentBendType->nameC, the_token ); - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum ); - exit(8); - } - - strcpy( currentBendType->type, the_token ); - - if( !strcmp( currentBendType->type, "quadratic" ) ){ if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum ); - exit(8); + sprintf( painCave.errMsg, + "Error parseing BendTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); } + + strcpy( currentBendType->type, the_token ); + + if( !strcmp( currentBendType->type, "quadratic" ) ){ + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing BendTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } - sscanf( the_token, "%lf", ¤tBendType->k1 ); + sscanf( the_token, "%lf", ¤tBendType->k1 ); - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum ); - exit(8); - } + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing BendTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } - sscanf( the_token, "%lf", ¤tBendType->k2 ); + sscanf( the_token, "%lf", ¤tBendType->k2 ); - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum ); - exit(8); - } + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing BendTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } - sscanf( the_token, "%lf", ¤tBendType->k3 ); + sscanf( the_token, "%lf", ¤tBendType->k3 ); - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum ); - exit(8); - } + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing BendTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } - sscanf( the_token, "%lf", ¤tBendType->t0 ); - } + sscanf( the_token, "%lf", ¤tBendType->t0 ); + } - else{ - fprintf(stderr, - "Unknown TraPPE_Ex bend type \"%s\" at line %d\n", - currentBendType->type, - lineNum ); - exit(8); - } + else{ + sprintf( painCave.errMsg, + "Unknown TraPPE_Ex bend type \"%s\" at line %d\n", + currentBendType->type, + lineNum ); + painCave.isFatal = 1; + simError(); + } + } } - } - tempBendType = new LinkedType; - currentBendType->next = tempBendType; - currentBendType = tempBendType; + tempBendType = new LinkedType; + currentBendType->next = tempBendType; + currentBendType = tempBendType; - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; + } + +#ifdef IS_MPI + + // send out the linked list to all the other processes + + sprintf( checkPointMsg, + "TraPPE_Ex bend structures read successfully." ); + MPIcheckPoint(); + + currentBendType = headBendType; + while( currentBendType != NULL ){ + currentBendType->duplicate( info ); + sendFrcStruct( &info, mpiBendStructType ); + currentBendType = currentBendType->next; + } + info.last = 1; + sendFrcStruct( &info, mpiBendStructType ); + } + else{ + + // listen for node 0 to send out the force params + + MPIcheckPoint(); + + headBendType = new LinkedType; + recieveFrcStruct( &info, mpiBendStructType ); + while( !info.last ){ + + headBendType->add( info ); + recieveFrcStruct( &info, mpiBendStructType ); + } + } +#endif // is_mpi // initialize the Bends @@ -1043,10 +1162,11 @@ void TraPPE_ExFF::initializeBends( bend_set* the_bends atomC = the_atoms[c]->getType(); currentBendType = headBendType->find( atomA, atomB, atomC ); if( currentBendType == NULL ){ - fprintf( stderr, "BendType error, %s - %s - %s not found" + sprintf( painCave.errMsg, "BendType error, %s - %s - %s not found" " in force file.\n", atomA, atomB, atomC ); - exit(8); + painCave.isFatal = 1; + simError(); } if( !strcmp( currentBendType->type, "quadratic" ) ){ @@ -1068,6 +1188,11 @@ void TraPPE_ExFF::initializeBends( bend_set* the_bends delete headBendType; +#ifdef IS_MPI + sprintf( checkPointMsg, "TraPPE_Ex bends initialized succesfully" ); + MPIcheckPoint(); +#endif // is_mpi + } void TraPPE_ExFF::initializeTorsions( torsion_set* the_torsions ){ @@ -1140,6 +1265,12 @@ void TraPPE_ExFF::initializeTorsions( torsion_set* the LinkedType* currentTorsionType; LinkedType* tempTorsionType; +#ifdef IS_MPI + torsionStruct info; + info.last = 1; // initialize last to have the last set. + // if things go well, last will be set to 0 +#endif + char readLine[500]; char* the_token; char* eof_test; @@ -1159,145 +1290,205 @@ void TraPPE_ExFF::initializeTorsions( torsion_set* the the_atoms = entry_plug->atoms; nTorsions = entry_plug->n_torsions; - // read in the torsion types. +#ifdef IS_MPI + if( worldRank == 0 ){ +#endif - rewind( frcFile ); - headTorsionType = new LinkedType; - currentTorsionType = headTorsionType; - - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - if( eof_test == NULL ){ - fprintf( stderr, "Error in reading Torsions from force file.\n" ); - exit(8); - } + // read in the torsion types. + rewind( frcFile ); + headTorsionType = new LinkedType; + currentTorsionType = headTorsionType; - while( !foundTorsion ){ - while( eof_test != NULL && readLine[0] != '#' ){ - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - } + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; if( eof_test == NULL ){ - fprintf( stderr, - "Error in reading Torsions from force file at line %d.\n", - lineNum ); - exit(8); + sprintf( painCave.errMsg, + "Error in reading Torsions from force file.\n" ); + painCave.isFatal = 1; + simError(); } - the_token = strtok( readLine, " ,;\t#\n" ); - foundTorsion = !strcmp( "TorsionTypes", the_token ); - - if( !foundTorsion ){ - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - + + while( !foundTorsion ){ + while( eof_test != NULL && readLine[0] != '#' ){ + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; + } if( eof_test == NULL ){ - fprintf( stderr, + sprintf( painCave.errMsg, "Error in reading Torsions from force file at line %d.\n", lineNum ); - exit(8); - } + painCave.isFatal = 1; + simError(); + } + + the_token = strtok( readLine, " ,;\t#\n" ); + foundTorsion = !strcmp( "TorsionTypes", the_token ); + + if( !foundTorsion ){ + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; + + if( eof_test == NULL ){ + sprintf( painCave.errMsg, + "Error in reading Torsions from force file at line %d.\n", + lineNum ); + painCave.isFatal = 1; + simError(); + } + } } - } - // we are now at the TorsionTypes section. + // we are now at the TorsionTypes section. - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; - if( eof_test == NULL ){ - fprintf( stderr, - "Error in reading Torsions from force file at line %d.\n", - lineNum ); - exit(8); - } + if( eof_test == NULL ){ + sprintf( painCave.errMsg, + "Error in reading Torsions from force file at line %d.\n", + lineNum ); + painCave.isFatal = 1; + simError(); + } - while( readLine[0] != '#' && eof_test != NULL ){ + while( readLine[0] != '#' && eof_test != NULL ){ - if( readLine[0] != '!' ){ + if( readLine[0] != '!' ){ - the_token = strtok( readLine, " \n\t,;" ); - if( the_token != NULL ){ + the_token = strtok( readLine, " \n\t,;" ); + if( the_token != NULL ){ - strcpy( currentTorsionType->nameA, the_token ); + strcpy( currentTorsionType->nameA, the_token ); - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing TorsionTypes: line %d\n", lineNum ); - exit(8); - } + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing TorsionTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } - strcpy( currentTorsionType->nameB, the_token ); + strcpy( currentTorsionType->nameB, the_token ); - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing TorsionTypes: line %d\n", lineNum ); - exit(8); - } + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing TorsionTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } - strcpy( currentTorsionType->nameC, the_token ); + strcpy( currentTorsionType->nameC, the_token ); - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing TorsionTypes: line %d\n", lineNum ); - exit(8); - } + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing TorsionTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } - strcpy( currentTorsionType->nameD, the_token ); + strcpy( currentTorsionType->nameD, the_token ); - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing TorsionTypes: line %d\n", lineNum ); - exit(8); - } - - strcpy( currentTorsionType->type, the_token ); - - if( !strcmp( currentTorsionType->type, "cubic" ) ){ if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf(stderr,"Error parseing TorsionTypes: line %d\n", lineNum ); - exit(8); + sprintf( painCave.errMsg, + "Error parseing TorsionTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); } + + strcpy( currentTorsionType->type, the_token ); + + if( !strcmp( currentTorsionType->type, "cubic" ) ){ + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing TorsionTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } - sscanf( the_token, "%lf", ¤tTorsionType->k1 ); + sscanf( the_token, "%lf", ¤tTorsionType->k1 ); - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf(stderr,"Error parseing TorsionTypes: line %d\n", lineNum ); - exit(8); - } + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing TorsionTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } - sscanf( the_token, "%lf", ¤tTorsionType->k2 ); + sscanf( the_token, "%lf", ¤tTorsionType->k2 ); - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf(stderr,"Error parseing TorsionTypes: line %d\n", lineNum ); - exit(8); - } + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing TorsionTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } - sscanf( the_token, "%lf", ¤tTorsionType->k3 ); + sscanf( the_token, "%lf", ¤tTorsionType->k3 ); - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf(stderr,"Error parseing TorsionTypes: line %d\n", lineNum ); - exit(8); - } + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + sprintf( painCave.errMsg, + "Error parseing TorsionTypes: line %d\n", lineNum ); + painCave.isFatal = 1; + simError(); + } - sscanf( the_token, "%lf", ¤tTorsionType->k4 ); - } + sscanf( the_token, "%lf", ¤tTorsionType->k4 ); + } - else{ - fprintf(stderr, - "Unknown TraPPE_Ex torsion type \"%s\" at line %d\n", - currentTorsionType->type, - lineNum ); - exit(8); - } + else{ + sprintf( painCave.errMsg, + "Unknown TraPPE_Ex torsion type \"%s\" at line %d\n", + currentTorsionType->type, + lineNum ); + painCave.isFatal = 1; + simError(); + } + } } + + tempTorsionType = new LinkedType; + currentTorsionType->next = tempTorsionType; + currentTorsionType = tempTorsionType; + + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; } + +#ifdef IS_MPI - tempTorsionType = new LinkedType; - currentTorsionType->next = tempTorsionType; - currentTorsionType = tempTorsionType; + // send out the linked list to all the other processes - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; + sprintf( checkPointMsg, + "TraPPE_Ex torsion structures read successfully." ); + MPIcheckPoint(); + + currentTorsionType = headTorsionType; + while( currentTorsionType != NULL ){ + currentTorsionType->duplicate( info ); + sendFrcStruct( &info, mpiTorsionStructType ); + currentTorsionType = currentTorsionType->next; + } + info.last = 1; + sendFrcStruct( &info, mpiTorsionStructType ); + } + else{ + + // listen for node 0 to send out the force params + + MPIcheckPoint(); + + headTorsionType = new LinkedType; + recieveFrcStruct( &info, mpiTorsionStructType ); + while( !info.last ){ + + headTorsionType->add( info ); + recieveFrcStruct( &info, mpiTorsionStructType ); + } + } +#endif // is_mpi // initialize the Torsions @@ -1314,10 +1505,12 @@ void TraPPE_ExFF::initializeTorsions( torsion_set* the atomD = the_atoms[d]->getType(); currentTorsionType = headTorsionType->find( atomA, atomB, atomC, atomD ); if( currentTorsionType == NULL ){ - fprintf( stderr, "TorsionType error, %s - %s - %s - %s not found" + sprintf( painCave.errMsg, + "TorsionType error, %s - %s - %s - %s not found" " in force file.\n", atomA, atomB, atomC, atomD ); - exit(8); + painCave.isFatal = 1; + simError(); } if( !strcmp( currentTorsionType->type, "cubic" ) ){ @@ -1336,4 +1529,9 @@ void TraPPE_ExFF::initializeTorsions( torsion_set* the delete headTorsionType; +#ifdef IS_MPI + sprintf( checkPointMsg, "TraPPE_Ex torsions initialized succesfully" ); + MPIcheckPoint(); +#endif // is_mpi + }