--- trunk/OOPSE/libmdtools/TraPPE_ExFF.cpp 2003/03/24 21:55:34 394 +++ trunk/OOPSE/libmdtools/TraPPE_ExFF.cpp 2003/03/27 17:32:03 420 @@ -82,9 +82,325 @@ namespace TPE { // restrict the access of the folowin MPI_Datatype mpiBondStructType; MPI_Datatype mpiBendStructType; MPI_Datatype mpiTorsionStructType; + +#endif + + class LinkedAtomType { + public: + LinkedAtomType(){ + next = NULL; + name[0] = '\0'; + } + ~LinkedAtomType(){ if( next != NULL ) delete next; } + + LinkedAtomType* find(char* key){ + if( !strcmp(name, key) ) return this; + if( next != NULL ) return next->find(key); + return NULL; + } + + void add( atomStruct &info ){ + + // check for duplicates + + if( !strcmp( info.name, name ) ){ + sprintf( painCave.errMsg, + "Duplicate TraPPE_Ex atom type \"%s\" found in " + "the TraPPE_ExFF param file./n", + name ); + painCave.isFatal = 1; + simError(); + } + + if( next != NULL ) next->add(info); + else{ + next = new LinkedType(); + strcpy(next->name, info.name); + next->isDipole = info.isDipole; + next->isSSD = info.isSSD; + next->mass = info.mass; + next->epslon = info.epslon; + next->sigma = info.sigma; + next->dipole = info.dipole; + next->w0 = info.w0; + next->v0 = info.v0; + next->ident = info.ident; + } + } + +#ifdef IS_MPI + + void duplicate( atomStruct &info ){ + strcpy(info.name, name); + info.isDipole = isDipole; + info.isSSD = isSSD; + info.mass = mass; + info.epslon = epslon; + info.sigma = sigma; + info.dipole = dipole; + info.w0 = w0; + info.v0 = v0; + info.last = 0; + } + + +#endif + + char name[15]; + int isDipole; + int isSSD; + double mass; + double epslon; + double sigma; + double dipole; + double w0; + double v0; + int ident; + LinkedAtomType* next; + }; + + class LinkedBondType { + public: + LinkedBondType(){ + next = NULL; + nameA[0] = '\0'; + nameB[0] = '\0'; + type[0] = '\0'; + } + ~LinkedBondType(){ if( next != NULL ) delete next; } + + LinkedBondType* find(char* key1, char* key2){ + if( !strcmp(nameA, key1 ) && !strcmp( nameB, key2 ) ) return this; + if( !strcmp(nameA, key2 ) && !strcmp( nameB, key1 ) ) return this; + if( next != NULL ) return next->find(key1, key2); + return NULL; + } + + + void add( bondStruct &info ){ + + // check for duplicates + int dup = 0; + + if( !strcmp(nameA, info.nameA ) && !strcmp( nameB, info.nameB ) ) dup = 1; + if( !strcmp(nameA, info.nameB ) && !strcmp( nameB, info.nameA ) ) dup = 1; + + if(dup){ + sprintf( painCave.errMsg, + "Duplicate TraPPE_Ex bond type \"%s - %s\" found in " + "the TraPPE_ExFF param file./n", + nameA, nameB ); + painCave.isFatal = 1; + simError(); + } + + + if( next != NULL ) next->add(info); + else{ + next = new LinkedType(); + strcpy(next->nameA, info.nameA); + strcpy(next->nameB, info.nameB); + strcpy(next->type, info.type); + next->d0 = info.d0; + } + } + +#ifdef IS_MPI + void duplicate( bondStruct &info ){ + strcpy(info.nameA, nameA); + strcpy(info.nameB, nameB); + strcpy(info.type, type); + info.d0 = d0; + info.last = 0; + } + + +#endif + + char nameA[15]; + char nameB[15]; + char type[30]; + double d0; + + LinkedBondType* next; + }; + + class LinkedBendType { + public: + LinkedBendType(){ + next = NULL; + nameA[0] = '\0'; + nameB[0] = '\0'; + nameC[0] = '\0'; + type[0] = '\0'; + } + ~LinkedBendType(){ if( next != NULL ) delete next; } + + LinkedBendType* find( char* key1, char* key2, char* key3 ){ + if( !strcmp( nameA, key1 ) && !strcmp( nameB, key2 ) + && !strcmp( nameC, key3 ) ) return this; + if( !strcmp( nameA, key3 ) && !strcmp( nameB, key2 ) + && !strcmp( nameC, key1 ) ) return this; + if( next != NULL ) return next->find(key1, key2, key3); + return NULL; + } + + void add( bendStruct &info ){ + + // check for duplicates + int dup = 0; + + if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB ) + && !strcmp( nameC, info.nameC ) ) dup = 1; + if( !strcmp( nameA, info.nameC ) && !strcmp( nameB, info.nameB ) + && !strcmp( nameC, info.nameA ) ) dup = 1; + + if(dup){ + sprintf( painCave.errMsg, + "Duplicate TraPPE_Ex bend type \"%s - %s - %s\" found in " + "the TraPPE_ExFF param file./n", + nameA, nameB, nameC ); + painCave.isFatal = 1; + simError(); + } + + if( next != NULL ) next->add(info); + else{ + next = new LinkedType(); + strcpy(next->nameA, info.nameA); + strcpy(next->nameB, info.nameB); + strcpy(next->nameC, info.nameC); + strcpy(next->type, info.type); + next->k1 = info.k1; + next->k2 = info.k2; + next->k3 = info.k3; + next->t0 = info.t0; + } + } + +#ifdef IS_MPI + + void duplicate( bendStruct &info ){ + strcpy(info.nameA, nameA); + strcpy(info.nameB, nameB); + strcpy(info.nameC, nameC); + strcpy(info.type, type); + info.k1 = k1; + info.k2 = k2; + info.k3 = k3; + info.t0 = t0; + info.last = 0; + } +#endif // is_mpi + + char nameA[15]; + char nameB[15]; + char nameC[15]; + char type[30]; + double k1, k2, k3, t0; + + LinkedBendType* next; + }; + + class LinkedTorsionType { + public: + LinkedTorsionType(){ + next = NULL; + nameA[0] = '\0'; + nameB[0] = '\0'; + nameC[0] = '\0'; + type[0] = '\0'; + } + ~LinkedTorsionType(){ if( next != NULL ) delete next; } + + LinkedTorsionType* find( char* key1, char* key2, char* key3, char* key4 ){ + + + + + if( !strcmp( nameA, key1 ) && !strcmp( nameB, key2 ) && + !strcmp( nameC, key3 ) && !strcmp( nameD, key4 ) ) return this; + + if( !strcmp( nameA, key4 ) && !strcmp( nameB, key3 ) && + !strcmp( nameC, key2 ) && !strcmp( nameD, key1 ) ) return this; + + if( next != NULL ) return next->find(key1, key2, key3, key4); + return NULL; + } + + void add( torsionStruct &info ){ + + // check for duplicates + int dup = 0; + + if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB ) && + !strcmp( nameC, info.nameC ) && !strcmp( nameD, info.nameD ) ) dup = 1; + + if( !strcmp( nameA, info.nameD ) && !strcmp( nameB, info.nameC ) && + !strcmp( nameC, info.nameB ) && !strcmp( nameD, info.nameA ) ) dup = 1; + + if(dup){ + sprintf( painCave.errMsg, + "Duplicate TraPPE_Ex torsion type \"%s - %s - %s - %s\" found in " + "the TraPPE_ExFF param file./n", nameA, nameB, nameC, nameD ); + painCave.isFatal = 1; + simError(); + } + + if( next != NULL ) next->add(info); + else{ + next = new LinkedType(); + strcpy(next->nameA, info.nameA); + strcpy(next->nameB, info.nameB); + strcpy(next->nameC, info.nameC); + strcpy(next->nameD, info.nameD); + strcpy(next->type, info.type); + next->k1 = info.k1; + next->k2 = info.k2; + next->k3 = info.k3; + next->k4 = info.k4; + + } + } + +#ifdef IS_MPI + + void duplicate( torsionStruct &info ){ + strcpy(info.nameA, nameA); + strcpy(info.nameB, nameB); + strcpy(info.nameC, nameC); + strcpy(info.nameD, nameD); + strcpy(info.type, type); + info.k1 = k1; + info.k2 = k2; + info.k3 = k3; + info.k4 = k4; + info.last = 0; + } + #endif + char nameA[15]; + char nameB[15]; + char nameC[15]; + char nameD[15]; + char type[30]; + double k1, k2, k3, k4; + + LinkedTorsionType* next; + }; + + + LinkedAtomType* headAtomType; + LinkedAtomType* currentAtomType; + LinkedBondType* headBondType; + LinkedBondType* currentBondType; + LinkedBendType* headBendType; + LinkedBendType* currentBendType; + LinkedTorsionType* headTorsionType; + LinkedTorsionType* currentTorsionType; + } // namespace using namespace TPE; @@ -103,6 +419,15 @@ TraPPE_ExFF::TraPPE_ExFF(){ char temp[200]; char errMsg[1000]; + headAtomType = NULL; + currentAtomType = NULL; + headBondType = NULL; + currentBondType = NULL; + headBendType = NULL; + currentBendType = NULL; + headTorsionType = NULL; + currentTorsionType = NULL; + // do the funtion wrapping wrapMeFF( this ); @@ -253,6 +578,11 @@ TraPPE_ExFF::~TraPPE_ExFF(){ TraPPE_ExFF::~TraPPE_ExFF(){ + if( headAtomType != NULL ) delete headAtomType; + if( headBondType != NULL ) delete headBondType; + if( headBendType != NULL ) delete headBendType; + if( headTorsionType != NULL ) delete headTorsionType; + #ifdef IS_MPI if( worldRank == 0 ){ #endif // is_mpi @@ -264,147 +594,57 @@ void TraPPE_ExFF::initForceField( int ljMixRule ){ #endif // is_mpi } -void TraPPE_ExFF::initForceField( int ljMixRule ){ - - initFortran( ljMixRule, entry_plug->useReactionField ); -} +void TraPPE_ExFF::cleanMe( void ){ - -void TraPPE_ExFF::initializeAtoms( void ){ +#ifdef IS_MPI - class LinkedType { - public: - LinkedType(){ - next = NULL; - name[0] = '\0'; - } - ~LinkedType(){ if( next != NULL ) delete next; } + // keep the linked lists in the mpi version - LinkedType* find(char* key){ - if( !strcmp(name, key) ) return this; - if( next != NULL ) return next->find(key); - return NULL; - } - - void add( atomStruct &info ){ +#else // is_mpi - // check for duplicates - - if( !strcmp( info.name, name ) ){ - sprintf( painCave.errMsg, - "Duplicate TraPPE_Ex atom type \"%s\" found in " - "the TraPPE_ExFF param file./n", - name ); - painCave.isFatal = 1; - simError(); - } + // delete the linked lists in the single processor version - if( next != NULL ) next->add(info); - else{ - next = new LinkedType(); - strcpy(next->name, info.name); - next->isDipole = info.isDipole; - next->isSSD = info.isSSD; - next->mass = info.mass; - next->epslon = info.epslon; - next->sigma = info.sigma; - next->dipole = info.dipole; - next->w0 = info.w0; - next->v0 = info.v0; - next->ident = info.ident; - } - } + if( headAtomType != NULL ) delete headAtomType; + if( headBondType != NULL ) delete headBondType; + if( headBendType != NULL ) delete headBendType; + if( headTorsionType != NULL ) delete headTorsionType; -#ifdef IS_MPI - - void duplicate( atomStruct &info ){ - strcpy(info.name, name); - info.isDipole = isDipole; - info.isSSD = isSSD; - info.mass = mass; - info.epslon = epslon; - info.sigma = sigma; - info.dipole = dipole; - info.w0 = w0; - info.v0 = v0; - info.last = 0; - } +#endif // is_mpi +} -#endif +void TraPPE_ExFF::initForceField( int ljMixRule ){ + + initFortran( ljMixRule, entry_plug->useReactionField ); +} - char name[15]; - int isDipole; - int isSSD; - double mass; - double epslon; - double sigma; - double dipole; - double w0; - double v0; - int ident; - LinkedType* next; - }; - - LinkedType* headAtomType; - LinkedType* currentAtomType; - atomStruct info; - info.last = 1; // initialize last to have the last set. - // if things go well, last will be set to 0 - +void TraPPE_ExFF::readParams( void ){ int i; int identNum; - Atom** the_atoms; - int nAtoms; - the_atoms = entry_plug->atoms; - nAtoms = entry_plug->n_atoms; + atomStruct atomInfo; + bondStruct bondInfo; + bendStruct bendInfo; + torsionStruct torsionInfo; - ////////////////////////////////////////////////// - // a quick water fix - - double waterI[3][3]; - waterI[0][0] = 1.76958347772500; - waterI[0][1] = 0.0; - waterI[0][2] = 0.0; - - waterI[1][0] = 0.0; - waterI[1][1] = 0.614537057924513; - waterI[1][2] = 0.0; - - waterI[2][0] = 0.0; - waterI[2][1] = 0.0; - waterI[2][2] = 1.15504641980049; - - - double headI[3][3]; - headI[0][0] = 1125; - headI[0][1] = 0.0; - headI[0][2] = 0.0; - - headI[1][0] = 0.0; - headI[1][1] = 1125; - headI[1][2] = 0.0; - - headI[2][0] = 0.0; - headI[2][1] = 0.0; - headI[2][2] = 250; - + atomInfo.last = 1; + bondInfo.last = 1; + bendInfo.last = 1; + torsionInfo.last = 1; - ////////////////////////////////////////////////// - - + // read in the atom info + #ifdef IS_MPI if( worldRank == 0 ){ #endif // read in the atom types. - - headAtomType = new LinkedType; + headAtomType = new LinkedAtomType; + fastForward( "AtomTypes", "initializeAtoms" ); // we are now at the AtomTypes section. @@ -431,9 +671,9 @@ void TraPPE_ExFF::initializeAtoms( void ){ if( readLine[0] != '!' ){ // the parser returns 0 if the line was blank - if( parseAtom( readLine, lineNum, info ) ){ - info.ident = identNum; - headAtomType->add( info );; + if( parseAtom( readLine, lineNum, atomInfo ) ){ + atomInfo.ident = identNum; + headAtomType->add( atomInfo );; identNum++; } } @@ -451,21 +691,21 @@ void TraPPE_ExFF::initializeAtoms( void ){ currentAtomType = headAtomType->next; //skip the first element who is a place holder. while( currentAtomType != NULL ){ - currentAtomType->duplicate( info ); + currentAtomType->duplicate( atomInfo ); - sendFrcStruct( &info, mpiAtomStructType ); + sendFrcStruct( &atomInfo, mpiAtomStructType ); sprintf( checkPointMsg, "successfully sent TraPPE_Ex force type: \"%s\"\n", - info.name ); + atomInfo.name ); MPIcheckPoint(); currentAtomType = currentAtomType->next; } - info.last = 1; - sendFrcStruct( &info, mpiAtomStructType ); + atomInfo.last = 1; + sendFrcStruct( &atomInfo, mpiAtomStructType ); } @@ -476,17 +716,17 @@ void TraPPE_ExFF::initializeAtoms( void ){ MPIcheckPoint(); headAtomType = new LinkedType; - recieveFrcStruct( &info, mpiAtomStructType ); + recieveFrcStruct( &atomInfo, mpiAtomStructType ); - while( !info.last ){ + while( !atomInfo.last ){ - headAtomType->add( info ); + headAtomType->add( atomInfo ); MPIcheckPoint(); - recieveFrcStruct( &info, mpiAtomStructType ); + recieveFrcStruct( &atomInfo, mpiAtomStructType ); } } #endif // is_mpi @@ -543,8 +783,67 @@ void TraPPE_ExFF::initializeAtoms( void ){ "TraPPE_ExFF atom structures successfully sent to fortran\n" ); MPIcheckPoint(); #endif // is_mpi + + + // read in the bonds + + + +} + + + +void TraPPE_ExFF::initializeAtoms( void ){ + + + + + + + Atom** the_atoms; + int nAtoms; + the_atoms = entry_plug->atoms; + nAtoms = entry_plug->n_atoms; + + ////////////////////////////////////////////////// + // a quick water fix + + double waterI[3][3]; + waterI[0][0] = 1.76958347772500; + waterI[0][1] = 0.0; + waterI[0][2] = 0.0; + + waterI[1][0] = 0.0; + waterI[1][1] = 0.614537057924513; + waterI[1][2] = 0.0; + + waterI[2][0] = 0.0; + waterI[2][1] = 0.0; + waterI[2][2] = 1.15504641980049; + + + double headI[3][3]; + headI[0][0] = 1125; + headI[0][1] = 0.0; + headI[0][2] = 0.0; + + headI[1][0] = 0.0; + headI[1][1] = 1125; + headI[1][2] = 0.0; + + headI[2][0] = 0.0; + headI[2][1] = 0.0; + headI[2][2] = 250; + + + + ////////////////////////////////////////////////// + + + + // initialize the atoms double bigSigma = 0.0; @@ -654,77 +953,12 @@ void TraPPE_ExFF::initializeBonds( bond_pair* the_bond void TraPPE_ExFF::initializeBonds( bond_pair* the_bonds ){ - class LinkedType { - public: - LinkedType(){ - next = NULL; - nameA[0] = '\0'; - nameB[0] = '\0'; - type[0] = '\0'; - } - ~LinkedType(){ if( next != NULL ) delete next; } - LinkedType* find(char* key1, char* key2){ - if( !strcmp(nameA, key1 ) && !strcmp( nameB, key2 ) ) return this; - if( !strcmp(nameA, key2 ) && !strcmp( nameB, key1 ) ) return this; - if( next != NULL ) return next->find(key1, key2); - return NULL; - } - - void add( bondStruct &info ){ - - // check for duplicates - int dup = 0; - if( !strcmp(nameA, info.nameA ) && !strcmp( nameB, info.nameB ) ) dup = 1; - if( !strcmp(nameA, info.nameB ) && !strcmp( nameB, info.nameA ) ) dup = 1; - - if(dup){ - sprintf( painCave.errMsg, - "Duplicate TraPPE_Ex bond type \"%s - %s\" found in " - "the TraPPE_ExFF param file./n", - nameA, nameB ); - painCave.isFatal = 1; - simError(); - } - - - if( next != NULL ) next->add(info); - else{ - next = new LinkedType(); - strcpy(next->nameA, info.nameA); - strcpy(next->nameB, info.nameB); - strcpy(next->type, info.type); - next->d0 = info.d0; - } - } - -#ifdef IS_MPI - void duplicate( bondStruct &info ){ - strcpy(info.nameA, nameA); - strcpy(info.nameB, nameB); - strcpy(info.type, type); - info.d0 = d0; - info.last = 0; - } + -#endif - - char nameA[15]; - char nameB[15]; - char type[30]; - double d0; - - LinkedType* next; - }; - - - - LinkedType* headBondType; - LinkedType* currentBondType; - bondStruct info; info.last = 1; // initialize last to have the last set. // if things go well, last will be set to 0 @@ -858,86 +1092,9 @@ void TraPPE_ExFF::initializeBends( bend_set* the_bends void TraPPE_ExFF::initializeBends( bend_set* the_bends ){ - class LinkedType { - public: - LinkedType(){ - next = NULL; - nameA[0] = '\0'; - nameB[0] = '\0'; - nameC[0] = '\0'; - type[0] = '\0'; - } - ~LinkedType(){ if( next != NULL ) delete next; } - LinkedType* find( char* key1, char* key2, char* key3 ){ - if( !strcmp( nameA, key1 ) && !strcmp( nameB, key2 ) - && !strcmp( nameC, key3 ) ) return this; - if( !strcmp( nameA, key3 ) && !strcmp( nameB, key2 ) - && !strcmp( nameC, key1 ) ) return this; - if( next != NULL ) return next->find(key1, key2, key3); - return NULL; - } - - void add( bendStruct &info ){ - - // check for duplicates - int dup = 0; - - if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB ) - && !strcmp( nameC, info.nameC ) ) dup = 1; - if( !strcmp( nameA, info.nameC ) && !strcmp( nameB, info.nameB ) - && !strcmp( nameC, info.nameA ) ) dup = 1; - - if(dup){ - sprintf( painCave.errMsg, - "Duplicate TraPPE_Ex bend type \"%s - %s - %s\" found in " - "the TraPPE_ExFF param file./n", - nameA, nameB, nameC ); - painCave.isFatal = 1; - simError(); - } - - if( next != NULL ) next->add(info); - else{ - next = new LinkedType(); - strcpy(next->nameA, info.nameA); - strcpy(next->nameB, info.nameB); - strcpy(next->nameC, info.nameC); - strcpy(next->type, info.type); - next->k1 = info.k1; - next->k2 = info.k2; - next->k3 = info.k3; - next->t0 = info.t0; - } - } - -#ifdef IS_MPI - - void duplicate( bendStruct &info ){ - strcpy(info.nameA, nameA); - strcpy(info.nameB, nameB); - strcpy(info.nameC, nameC); - strcpy(info.type, type); - info.k1 = k1; - info.k2 = k2; - info.k3 = k3; - info.t0 = t0; - info.last = 0; - } - -#endif // is_mpi - - char nameA[15]; - char nameB[15]; - char nameC[15]; - char type[30]; - double k1, k2, k3, t0; + - LinkedType* next; - }; - - LinkedType* headBendType; - LinkedType* currentBendType; bendStruct info; info.last = 1; // initialize last to have the last set. // if things go well, last will be set to 0 @@ -1117,96 +1274,9 @@ void TraPPE_ExFF::initializeTorsions( torsion_set* the void TraPPE_ExFF::initializeTorsions( torsion_set* the_torsions ){ - class LinkedType { - public: - LinkedType(){ - next = NULL; - nameA[0] = '\0'; - nameB[0] = '\0'; - nameC[0] = '\0'; - type[0] = '\0'; - } - ~LinkedType(){ if( next != NULL ) delete next; } - LinkedType* find( char* key1, char* key2, char* key3, char* key4 ){ - - - - - if( !strcmp( nameA, key1 ) && !strcmp( nameB, key2 ) && - !strcmp( nameC, key3 ) && !strcmp( nameD, key4 ) ) return this; - - if( !strcmp( nameA, key4 ) && !strcmp( nameB, key3 ) && - !strcmp( nameC, key2 ) && !strcmp( nameD, key1 ) ) return this; - - if( next != NULL ) return next->find(key1, key2, key3, key4); - return NULL; - } - - void add( torsionStruct &info ){ - - // check for duplicates - int dup = 0; - - if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB ) && - !strcmp( nameC, info.nameC ) && !strcmp( nameD, info.nameD ) ) dup = 1; - - if( !strcmp( nameA, info.nameD ) && !strcmp( nameB, info.nameC ) && - !strcmp( nameC, info.nameB ) && !strcmp( nameD, info.nameA ) ) dup = 1; - - if(dup){ - sprintf( painCave.errMsg, - "Duplicate TraPPE_Ex torsion type \"%s - %s - %s - %s\" found in " - "the TraPPE_ExFF param file./n", nameA, nameB, nameC, nameD ); - painCave.isFatal = 1; - simError(); - } + - if( next != NULL ) next->add(info); - else{ - next = new LinkedType(); - strcpy(next->nameA, info.nameA); - strcpy(next->nameB, info.nameB); - strcpy(next->nameC, info.nameC); - strcpy(next->nameD, info.nameD); - strcpy(next->type, info.type); - next->k1 = info.k1; - next->k2 = info.k2; - next->k3 = info.k3; - next->k4 = info.k4; - - } - } - -#ifdef IS_MPI - - void duplicate( torsionStruct &info ){ - strcpy(info.nameA, nameA); - strcpy(info.nameB, nameB); - strcpy(info.nameC, nameC); - strcpy(info.nameD, nameD); - strcpy(info.type, type); - info.k1 = k1; - info.k2 = k2; - info.k3 = k3; - info.k4 = k4; - info.last = 0; - } - -#endif - - char nameA[15]; - char nameB[15]; - char nameC[15]; - char nameD[15]; - char type[30]; - double k1, k2, k3, k4; - - LinkedType* next; - }; - - LinkedType* headTorsionType; - LinkedType* currentTorsionType; torsionStruct info; info.last = 1; // initialize last to have the last set. // if things go well, last will be set to 0