Example #1
0
 inline Site from_string<Site>(
     const std::string & str
     )
 {
   std::string name, binding_state, internal_state;
   int selector = 0; // 0 = name, 1 = internal_state, 2 = binding_state
   BOOST_FOREACH( const char & c, str )
   {
     if (c == '~')
     {
       selector = 1;
     }
     else if (c == '!')
     {
       selector = 2;
     }
     else if (c == ' ')
     {
       continue;
     }
     else
     {
       if (selector == 0)
         name += c;
       else if (selector == 1)
         internal_state += c;
       else if (selector == 2)
         binding_state += c;
     }
   }
   return Site(name, internal_state, binding_state);
 }
Example #2
0
    // 使用 siteCode 从 sites 里查找第一个有相同 siteCode 的 site
    Site findSite(const QString &siteCode) const {
        foreach (const Site &s, sites) {
            if (siteCode == s.siteCode) {
                return s;
            }
        }

        return Site();
    }
Example #3
0
	void system::do_refinement()
	{
#if 0
		const int nactive_ptcl = active_ptcl.size();
		int nrefine = 0;
		int nsuccess  = 0;

		std::vector<vec3> new_sites_pos;
		std::vector<real> new_sites_rmax;
		for (int iptcl = 0; iptcl < nactive_ptcl; iptcl++)
		{
			const int i = active_ptcl[iptcl];
			if (!ptcl[i].is_refine()) continue;
			nrefine++;

			const Cell &ci = cells[i];
			const int nface = ci.faces.size();	
			const size_t size0 = new_sites_pos.size();
			for (int iface = 0; iface < nface; iface++)
			{
				Face &face = faces[ci.faces[iface]];
				if (face.s1 < 0) continue;
				face.s1 = int_map(face.s1);
				const int j = site_map(face.ngb<false>(i));
				if (j >= local_n)
				{
					new_sites_pos.resize(size0);
					new_sites_rmax.resize(size0);
					break;
				}
				else
				{
					new_sites_pos.push_back(face.centroid);
					new_sites_rmax.push_back(std::max(ptcl[i].rmax, ptcl[j].rmax));
				}
			}
			if (size0 != new_sites_pos.size())
				nsuccess++;
		}

		std::vector<Fluid> Uj       (2*import_n, 0.0);
		std::vector<real>  gradPsi_j(4*import_n, 0.0);

		const int n_new_sites = new_sites_pos.size();
		for (int i = 0; i < n_new_sites; i++)
		{
			std::vector< std::pair<int, std::pair<fvmhd3d::real, fvmhd3d::real> > > volume;
			const bool success_flag = insert_site(Site(new_sites_pos[i], -1-i, new_sites_rmax[i]), volume);
			assert(success_flag);

			for (int jsite = 0; jsite < (const int)volume.size(); jsite++)
			{
			}

		}
#endif
	}
Example #4
0
/** Admin command to check all objects.
 * \verbatim
 * This implements @wcheck/all.
 * \endverbatim
 * \param player the enactor.
 */
