Exemple #1
0
   /*
   * Initialize all Bond objects for Molecules of one Species. (private)
   *
   * This functions assigns pointers to Atoms and bond types ids within a
   * contiguous block of Bond objects, and sets a pointer in each Molecule
   * to the first Bond in the associated block.
   */
   void Simulation::initializeSpeciesBonds(int iSpecies)
   {
      if (nBondType_ <= 0) {
         UTIL_THROW("nBondType_ must be positive");
      }

      Species*  speciesPtr = 0;
      Molecule* moleculePtr = 0;
      Bond*     bondPtr = 0;
      Atom*     firstAtomPtr;
      Atom*     atom0Ptr;
      Atom*     atom1Ptr;
      int       iMol, iBond, atom0Id, atom1Id, type;
      int       capacity, nBond;

      speciesPtr = &species(iSpecies);
      nBond      = speciesPtr->nBond();
      capacity   = speciesPtr->capacity();

      // Initialize pointers before loop
      moleculePtr = &molecules_[firstMoleculeIds_[iSpecies]];
      bondPtr = &bonds_[firstBondIds_[iSpecies]];

      // Loop over molecules in Species
      for (iMol = 0; iMol < capacity; ++iMol) {

         firstAtomPtr = &(moleculePtr->atom(0));
         moleculePtr->setFirstBond(*bondPtr);
         moleculePtr->setNBond(nBond);

         if (nBond > 0) {

            // Create bonds for a molecule
            for (iBond = 0; iBond < nBond; ++iBond) {

               // Get pointers to bonded atoms and bond type
               atom0Id  = speciesPtr->speciesBond(iBond).atomId(0);
               atom1Id  = speciesPtr->speciesBond(iBond).atomId(1);
               type     = speciesPtr->speciesBond(iBond).typeId();
               atom0Ptr = firstAtomPtr + atom0Id;
               atom1Ptr = firstAtomPtr + atom1Id;

               // Set fields of the Bond object
               bondPtr->setAtom(0, *atom0Ptr);
               bondPtr->setAtom(1, *atom1Ptr);
               bondPtr->setTypeId(type);

               // If MaskBonded, add each bonded atom to its partners Mask
               if (maskedPairPolicy_ == MaskBonded) {
                  atom0Ptr->mask().append(*atom1Ptr);
                  atom1Ptr->mask().append(*atom0Ptr);
               }

               ++bondPtr;
            }

         }
         ++moleculePtr;
      }

   }