ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/brains/SimInfo.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/brains/SimInfo.cpp (file contents):
Revision 2425 by chrisfen, Fri Nov 11 15:22:11 2005 UTC vs.
Revision 2463 by gezelter, Mon Nov 21 22:59:21 2005 UTC

# Line 48 | Line 48
48  
49   #include <algorithm>
50   #include <set>
51 + #include <map>
52  
53   #include "brains/SimInfo.hpp"
54   #include "math/Vector3.hpp"
# Line 58 | Line 59
59   #include "UseTheForce/DarkSide/fSwitchingFunctionType.h"
60   #include "UseTheForce/doForces_interface.h"
61   #include "UseTheForce/DarkSide/electrostatic_interface.h"
61 #include "UseTheForce/notifyCutoffs_interface.h"
62   #include "UseTheForce/DarkSide/switcheroo_interface.h"
63   #include "utils/MemoryUtils.hpp"
64   #include "utils/simError.h"
# Line 70 | Line 70 | namespace oopse {
70   #endif
71  
72   namespace oopse {
73 +  std::set<int> getRigidSet(int index, std::map<int, std::set<int> >& container) {
74 +    std::map<int, std::set<int> >::iterator i = container.find(index);
75 +    std::set<int> result;
76 +    if (i != container.end()) {
77 +        result = i->second;
78 +    }
79  
80 +    return result;
81 +  }
82 +  
83    SimInfo::SimInfo(MakeStamps* stamps, std::vector<std::pair<MoleculeStamp*, int> >& molStampPairs,
84                     ForceField* ff, Globals* simParams) :
85      stamps_(stamps), forceField_(ff), simParams_(simParams),
# Line 345 | Line 354 | namespace oopse {
354      int b;
355      int c;
356      int d;
357 +
358 +    std::map<int, std::set<int> > atomGroups;
359 +
360 +    Molecule::RigidBodyIterator rbIter;
361 +    RigidBody* rb;
362 +    Molecule::IntegrableObjectIterator ii;
363 +    StuntDouble* integrableObject;
364 +    
365 +    for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
366 +           integrableObject = mol->nextIntegrableObject(ii)) {
367 +
368 +      if (integrableObject->isRigidBody()) {
369 +          rb = static_cast<RigidBody*>(integrableObject);
370 +          std::vector<Atom*> atoms = rb->getAtoms();
371 +          std::set<int> rigidAtoms;
372 +          for (int i = 0; i < atoms.size(); ++i) {
373 +            rigidAtoms.insert(atoms[i]->getGlobalIndex());
374 +          }
375 +          for (int i = 0; i < atoms.size(); ++i) {
376 +            atomGroups.insert(std::map<int, std::set<int> >::value_type(atoms[i]->getGlobalIndex(), rigidAtoms));
377 +          }      
378 +      } else {
379 +        std::set<int> oneAtomSet;
380 +        oneAtomSet.insert(integrableObject->getGlobalIndex());
381 +        atomGroups.insert(std::map<int, std::set<int> >::value_type(integrableObject->getGlobalIndex(), oneAtomSet));        
382 +      }
383 +    }  
384 +
385 +    
386      
387      for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) {
388        a = bond->getAtomA()->getGlobalIndex();
# Line 356 | Line 394 | namespace oopse {
394        a = bend->getAtomA()->getGlobalIndex();
395        b = bend->getAtomB()->getGlobalIndex();        
396        c = bend->getAtomC()->getGlobalIndex();
397 +      std::set<int> rigidSetA = getRigidSet(a, atomGroups);
398 +      std::set<int> rigidSetB = getRigidSet(b, atomGroups);
399 +      std::set<int> rigidSetC = getRigidSet(c, atomGroups);
400  
401 <      exclude_.addPair(a, b);
402 <      exclude_.addPair(a, c);
403 <      exclude_.addPair(b, c);        
401 >      exclude_.addPairs(rigidSetA, rigidSetB);
402 >      exclude_.addPairs(rigidSetA, rigidSetC);
403 >      exclude_.addPairs(rigidSetB, rigidSetC);
404 >      
405 >      //exclude_.addPair(a, b);
406 >      //exclude_.addPair(a, c);
407 >      //exclude_.addPair(b, c);        
408      }
409  
410      for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) {
# Line 367 | Line 412 | namespace oopse {
412        b = torsion->getAtomB()->getGlobalIndex();        
413        c = torsion->getAtomC()->getGlobalIndex();        
414        d = torsion->getAtomD()->getGlobalIndex();        
415 +      std::set<int> rigidSetA = getRigidSet(a, atomGroups);
416 +      std::set<int> rigidSetB = getRigidSet(b, atomGroups);
417 +      std::set<int> rigidSetC = getRigidSet(c, atomGroups);
418 +      std::set<int> rigidSetD = getRigidSet(d, atomGroups);
419  
420 +      exclude_.addPairs(rigidSetA, rigidSetB);
421 +      exclude_.addPairs(rigidSetA, rigidSetC);
422 +      exclude_.addPairs(rigidSetA, rigidSetD);
423 +      exclude_.addPairs(rigidSetB, rigidSetC);
424 +      exclude_.addPairs(rigidSetB, rigidSetD);
425 +      exclude_.addPairs(rigidSetC, rigidSetD);
426 +
427 +      /*
428 +      exclude_.addPairs(rigidSetA.begin(), rigidSetA.end(), rigidSetB.begin(), rigidSetB.end());
429 +      exclude_.addPairs(rigidSetA.begin(), rigidSetA.end(), rigidSetC.begin(), rigidSetC.end());
430 +      exclude_.addPairs(rigidSetA.begin(), rigidSetA.end(), rigidSetD.begin(), rigidSetD.end());
431 +      exclude_.addPairs(rigidSetB.begin(), rigidSetB.end(), rigidSetC.begin(), rigidSetC.end());
432 +      exclude_.addPairs(rigidSetB.begin(), rigidSetB.end(), rigidSetD.begin(), rigidSetD.end());
433 +      exclude_.addPairs(rigidSetC.begin(), rigidSetC.end(), rigidSetD.begin(), rigidSetD.end());
434 +        
435 +      
436        exclude_.addPair(a, b);
437        exclude_.addPair(a, c);
438        exclude_.addPair(a, d);
439        exclude_.addPair(b, c);
440        exclude_.addPair(b, d);
441        exclude_.addPair(c, d);        
442 +      */
443      }
444  
379    Molecule::RigidBodyIterator rbIter;
380    RigidBody* rb;
445      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
446        std::vector<Atom*> atoms = rb->getAtoms();
447        for (int i = 0; i < atoms.size() -1 ; ++i) {
# Line 402 | Line 466 | namespace oopse {
466      int b;
467      int c;
468      int d;
469 +
470 +    std::map<int, std::set<int> > atomGroups;
471 +
472 +    Molecule::RigidBodyIterator rbIter;
473 +    RigidBody* rb;
474 +    Molecule::IntegrableObjectIterator ii;
475 +    StuntDouble* integrableObject;
476      
477 +    for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
478 +           integrableObject = mol->nextIntegrableObject(ii)) {
479 +
480 +      if (integrableObject->isRigidBody()) {
481 +          rb = static_cast<RigidBody*>(integrableObject);
482 +          std::vector<Atom*> atoms = rb->getAtoms();
483 +          std::set<int> rigidAtoms;
484 +          for (int i = 0; i < atoms.size(); ++i) {
485 +            rigidAtoms.insert(atoms[i]->getGlobalIndex());
486 +          }
487 +          for (int i = 0; i < atoms.size(); ++i) {
488 +            atomGroups.insert(std::map<int, std::set<int> >::value_type(atoms[i]->getGlobalIndex(), rigidAtoms));
489 +          }      
490 +      } else {
491 +        std::set<int> oneAtomSet;
492 +        oneAtomSet.insert(integrableObject->getGlobalIndex());
493 +        atomGroups.insert(std::map<int, std::set<int> >::value_type(integrableObject->getGlobalIndex(), oneAtomSet));        
494 +      }
495 +    }  
496 +
497 +    
498      for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) {
499        a = bond->getAtomA()->getGlobalIndex();
500        b = bond->getAtomB()->getGlobalIndex();        
# Line 414 | Line 506 | namespace oopse {
506        b = bend->getAtomB()->getGlobalIndex();        
507        c = bend->getAtomC()->getGlobalIndex();
508  
509 <      exclude_.removePair(a, b);
510 <      exclude_.removePair(a, c);
511 <      exclude_.removePair(b, c);        
509 >      std::set<int> rigidSetA = getRigidSet(a, atomGroups);
510 >      std::set<int> rigidSetB = getRigidSet(b, atomGroups);
511 >      std::set<int> rigidSetC = getRigidSet(c, atomGroups);
512 >
513 >      exclude_.removePairs(rigidSetA, rigidSetB);
514 >      exclude_.removePairs(rigidSetA, rigidSetC);
515 >      exclude_.removePairs(rigidSetB, rigidSetC);
516 >      
517 >      //exclude_.removePair(a, b);
518 >      //exclude_.removePair(a, c);
519 >      //exclude_.removePair(b, c);        
520      }
521  
522      for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) {
# Line 425 | Line 525 | namespace oopse {
525        c = torsion->getAtomC()->getGlobalIndex();        
526        d = torsion->getAtomD()->getGlobalIndex();        
527  
528 +      std::set<int> rigidSetA = getRigidSet(a, atomGroups);
529 +      std::set<int> rigidSetB = getRigidSet(b, atomGroups);
530 +      std::set<int> rigidSetC = getRigidSet(c, atomGroups);
531 +      std::set<int> rigidSetD = getRigidSet(d, atomGroups);
532 +
533 +      exclude_.removePairs(rigidSetA, rigidSetB);
534 +      exclude_.removePairs(rigidSetA, rigidSetC);
535 +      exclude_.removePairs(rigidSetA, rigidSetD);
536 +      exclude_.removePairs(rigidSetB, rigidSetC);
537 +      exclude_.removePairs(rigidSetB, rigidSetD);
538 +      exclude_.removePairs(rigidSetC, rigidSetD);
539 +
540 +      /*
541 +      exclude_.removePairs(rigidSetA.begin(), rigidSetA.end(), rigidSetB.begin(), rigidSetB.end());
542 +      exclude_.removePairs(rigidSetA.begin(), rigidSetA.end(), rigidSetC.begin(), rigidSetC.end());
543 +      exclude_.removePairs(rigidSetA.begin(), rigidSetA.end(), rigidSetD.begin(), rigidSetD.end());
544 +      exclude_.removePairs(rigidSetB.begin(), rigidSetB.end(), rigidSetC.begin(), rigidSetC.end());
545 +      exclude_.removePairs(rigidSetB.begin(), rigidSetB.end(), rigidSetD.begin(), rigidSetD.end());
546 +      exclude_.removePairs(rigidSetC.begin(), rigidSetC.end(), rigidSetD.begin(), rigidSetD.end());
547 +
548 +      
549        exclude_.removePair(a, b);
550        exclude_.removePair(a, c);
551        exclude_.removePair(a, d);
552        exclude_.removePair(b, c);
553        exclude_.removePair(b, d);
554        exclude_.removePair(c, d);        
555 +      */
556      }
557  
436    Molecule::RigidBodyIterator rbIter;
437    RigidBody* rb;
558      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
559        std::vector<Atom*> atoms = rb->getAtoms();
560        for (int i = 0; i < atoms.size() -1 ; ++i) {
# Line 519 | Line 639 | namespace oopse {
639      int useLennardJones = 0;
640      int useElectrostatic = 0;
641      int useEAM = 0;
642 +    int useSC = 0;
643      int useCharge = 0;
644      int useDirectional = 0;
645      int useDipole = 0;
# Line 557 | Line 678 | namespace oopse {
678        useLennardJones |= (*i)->isLennardJones();
679        useElectrostatic |= (*i)->isElectrostatic();
680        useEAM |= (*i)->isEAM();
681 +      useSC |= (*i)->isSC();
682        useCharge |= (*i)->isCharge();
683        useDirectional |= (*i)->isDirectional();
684        useDipole |= (*i)->isDipole();
# Line 607 | Line 729 | namespace oopse {
729      temp = useEAM;
730      MPI_Allreduce(&temp, &useEAM, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
731  
732 +    temp = useSC;
733 +    MPI_Allreduce(&temp, &useSC, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
734 +    
735      temp = useShape;
736      MPI_Allreduce(&temp, &useShape, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);  
737  
# Line 631 | Line 756 | namespace oopse {
756      fInfo_.SIM_uses_StickyPower = useStickyPower;
757      fInfo_.SIM_uses_GayBerne = useGayBerne;
758      fInfo_.SIM_uses_EAM = useEAM;
759 +    fInfo_.SIM_uses_SC = useSC;
760      fInfo_.SIM_uses_Shapes = useShape;
761      fInfo_.SIM_uses_FLARB = useFLARB;
762      fInfo_.SIM_uses_RF = useRF;
# Line 793 | Line 919 | namespace oopse {
919  
920  
921    }
796
797 #endif
798
799  double SimInfo::calcMaxCutoffRadius() {
800
801
802    std::set<AtomType*> atomTypes;
803    std::set<AtomType*>::iterator i;
804    std::vector<double> cutoffRadius;
805
806    //get the unique atom types
807    atomTypes = getUniqueAtomTypes();
808
809    //query the max cutoff radius among these atom types
810    for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
811      cutoffRadius.push_back(forceField_->getRcutFromAtomType(*i));
812    }
922  
814    double maxCutoffRadius = *(std::max_element(cutoffRadius.begin(), cutoffRadius.end()));
815 #ifdef IS_MPI
816    //pick the max cutoff radius among the processors
923   #endif
924  
925 <    return maxCutoffRadius;
820 <  }
821 <
822 <  void SimInfo::getCutoff(double& rcut, double& rsw) {
925 >  void SimInfo::setupCutoff() {          
926      
927 <    if (fInfo_.SIM_uses_Charges | fInfo_.SIM_uses_Dipoles | fInfo_.SIM_uses_RF) {
825 <        
826 <      if (!simParams_->haveCutoffRadius()){
827 <        sprintf(painCave.errMsg,
828 <                "SimCreator Warning: No value was set for the cutoffRadius.\n"
829 <                "\tOOPSE will use a default value of 15.0 angstroms"
830 <                "\tfor the cutoffRadius.\n");
831 <        painCave.isFatal = 0;
832 <        simError();
833 <        rcut = 15.0;
834 <      } else{
835 <        rcut = simParams_->getCutoffRadius();
836 <      }
837 <
838 <      if (!simParams_->haveSwitchingRadius()){
839 <        sprintf(painCave.errMsg,
840 <                "SimCreator Warning: No value was set for switchingRadius.\n"
841 <                "\tOOPSE will use a default value of\n"
842 <                "\t0.85 * cutoffRadius for the switchingRadius\n");
843 <        painCave.isFatal = 0;
844 <        simError();
845 <        rsw = 0.85 * rcut;
846 <      } else{
847 <        rsw = simParams_->getSwitchingRadius();
848 <      }
849 <
850 <    } else {
851 <      // if charge, dipole or reaction field is not used and the cutofff radius is not specified in
852 <      //meta-data file, the maximum cutoff radius calculated from forcefiled will be used
853 <        
854 <      if (simParams_->haveCutoffRadius()) {
855 <        rcut = simParams_->getCutoffRadius();
856 <      } else {
857 <        //set cutoff radius to the maximum cutoff radius based on atom types in the whole system
858 <        rcut = calcMaxCutoffRadius();
859 <      }
860 <
861 <      if (simParams_->haveSwitchingRadius()) {
862 <        rsw  = simParams_->getSwitchingRadius();
863 <      } else {
864 <        rsw = rcut;
865 <      }
866 <    
867 <    }
868 <  }
869 <
870 <  void SimInfo::setupCutoff() {    
871 <    getCutoff(rcut_, rsw_);    
872 <    double rnblist = rcut_ + 1; // skin of neighbor list
873 <
874 <    //Pass these cutoff radius etc. to fortran. This function should be called once and only once
875 <    
927 >    // Check the cutoff policy
928      int cp =  TRADITIONAL_CUTOFF_POLICY;
929      if (simParams_->haveCutoffPolicy()) {
930        std::string myPolicy = simParams_->getCutoffPolicy();
# Line 894 | Line 946 | namespace oopse {
946            }    
947          }          
948        }
949 <    }
949 >    }          
950 >    notifyFortranCutoffPolicy(&cp);
951  
952 <
952 >    // Check the Skin Thickness for neighborlists
953 >    double skin;
954      if (simParams_->haveSkinThickness()) {
955 <      double skinThickness = simParams_->getSkinThickness();
956 <    }
955 >      skin = simParams_->getSkinThickness();
956 >      notifyFortranSkinThickness(&skin);
957 >    }            
958 >        
959 >    // Check if the cutoff was set explicitly:
960 >    if (simParams_->haveCutoffRadius()) {
961 >      rcut_ = simParams_->getCutoffRadius();
962 >      if (simParams_->haveSwitchingRadius()) {
963 >        rsw_  = simParams_->getSwitchingRadius();
964 >      } else {
965 >        rsw_ = rcut_;
966 >      }
967 >      notifyFortranCutoffs(&rcut_, &rsw_);
968 >      
969 >    } else {
970 >      
971 >      // For electrostatic atoms, we'll assume a large safe value:
972 >      if (fInfo_.SIM_uses_Charges | fInfo_.SIM_uses_Dipoles | fInfo_.SIM_uses_RF) {
973 >        sprintf(painCave.errMsg,
974 >                "SimCreator Warning: No value was set for the cutoffRadius.\n"
975 >                "\tOOPSE will use a default value of 15.0 angstroms"
976 >                "\tfor the cutoffRadius.\n");
977 >        painCave.isFatal = 0;
978 >        simError();
979 >        rcut_ = 15.0;
980 >      
981 >        if (simParams_->haveElectrostaticSummationMethod()) {
982 >          std::string myMethod = simParams_->getElectrostaticSummationMethod();
983 >          toUpper(myMethod);
984 >          if (myMethod == "SHIFTED_POTENTIAL" || myMethod == "SHIFTED_FORCE") {
985 >            if (simParams_->haveSwitchingRadius()){
986 >              sprintf(painCave.errMsg,
987 >                      "SimInfo Warning: A value was set for the switchingRadius\n"
988 >                      "\teven though the electrostaticSummationMethod was\n"
989 >                      "\tset to %s\n", myMethod.c_str());
990 >              painCave.isFatal = 1;
991 >              simError();            
992 >            }
993 >          }
994 >        }
995 >      
996 >        if (simParams_->haveSwitchingRadius()){
997 >          rsw_ = simParams_->getSwitchingRadius();
998 >        } else {        
999 >          sprintf(painCave.errMsg,
1000 >                  "SimCreator Warning: No value was set for switchingRadius.\n"
1001 >                  "\tOOPSE will use a default value of\n"
1002 >                  "\t0.85 * cutoffRadius for the switchingRadius\n");
1003 >          painCave.isFatal = 0;
1004 >          simError();
1005 >          rsw_ = 0.85 * rcut_;
1006 >        }
1007 >        notifyFortranCutoffs(&rcut_, &rsw_);
1008 >      } else {
1009 >        // We didn't set rcut explicitly, and we don't have electrostatic atoms, so
1010 >        // We'll punt and let fortran figure out the cutoffs later.
1011 >        
1012 >        notifyFortranYouAreOnYourOwn();
1013  
1014 <    notifyFortranCutoffs(&rcut_, &rsw_, &rnblist, &cp);
1015 <    // also send cutoff notification to electrostatics
906 <    setElectrostaticCutoffRadius(&rcut_, &rsw_);
1014 >      }
1015 >    }
1016    }
1017  
1018    void SimInfo::setupElectrostaticSummationMethod( int isError ) {    
# Line 938 | Line 1047 | namespace oopse {
1047                } else {
1048                  // throw error        
1049                  sprintf( painCave.errMsg,
1050 <                         "SimInfo error: Unknown electrostaticSummationMethod. (Input file specified %s .)\n\telectrostaticSummationMethod must be one of: \"none\", \"shifted_potential\", \"shifted_force\", or \"reaction_field\".", myMethod.c_str() );
1050 >                         "SimInfo error: Unknown electrostaticSummationMethod.\n"
1051 >                         "\t(Input file specified %s .)\n"
1052 >                         "\telectrostaticSummationMethod must be one of: \"none\",\n"
1053 >                         "\t\"shifted_potential\", \"shifted_force\", or \n"
1054 >                         "\t\"reaction_field\".\n", myMethod.c_str() );
1055                  painCave.isFatal = 1;
1056                  simError();
1057                }    
# Line 959 | Line 1072 | namespace oopse {
1072            if (!simParams_->haveDampingAlpha()) {
1073              //throw error
1074              sprintf( painCave.errMsg,
1075 <                     "SimInfo warning: dampingAlpha was not specified in the input file. A default value of %f (1/ang) will be used.", alphaVal);
1075 >                     "SimInfo warning: dampingAlpha was not specified in the input file.\n"
1076 >                     "\tA default value of %f (1/ang) will be used.\n", alphaVal);
1077              painCave.isFatal = 0;
1078              simError();
1079            }
1080          } else {
1081            // throw error        
1082            sprintf( painCave.errMsg,
1083 <                   "SimInfo error: Unknown electrostaticScreeningMethod. (Input file specified %s .)\n\telectrostaticScreeningMethod must be one of: \"undamped\" or \"damped\".", myScreen.c_str() );
1083 >                   "SimInfo error: Unknown electrostaticScreeningMethod.\n"
1084 >                   "\t(Input file specified %s .)\n"
1085 >                   "\telectrostaticScreeningMethod must be one of: \"undamped\"\n"
1086 >                   "or \"damped\".\n", myScreen.c_str() );
1087            painCave.isFatal = 1;
1088            simError();
1089          }
# Line 975 | Line 1092 | namespace oopse {
1092      
1093      // let's pass some summation method variables to fortran
1094      setElectrostaticSummationMethod( &esm );
1095 +    notifyFortranElectrostaticMethod( &esm );
1096      setScreeningMethod( &sm );
1097      setDampingAlpha( &alphaVal );
1098      setReactionFieldDielectric( &dielectric );
1099 <    initFortranFF( &esm, &errorOut );
1099 >    initFortranFF( &errorOut );
1100    }
1101  
1102    void SimInfo::setupSwitchingFunction() {    

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines