示例#1
0
   /*
   * Identify all clusters in the system.
   */
   void ClusterIdentifier::identifyClusters()
   {

      // Initialize all data structures:
      // Setup a grid of empty cells
      cellList_.setup(system().boundary(), cutoff_);
      // Clear clusters array and all links
      clusters_.clear();
      for (int i = 0; i < links_.capacity(); ++i) {
         links_[i].clear();
      }

      // Build the cellList, associate Molecule with ClusterLink.
      // Iterate over molecules of species speciesId_
      System::MoleculeIterator molIter;
      Molecule::AtomIterator atomIter;
      system().begin(speciesId_, molIter);
      for ( ; molIter.notEnd(); ++molIter) {

         // Associate this Molecule with a ClusterLink
         links_[molIter->id()].setMolecule(*molIter.get());

         // Add atoms of type = atomTypeId_ to the CellList
         for (molIter->begin(atomIter); atomIter.notEnd(); ++atomIter) {
            if (atomIter->typeId() == atomTypeId_) {
               system().boundary().shift(atomIter->position());
               cellList_.addAtom(*atomIter);
            }

         }
      }

      // Identify all clusters
      Cluster* clusterPtr;
      ClusterLink* linkPtr;
      int clusterId = 0;
      system().begin(speciesId_, molIter);
      for ( ; molIter.notEnd(); ++molIter) {

         // Find the link with same index as this molecule
         linkPtr = &(links_[molIter->id()]);
         assert (&(linkPtr->molecule()) == molIter.get());

         // If this link is not in a cluster, begin a new cluster
         if (linkPtr->clusterId() == -1) {

            // Add a new empty cluster to clusters_ array
            clusters_.resize(clusterId+1);
            clusterPtr = &clusters_[clusterId];
            clusterPtr->clear();
            clusterPtr->setId(clusterId);

            // Identify molecules in this cluster
            clusterPtr->addLink(*linkPtr);
            workStack_.push(*linkPtr);
            while (workStack_.size() > 0) {
               processNextMolecule(*clusterPtr);
            }

            clusterId++;
         }

      }

      // Validity check - throws exception on failure.
      isValid();
   }
   /* 
   * Evaluate end-to-end vectors of all chains, add to ensemble.
   */
   void ClustersDynamics::sample(long iStep) 
   { if (isAtInterval(iStep)) {
         newClustersPtr_->sample(iStep);

         if (iStep == 0) {
            oldClustersPtr_->sample(iStep);
         }         
         int clustersCorrelations_[newClustersPtr_->clusterLengths_.size()][oldClustersPtr_->clusterLengths_.size()];
          
         for (int i = 0; i < newClustersPtr_->clusterLengths_.size(); i++) {
             for (int j = 0; j < oldClustersPtr_->clusterLengths_.size(); j++) {
                 clustersCorrelations_[i][j] = 0;
             }
         }

         System::MoleculeIterator molIter;
         for (system().begin(speciesId_, molIter); molIter.notEnd(); ++molIter) {
             clustersCorrelations_[newClustersPtr_->clusters_[molIter->id()].clusterId_][oldClustersPtr_->clusters_[molIter->id()].clusterId_] += 1 ;
         }

         bool usedIds_[newClustersPtr_->clusterLengths_.size()];
         int idConversions_[newClustersPtr_->clusterLengths_.size()];

         for (int i = 0; i < newClustersPtr_->clusterLengths_.size(); i++) {
             usedIds_[i] = false;
             idConversions_[i] = 0;
         }
         int id_ = 0;
         for (int i = 0; i < newClustersPtr_->clusterLengths_.size(); i++) {
           for (int j = 0; j < oldClustersPtr_->clusterLengths_.size(); j++) {
             //this only works if the criterion > 50%
                 if (clustersCorrelations_[i][j] > criterion_ * oldClustersPtr_->clusterLengths_[i]) id_ = i;
             }
             usedIds_[id_] = true;
             idConversions_[i] = id_;
         }
         int usedIdCounter_ = 0;
         for (int i = 0; i < newClustersPtr_->clusterLengths_.size(); i++) {
             if (idConversions_[i] == 0) {
                while (usedIds_[usedIdCounter_] == true) usedIdCounter_++;
                idConversions_[i] = usedIdCounter_;
                usedIds_[usedIdCounter_] = true;
             }  
         }

/*         for (system().begin(speciesId_, molIter); molIter.notEnd(); ++molIter) {
             newClustersPtr_->clusters_[molIter->id()].clusterId_ = idConversions_[newClustersPtr_->clusters_[molIter->id()].clusterId_];
         } */

         std::string fileName;
         fileName  = outputFileName();
         fileName += toString(iStep);
         fileName += ".dynamics";
         fileMaster().openOutputFile(fileName, outputFile_);
         for (int i = 0; i < newClustersPtr_->clusterLengths_.size(); i++) {
             outputFile_<<"<"<< i <<">"<<"("<<newClustersPtr_->clusterLengths_[i]<<") = ";
             for (int j=0; j < oldClustersPtr_->clusterLengths_.size(); j++) {
                  if (clustersCorrelations_[i][j] != 0){
                    outputFile_<<"<"<< j <<">["<<oldClustersPtr_->clusterLengths_[j]<<"]("<<clustersCorrelations_[i][j]<<") ";
                 }
             }
             outputFile_<<"\n";
         }
         outputFile_.close();

         ClustersFinder *tmp = oldClustersPtr_;
         oldClustersPtr_ = &(*newClustersPtr_);
         newClustersPtr_ = &(*tmp);
      }
   }