コード例 #1
0
ファイル: OBMoleculeAnalytic.cpp プロジェクト: dkoes/leadit
//computes a set of solitary grid points that represent the interaction between
//this ligand and the provided receptor in some way
void OBAMolecule::computeInteractionGridPoints(OBAMolecule& receptor,
		MGrid& grid, double interactionDist,
		double maxClusterDist,
		unsigned minClusterPoints, double interactionPointRadius)
{
	grid.clear();
	//first construct a bounding box for the ligand while assembling a
	//vector of atomic coordinates
	BoundingBox ligandBox;
	vector<AtomPoint> points;
	points.reserve(mol.NumAtoms());
	for (OBAtomIterator aitr = mol.BeginAtoms(); aitr != mol.EndAtoms(); ++aitr)
	{
		OBAtom* atom = *aitr;
		points.push_back(AtomPoint(atom->x(), atom->y(), atom->z()));
		ligandBox.update(atom->x(), atom->y(), atom->z());
	}
	ligandBox.extend(interactionDist);

	//then identify all coordinates that are interacting
	double idistSq = interactionDist * interactionDist;
	OBMol& rmol = receptor.getMol();
	for (OBAtomIterator aitr = rmol.BeginAtoms(); aitr != rmol.EndAtoms();
			++aitr)
	{
		OBAtom* a = *aitr;
		if (ligandBox.contains(a->x(), a->y(), a->z()))
		{
			for (unsigned i = 0, n = points.size(); i < n; i++)
			{
				if (points[i].distSq(a->x(), a->y(), a->z()) <= idistSq)
				{
					points[i].interactingCnt++;
				}
			}
		}
	}

	//prune out non-interacting poitns
	vector<AtomPoint> tmp;
	tmp.reserve(points.size());
	for (unsigned i = 0, n = points.size(); i < n; i++)
	{
		if (points[i].interactingCnt > 0)
			tmp.push_back(points[i]);
	}
	points.swap(tmp);
	tmp.clear();

	//cluster these coordinates
	vector<vector<unsigned> > clusters;
	clusterPoints(points, maxClusterDist, clusters);

	//make the cluster centers the interaction grid points
	for (unsigned i = 0, n = clusters.size(); i < n; i++)
	{
		double xtot = 0, ytot = 0, ztot = 0;
		unsigned npts = clusters[i].size();

		if (npts >= minClusterPoints)
		{
			for (unsigned j = 0; j < npts; j++)
			{
				xtot += points[clusters[i][j]].x;
				ytot += points[clusters[i][j]].y;
				ztot += points[clusters[i][j]].z;
			}
			double xave = xtot / (double) npts;
			double yave = ytot / (double) npts;
			double zave = ztot / (double) npts;

			grid.setPoint(xave, yave, zave);
			if(interactionPointRadius > 0)
			{
				grid.markXYZSphere(xave,yave,zave,interactionPointRadius);
			}
		}
	}
}