/* 
   * Read parameter speciesId.
   */
   void EndSwapMove::readParameters(std::istream& in) 
   {
      readProbability(in);
      read<int>(in, "speciesId", speciesId_);

      Species* speciesPtr = &(simulation().species(speciesId_));
      int nAtom = speciesPtr->nAtom();

      // Preconditions
      if (speciesPtr->isMutable()) {
         UTIL_THROW("EndSwapMove on mutable Species");
      }
      Linear* linearPtr = dynamic_cast<Linear*>(speciesPtr);
      if (linearPtr == 0) {
         UTIL_THROW("EndSwapMove on Species that is not a Linear");
      }

      // Allocate memory 
      atomTypeIds_.allocate(nAtom);
      positions_.allocate(nAtom);

      // Set array of atom type ids
      for (int i = 0; i < nAtom; ++i) {
           atomTypeIds_[i] = speciesPtr->atomTypeId(i); 
      }
   }
   /*
   * Load state from a binary file archive.
   */
   void McMuExchange::loadParameters(Serializable::IArchive& ar)
   { 
      loadInterval(ar);  
      loadOutputFileName(ar);  
      loadParameter(ar, "speciesId", speciesId_);
      ar >> nAtom_;
      Species* speciesPtr;
      speciesPtr = &(system().simulation().species(speciesId_));
      if (nAtom_ != speciesPtr->nAtom()) {
         UTIL_THROW("Inconsistent values of nAtom on loading");
      }
      newTypeIds_.allocate(nAtom_);
      loadDArray(ar, "newTypeIds", newTypeIds_, nAtom_);

      flipAtomIds_.allocate(nAtom_);
      isAtomFlipped_.allocate(nAtom_);
      for (int i = 0; i < nAtom_; ++i) {
         if (newTypeIds_[i] != speciesPtr->atomTypeId(i)) {
            flipAtomIds_.append(i);
            isAtomFlipped_[i] = 1;
         } else {
            isAtomFlipped_[i] = 0;
         }
      }
      accumulators_.allocate(speciesPtr->capacity());

      ar >> nMolecule_;
      for (int i = 0; i < nMolecule_; ++i) {
         ar >> accumulators_[i];
      }
      isInitialized_ = true;
   }
Exemple #3
0
   /*
   * Initialize all Molecule and Atom objects for one Species (private).
   *
   * This function creates associations between Species, Molecule, and
   * Atom objects for all molecules of one species, and sets atom typeIds.
   *
   * For each molecule, it sets the id, species pointer, nAtom, and the 
   * firstAtom pointer. The molecule id is only unique within each species.
   *
   * For each atom, it sets the molecule pointer and an integer typeId.
   *
   * This method also pushes all molecules of the species onto the
   * reservoir, pushing them in order of decreasing molecule id.
   */
   void Simulation::initializeSpecies(int iSpecies)
   {

      Species*  speciesPtr;
      Molecule* moleculePtr;
      Atom*     atomPtr;
      int       iMol, iAtom;
      int       capacity, nAtom;

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

      // Initialize pointers before loop
      moleculePtr = &molecules_[firstMoleculeIds_[iSpecies]];
      atomPtr     = &atoms_[firstAtomIds_[iSpecies]];

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

         // Initialize a Molecule
         moleculePtr->setId(iMol);
         moleculePtr->setSpecies(*speciesPtr);
         moleculePtr->setNAtom(nAtom);
         moleculePtr->setFirstAtom(*atomPtr);

         // Loop over atoms in a molecule, set molecule and atom TypeId
         for (iAtom = 0; iAtom < nAtom; ++iAtom) {
            atomPtr->setMolecule(*moleculePtr);
            atomPtr->setTypeId(speciesPtr->atomTypeId(iAtom));
            ++atomPtr;
         }

         ++moleculePtr;
      }

      // Push all molecules of this species onto the reservoir stack
      // Push on in reverse order, so that they pop off in sequence
      moleculePtr = &molecules_[firstMoleculeIds_[iSpecies] + capacity - 1];
      for (iMol = 0; iMol < capacity; ++iMol) {
         speciesPtr->reservoir().push(*moleculePtr);
         --moleculePtr;
      }

   }
   /* 
   * Load from archive.
   */
   void EndSwapMove::loadParameters(Serializable::IArchive& ar) 
   {
      McMove::loadParameters(ar);
      loadParameter<int>(ar, "speciesId", speciesId_);
      ar & atomTypeIds_;

      // Validate
      Species* speciesPtr = &(simulation().species(speciesId_));
      int nAtom = speciesPtr->nAtom();
      if (speciesPtr->isMutable()) {
         UTIL_THROW("EndSwapMove applied to mutable species");
      }
      Linear* linearPtr = dynamic_cast<Linear*>(speciesPtr);
      if (linearPtr == 0) {
         UTIL_THROW("EndSwapMove applied to species that is not Linear");
      }
      if (nAtom != atomTypeIds_.capacity()) {
         UTIL_THROW("Inconsistent capacity for atomTypeIds array");
      }
  
      positions_.allocate(nAtom);
   }
Exemple #5
0
   /*
   * Allocate and initialize all private data (private method).
   *
   * Allocates global arrays (molecules_, atoms_, bonds_, angles_) and the
   * arrays first<class>Ids_ of integers to species blocks. Initializes:
   *
   *   - Capacity values and first<class>Ptr_ addresses.
   *   - Integer ids for Species and Molecule objects.
   *   - Pointers between Species, Molecule, and Atom objects
   *   - Atom typeIds and all Bond and Angle objects.
   */
   void Simulation::initialize()
   {
      //Preconditions
      assert(nSpecies() > 0);
      if (nSpecies() <= 0) {
         UTIL_THROW("Error: nSpecies() <= 0 in Simulation::initialize()");
      }
      if (nBondType_ < 0) {
         UTIL_THROW("Error: nBondType < 0 in Simulation::initialize()");
      }
      #ifdef INTER_ANGLE
      if (nAngleType_ < 0) {
         UTIL_THROW("Error: nAngleType < 0 in Simulation::initialize()");
      }
      #endif
      #ifdef INTER_DIHEDRAL
      if (nDihedralType_ < 0) {
         UTIL_THROW("Error: nDihedralType < 0 in Simulation::initialize()");
      }
      #endif
      #ifdef MCMD_LINK
      if (nLinkType_ < 0) {
         UTIL_THROW("Error: nLinkType_ < 0 in Simulation::initialize()");
      }
      #endif

      Species *speciesPtr;
      int  nAtom, nBond, iSpecies;
      int capacity;
      #ifdef INTER_ANGLE
      int  nAngle;
      #endif
      #ifdef INTER_DIHEDRAL
      int  nDihedral;
      #endif

      // Allocate arrays of pointers to first object in a species block.
      firstMoleculeIds_.allocate(nSpecies());
      firstAtomIds_.allocate(nSpecies());
      if (nBondType_ > 0) {
         firstBondIds_.allocate(nSpecies());
      }
      #ifdef INTER_ANGLE
      if (nAngleType_ > 0) {
         firstAngleIds_.allocate(nSpecies());
      }
      #endif
      #ifdef INTER_DIHEDRAL
      if (nDihedralType_ > 0) {
         firstDihedralIds_.allocate(nSpecies());
      }
      #endif

      // Count Molecules, Atoms and Groups.
      moleculeCapacity_ = 0;
      atomCapacity_     = 0;
      bondCapacity_     = 0;
      #ifdef INTER_ANGLE
      angleCapacity_    = 0;
      #endif
      #ifdef INTER_DIHEDRAL
      dihedralCapacity_  = 0;
      #endif
      for (iSpecies = 0; iSpecies < nSpecies(); ++iSpecies) {
         speciesPtr = &species(iSpecies);

         // Check species id
         if (speciesPtr->id() != iSpecies) {
            UTIL_THROW("Inconsistent species ids");
         }
         //speciesPtr->setId(iSpecies);

         // Set indexes of first objects of the blocks for this species
         firstMoleculeIds_[iSpecies] = moleculeCapacity_;
         firstAtomIds_[iSpecies] = atomCapacity_;
         if (nBondType_ > 0) {
            firstBondIds_[iSpecies] = bondCapacity_;
         }
         #ifdef INTER_ANGLE
         if (nAngleType_ > 0) {
            firstAngleIds_[iSpecies] = angleCapacity_;
         }
         #endif
         #ifdef INTER_DIHEDRAL
         if (nDihedralType_ > 0) {
            firstDihedralIds_[iSpecies] = dihedralCapacity_;
         }
         #endif

         // Increment total capacity values
         capacity = speciesPtr->capacity();
         nAtom = speciesPtr->nAtom();
         moleculeCapacity_ += capacity;
         atomCapacity_ += capacity*nAtom;
         if (nBondType_ > 0) {
            nBond    = speciesPtr->nBond();
            bondCapacity_ += capacity*nBond;
         }
         #ifdef INTER_ANGLE
         if (nAngleType_ > 0) {
            nAngle = speciesPtr->nAngle();
            angleCapacity_ += capacity*nAngle;
         }
         #endif
         #ifdef INTER_DIHEDRAL
         if (nDihedralType_ > 0) {
            nDihedral = speciesPtr->nDihedral();
            dihedralCapacity_ += capacity*nDihedral;
         }
         #endif
      }

      // Allocate global array of atoms (static member of Atom class).
      Atom::allocate(atomCapacity_, atoms_);

      // Allocate other global arrays (members of Simulation).
      molecules_.allocate(moleculeCapacity_);

      // Initialize all Atoms and Molecule objects.
      for (iSpecies = 0; iSpecies < nSpecies(); ++iSpecies) {
         speciesPtr = &species(iSpecies);
         initializeSpecies(iSpecies);
      }

      // Initialize bonds.
      if (nBondType_ > 0) {
         if (bondCapacity_ > 0) {
            bonds_.allocate(bondCapacity_);
         } else {
            bonds_.allocate(1);
         }
         for (iSpecies = 0; iSpecies < nSpecies(); ++iSpecies) {
            initializeSpeciesBonds(iSpecies);
         }
      }

      #ifdef INTER_ANGLE
      // Initialize angles.
      if (nAngleType_ > 0) {
         if (angleCapacity_ > 0) {
            angles_.allocate(angleCapacity_);
         } else {
            angles_.allocate(1);
         }
         for (iSpecies = 0; iSpecies < nSpecies(); ++iSpecies) {
            initializeSpeciesAngles(iSpecies);
         }
      }
      #endif

      #ifdef INTER_DIHEDRAL
      // Initialize dihedrals.
      if (nDihedralType_ > 0) {
         if (dihedralCapacity_ > 0) {
            dihedrals_.allocate(dihedralCapacity_);
         } else {
            dihedrals_.allocate(1);
         }
         for (iSpecies = 0; iSpecies < nSpecies(); ++iSpecies) {
            initializeSpeciesDihedrals(iSpecies);
         }
      }
      #endif

   }