void
do_wcheck_all(dbref player)
{
    if (!Site(player)) {
        notify(player, T("You'd better check your site power first."));
        return;
    }
    notify(player, T("Running database topology warning checks"));
    run_topology();
    notify(player, T("Warning checks complete."));
}
void CCommandQueue::ProcessNextCommand()
{
	if (m_inside_commandqueue)
		return;

	if (m_exclusiveEngineLock)
		return;

	if (m_pEngine->IsBusy())
		return;

	++m_inside_commandqueue;

	if (m_CommandList.empty()) {
		// Possible sequence of events:
		// - Engine emits listing and operation finished
		// - Connection gets terminated
		// - Interface cannot obtain listing since not connected
		// - Yet getting operation successful
		// To keep things flowing, we need to advance the recursive operation.
		m_state.GetRemoteRecursiveOperation()->NextOperation();
	}

	while (!m_CommandList.empty()) {
		auto const& commandInfo = m_CommandList.front();

		int res = m_pEngine->Execute(*commandInfo.command);
		ProcessReply(res, commandInfo.command->GetId());
		if (res == FZ_REPLY_WOULDBLOCK) {
			break;
		}
	}

	--m_inside_commandqueue;

	if (m_CommandList.empty()) {
		if (m_exclusiveEngineRequest)
			GrantExclusiveEngineRequest();
		else
			m_state.NotifyHandlers(STATECHANGE_REMOTE_IDLE);

		if (!m_state.SuccessfulConnect()) {
			m_state.SetSite(Site());
		}
	}
}
Example #6
0
	size_t Sites::readSites(DigestStream& inStream) {
		// prepare to read from the stream
		size_t bytesReadOffset = inStream.getBytesRead();
		char scratch[1 << 10];			// scratch read buffer
		uint16_t nameLength = 0;		// length of tile type name
		SiteCount siteCount;			// number of sites
		SiteTypeIndex siteTypeIndex;	// site type index
		TileIndex tileIndex;			// site tile index
		SiteFlags flags;				// site flags
		uint16_t pinMap = 0;			// site pin map

		// read the section header
		string sectionName;
		inStream.readSectionHeader(sectionName);
		/// \todo Throw a proper exception.
		if(sectionName != ">>>>  Sites >>>>") throw -1;

		// initialize the site array
		inStream.read(siteCount);
		mSites.setSize(siteCount);
		mOut() << "\tReading " << siteCount << " sites..." << std::endl;
		// loop through each site
		for(SiteIndex i; i < siteCount; i++) {
			// read the site name
			inStream.read(nameLength);
			/// \todo Throw a proper exception.
			if(nameLength > sizeof(scratch)) throw -1;
			inStream.read(scratch, nameLength);
			scratch[nameLength] = 0;
			// read the site type index, tile index, flags, and pin map
			inStream.read(siteTypeIndex);
			inStream.read(tileIndex);
			inStream.read(flags);
			inStream.read(pinMap);
			// look up a reference for the site, and discard the const trait
			Site& site = const_cast<Site&>(mSites[i]);
			site = Site(scratch, mSiteTypes[siteTypeIndex], tileIndex, flags, 
				mPrimitivePinMaps[pinMap]);
			mSiteNameToSiteIndex[scratch] = i;
		}

		// return the number of bytes read
		return inStream.getBytesRead() - bytesReadOffset;
	}
Example #7
0
/** Determine what atoms each mask pertains to for the current parm file.
  */
Action::RetType Action_NMRrst::Setup(ActionSetup& setup) {
  if (!viewrst_.empty() && rsttop_ == 0) rsttop_ = setup.TopAddress();
  // ---------------------------------------------
  // Set up NOEs from file.
  for (noeDataArray::iterator noe = NOEs_.begin(); noe != NOEs_.end(); ++noe) {
    if (setup.Top().SetupIntegerMask( noe->dMask1_ )) return Action::ERR;
    if (setup.Top().SetupIntegerMask( noe->dMask2_ )) return Action::ERR;
    if (noe->dMask1_.None() || noe->dMask2_.None()) {
      mprintf("Warning: One or both masks for NOE '%s' have no atoms (%i and %i).\n",
              noe->dist_->legend(), noe->dMask1_.Nselected(),
              noe->dMask2_.Nselected());
      noe->active_ = false; 
    } else
      noe->active_ = true;
  }
  // ---------------------------------------------
  // Set up potential NOE sites.
  if (findNOEs_) {
    if (setup.Top().SetupCharMask( Mask_ )) return Action::ERR;
    Mask_.MaskInfo();
    if (Mask_.None()) return Action::SKIP;
    SiteArray potentialSites; // .clear();
    AtomMap resMap;
    resMap.SetDebug( debug_ );
    std::vector<bool> selected;
    Range soluteRes = setup.Top().SoluteResidues();
    for (Range::const_iterator res = soluteRes.begin(); res != soluteRes.end(); ++res)
    {
      int res_first_atom = setup.Top().Res(*res).FirstAtom();
      selected.assign( setup.Top().Res(*res).NumAtoms(), false );
      // Find symmetric atom groups.
      AtomMap::AtomIndexArray symmGroups;
      if (resMap.SymmetricAtoms(setup.Top(), symmGroups, *res)) return Action::ERR;
      // DEBUG
      if (debug_ > 0) {
        mprintf("DEBUG: Residue %i: symmetric atom groups:\n", *res + 1);
        for (AtomMap::AtomIndexArray::const_iterator grp = symmGroups.begin();
                                                     grp != symmGroups.end(); ++grp)
        {
          mprintf("\t\t");
          for (AtomMap::Iarray::const_iterator at = grp->begin();
                                               at != grp->end(); ++at)
            mprintf(" %s", setup.Top().TruncAtomNameNum( *at ).c_str());
          mprintf("\n");
        }
      }
      // Each symmetric hydrogen atom group is a site.
      for (AtomMap::AtomIndexArray::const_iterator grp = symmGroups.begin();
                                                   grp != symmGroups.end(); ++grp)
      { // NOTE: If first atom is H all should be H.
        if ( setup.Top()[ grp->front() ].Element() == Atom::HYDROGEN )
        {
          Iarray symmAtomGroup;
          for (Iarray::const_iterator at = grp->begin();
                                      at != grp->end(); ++at)
            if (Mask_.AtomInCharMask( *at ))
              symmAtomGroup.push_back( *at );
          if (!symmAtomGroup.empty()) {
            potentialSites.push_back( Site(*res, symmAtomGroup) );
            // Mark symmetric atoms as selected.
            for (AtomMap::Iarray::const_iterator at = grp->begin();
                                                 at != grp->end(); ++at)
              selected[ *at - res_first_atom ] = true;
          }
        }
      }
      // All other non-selected hydrogens bonded to same heavy atom are sites.
      for (int ratom = res_first_atom; ratom != setup.Top().Res(*res).LastAtom(); ++ratom)
      {
        if ( setup.Top()[ratom].Element() != Atom::HYDROGEN ) {
          Iarray heavyAtomGroup;
          for (Atom::bond_iterator ba = setup.Top()[ratom].bondbegin();
                                   ba != setup.Top()[ratom].bondend(); ++ba)
            if ( Mask_.AtomInCharMask(*ba) && 
                 *ba >= res_first_atom && 
                 *ba < setup.Top().Res(*res).LastAtom() )
            {
              if ( !selected[ *ba - res_first_atom ] &&
                   setup.Top()[ *ba ].Element() == Atom::HYDROGEN )
                heavyAtomGroup.push_back( *ba );
            }
          if (!heavyAtomGroup.empty())
            potentialSites.push_back( Site(*res, heavyAtomGroup) );
        }
      }
    }
    mprintf("\t%zu potential NOE sites:\n", potentialSites.size());
    for (SiteArray::const_iterator site = potentialSites.begin();
                                   site != potentialSites.end(); ++site)
    {
      mprintf("  %u\tRes %i:", site - potentialSites.begin(), site->ResNum()+1);
      for (unsigned int idx = 0; idx != site->Nindices(); ++idx)
        mprintf(" %s", setup.Top().TruncAtomNameNum( site->Idx(idx) ).c_str());
      mprintf("\n");
    }
    if (noeArray_.empty()) {
      size_t siteArraySize = 0;
      // Set up all potential NOE pairs. Keep track of size.
      for (SiteArray::const_iterator site1 = potentialSites.begin();
                                     site1 != potentialSites.end(); ++site1)
      {
        for (SiteArray::const_iterator site2 = site1 + 1;
                                       site2 != potentialSites.end(); ++site2)
        {
          if (site1->ResNum() != site2->ResNum()) {
            std::string legend = site1->SiteLegend(setup.Top()) + "--" +
                                 site2->SiteLegend(setup.Top());
            DataSet* ds = 0;
            if (series_) {
              ds = masterDSL_->AddSet(DataSet::FLOAT,
                                      MetaData(setname_, "foundNOE", noeArray_.size()));
              if (ds == 0) return Action::ERR;
              // Construct a data set name.
              ds->SetLegend(legend);
            }
            noeArray_.push_back( NOEtype(*site1, *site2, ds, legend) );
            siteArraySize += (2 * sizeof(int) * site1->Nindices()) +
                             (2 * sizeof(int) * site2->Nindices());
          }
        }
      }
      numNoePairs_ = noeArray_.size();
      size_t siteSize = sizeof(int) + (2 * sizeof(Iarray)) + sizeof(Site);
      size_t noeSize = (2 * siteSize) + sizeof(DataSet*) + sizeof(double) 
                       + sizeof(NOEtype);
      if (series_) noeSize += sizeof(std::vector<float>);
      size_t noeArraySize = (noeSize * numNoePairs_) + siteArraySize;
      if (series_)
        noeArraySize += (setup.Nframes() * numNoePairs_ * sizeof(float));
      mprintf("\t%zu potential NOE pairs. Estimated memory usage is %s\n",
              numNoePairs_, ByteString(noeArraySize, BYTE_DECIMAL).c_str());
    } else if (numNoePairs_ != potentialSites.size()) {
      mprinterr("Warning: Found NOE matrix has already been set up for %zu potential\n"
                "Warning:   NOEs, but %zu NOEs currently found.\n", numNoePairs_,
                potentialSites.size());
      return Action::SKIP;
    }
  }
  // ---------------------------------------------
  // Set up NOEs specified on the command line
  if (!Pairs_.empty()) {
    if (!specifiedNOEs_.empty()) {
      mprintf("Warning: Specifying NOEs currently only works with first topology used.\n");
      return Action::SKIP;
    }
    for (MaskPairArray::iterator mp = Pairs_.begin(); mp != Pairs_.end(); mp++) {
      if (setup.Top().SetupIntegerMask( mp->first )) return Action::ERR;
      int res1 = CheckSameResidue(setup.Top(), mp->first);
      if (res1 < 0) continue;
      if (setup.Top().SetupIntegerMask( mp->second )) return Action::ERR;
      int res2 = CheckSameResidue(setup.Top(), mp->second);
      if (res2 < 0) continue;
      Site site1( res1, mp->first.Selected() );
      Site site2( res2, mp->second.Selected() );
      std::string legend = site1.SiteLegend(setup.Top()) + "--" +
                           site2.SiteLegend(setup.Top());
      DataSet* ds = 0;
      if (series_) {
        ds = masterDSL_->AddSet(DataSet::FLOAT,
                                MetaData(setname_, "specNOE", specifiedNOEs_.size()));
        if (ds == 0) return Action::ERR;
        ds->SetLegend(legend);
      }
      specifiedNOEs_.push_back( NOEtype(site1, site2, ds, legend) );
    }
  } 
  // Set up imaging info for this parm
  Image_.SetupImaging( setup.CoordInfo().TrajBox().Type() );
  if (Image_.ImagingEnabled())
    mprintf("\tImaged.\n");
  else
    mprintf("\tImaging off.\n");

  return Action::OK;  
}
Example #8
0
	void system::do_derefinement()
	{
#if 0
		const int nactive_ptcl = active_ptcl.size();
		int nderefine = 0;
		int nsuccess  = 0;
			
		std::vector<Fluid> Uj       (2*import_n, 0.0);
		std::vector<real>  gradPsi_j(4*import_n, 0.0);
		std::vector<int >  derefined;

		for (int iptcl = 0; iptcl < nactive_ptcl; iptcl++)
		{
			const int i = active_ptcl[iptcl];
			if (!ptcl[i].is_derefine()) continue;
			nderefine++;

			std::vector< std::pair<int, std::pair<fvmhd3d::real, fvmhd3d::real> > > volume;
			const bool success_flag = remove_site(Site(ptcl[i].pos(), i, ptcl[i].rmax), volume);
#if 0
			fprintf(stderr, " deref= %d   i= %d  success= %s \n",
					nderefine, i, success_flag ? "true" : "false");
#endif

			if (!success_flag) // || nsuccess > 0)
			{
				ptcl[i].unset_derefine();
				continue;
			}
			nsuccess++;
			derefined.push_back(i);

			real Vi = 0.0;
			for (int jptcl = 0; jptcl < (const int)volume.size(); jptcl++)
			{
				const real vold = volume[jptcl].second.first;
				const real vnew = volume[jptcl].second.second;
				const real dv   = vnew - vold;
				Vi += dv;
			}
#if 0
			if (!(std::abs(Vi - cells[i].Volume) < SMALLDIFF * Vi))
			{
				fprintf(stderr, " Vi= %g   cells[i].Volume= %g   diff= %g  %d %d \n",
						Vi, cells[i].Volume, Vi - cells[i].Volume, local_n, global_n);
			}
			assert(std::abs(Vi - cells[i].Volume) < SMALLDIFF * Vi);
#endif
			assert(Vi > 0.0);
			const real invVi = 1.0/Vi;

			for (int jptcl = 0; jptcl < (const int)volume.size(); jptcl++)
			{
				const int  j    = site_map(volume[jptcl].first);
				const real vold = volume[jptcl].second.first;
				const real vnew = volume[jptcl].second.second;
				const real dv   = vnew - vold;
				assert(vold > 0.0);
				if (!(dv > -SMALLDIFF*vold))
				{
					fprintf(stderr , "i= %d j= %d [ %d ] :: vnew= %g   vold= %g   dv= %g \n",
							i, j, jptcl,
							vnew, vold, dv);
				}
				assert(dv > -SMALLDIFF*vold);
				const real dv_over_Vi = dv * invVi;
				if (j >= local_n)
				{
					const int j1 = j - local_n;
					assert(false);
					for (int k = 0; k < Fluid::NFLUID; k++)
					{
						Uj[(j1 << 1) + 0][k] +=  U[i][k] * dv_over_Vi;
						Uj[(j1 << 1) + 1][k] += dU[i][k] * dv_over_Vi;
					}

					for (int k = 0; k < 4; k++)
						gradPsi_j[(j1 << 2) + k] += gradPsi[(i << 2) + k] * dv_over_Vi;
				}
				else
				{
					for (int k = 0; k < Fluid::NFLUID; k++)
					{
						U [j][k] +=  U[i][k] * dv_over_Vi;
						dU[j][k] += dU[i][k] * dv_over_Vi;
					}

					for (int k = 0; k < 4; k++)
						gradPsi[(j << 2) + k] += gradPsi[(i << 2) + k] * dv_over_Vi;
				}
			}
		}

#if 0
		std::vector<Fluid> Fluid_send[NMAXPROC];
		std::vector<Fluid> Fluid_recv[NMAXPROC];
		std::vector<real> gradPsi_send[NMAXPROC];
		std::vector<real> gradPsi_recv[NMAXPROC];

		for (int i = 0; i < (const int)return_site_list.size(); i++)
		{
			const std::pair<int, int> p = return_site_list[i];
			const int proc = p.first;
			const int jidx = p.second;

			assert(jidx >= local_n);
			const int j2 = (jidx - local_n) << 1;
			Fluid_send[proc].push_back(Uj[j2 + 0]);
			Fluid_send[proc].push_back(Uj[j2 + 1]);

			const int j4 = (jidx-local_n) << 2;
			gradPsi_send[proc].push_back(gradPsi_j[j4 + 0]);
			gradPsi_send[proc].push_back(gradPsi_j[j4 + 1]);
			gradPsi_send[proc].push_back(gradPsi_j[j4 + 2]);
			gradPsi_send[proc].push_back(gradPsi_j[j4 + 3]);
		}

		myMPI::all2all(Fluid_send, Fluid_recv, myproc, nproc, mpi_debug_flag);
		myMPI::all2all(gradPsi_send, gradPsi_recv, myproc, nproc, mpi_debug_flag);

		int iloc = 0;
		for (int p = 0; p < nproc; p++) 
			for (size_t q = 0; q < Fluid_recv[p].size(); q += 2)
			{
				assert(p != myproc);
				const int idx = return_site_map[iloc++];
				assert(idx < local_n);
				if (!ptcl[idx].is_active())
				{
					for (int k = 0; k < Fluid::NFLUID; k++)
					{
						U [idx][k] += Fluid_recv[p][q + 0][k];
						dU[idx][k] += Fluid_recv[p][q + 1][k];
					}
					gradPsi[(idx<<2) + 0] += gradPsi_recv[p][(q<<1) + 0];
					gradPsi[(idx<<2) + 1] += gradPsi_recv[p][(q<<1) + 1];
					gradPsi[(idx<<2) + 2] += gradPsi_recv[p][(q<<1) + 2];
					gradPsi[(idx<<2) + 3] += gradPsi_recv[p][(q<<1) + 3];
				}
			}

		assert(iloc == (int)export_site_list.size());
#endif

		fprintf(stderr, " nderefine= %d   nsuccess= %d  [ %g ]\n",
				nderefine, nsuccess, nderefine > 0 ? (real)nsuccess/nderefine : 0.0);
		assert(nsuccess == (int)derefined.size());

		for (int i = 0; i < nsuccess; i++)
		{
			ptcl[derefined[i]].set_virtual();
//			scheduler.remove<true>((int)ptcl[derefined[i]].rung[0], derefined[i]);
			assert(ptcl[derefined[i]].is_virtual());
			virtual_n++;
		}

#if 0
		if (derefined.size() == 0) return;

		fprintf(stderr , "local_n_old= %d ", local_n);

		int idx = 0;
		while (idx++ < local_n)
		{
			if (!ptcl[idx-1].is_derefine()) continue;

			idx--;

			assert(ptcl[idx].is_active());
			local_n--;
			std::swap(ptcl [idx], ptcl [local_n]);
			std::swap(ptcl_ppos[idx], ptcl_ppos[local_n]);
			std::swap( U   [idx],  U   [local_n]);
			std::swap(dU   [idx], dU   [local_n]);
			std::swap(Wgrad[idx], Wgrad[local_n]);
			std::swap(gradPsi[(idx<<2) + 0], gradPsi[(local_n<<2)+0]);
			std::swap(gradPsi[(idx<<2) + 1], gradPsi[(local_n<<2)+1]);
			std::swap(gradPsi[(idx<<2) + 2], gradPsi[(local_n<<2)+2]);
			std::swap(gradPsi[(idx<<2) + 3], gradPsi[(local_n<<2)+3]);
		}
		fprintf(stderr , "local_n_new= %d ", local_n);
			
		const int n_glob0 = global_n;
		MPI_Allreduce(&local_n, &global_n, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);

		if (myproc == 0)
			fprintf(stderr, " myproc= %d :  deref %d cells :: global_n_old= %d  global_n= %d \n",
					myproc, n_glob0 - global_n, n_glob0,  global_n);
#endif
#endif
	}
Example #9
0
inline Lattice::Site Lattice::random_site() const
{
  return Site(floor(size * random()));
}
Site Site::operator-(int direction)
{
	return Site( *lattice_, index_ - lattice_->jump(direction) );
}