Skip to content

Commit

Permalink
use templated functions to create grids (#136)
Browse files Browse the repository at this point in the history
* replace CreateGridX with a templated function

* remove statements with no effect

* lint
  • Loading branch information
ggutierrez-sunbright authored Dec 6, 2024
1 parent c59be78 commit cf10d12
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 69 deletions.
29 changes: 26 additions & 3 deletions include/RbtBaseIdxSF.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
#ifndef _RBTBASEIDXSF_H_
#define _RBTBASEIDXSF_H_

#include <type_traits>

#include "RbtBaseGrid.h"
#include "RbtBaseSF.h"
#include "RbtDockingSite.h"
#include "RbtInteractionGrid.h"
#include "RbtNonBondedGrid.h"
#include "RbtNonBondedHHSGrid.h"
#include "RbtWorkSpace.h"

class RbtBaseIdxSF: public virtual RbtBaseSF {
public:
Expand Down Expand Up @@ -47,9 +52,8 @@ class RbtBaseIdxSF: public virtual RbtBaseSF {
///////////////////
RbtBaseIdxSF();

RbtInteractionGridPtr CreateInteractionGrid() const;
RbtNonBondedGridPtr CreateNonBondedGrid() const;
RbtNonBondedHHSGridPtr CreateNonBondedHHSGrid() const;
template <class T>
SmartPtr<T> CreateGrid() const;
RbtDouble GetMaxError() const;
// DM 12 Apr 2002
// Returns the maximum range of the scoring function,
Expand Down Expand Up @@ -81,4 +85,23 @@ class RbtBaseIdxSF: public virtual RbtBaseSF {
RbtDouble m_border;
};

template <class T>
SmartPtr<T> RbtBaseIdxSF::CreateGrid() const {
// Create a grid covering the docking site
static_assert(std::is_base_of<RbtBaseGrid, T>::value, "T must inherit from RbtBaseGrid");
RbtDockingSitePtr spDS = GetWorkSpace()->GetDockingSite();
if (spDS.Null()) return SmartPtr<T>();

// Extend grid by _BORDER, mainly to allow for the possibility of polar hydrogens
// falling outside of the docking site
RbtCoord minCoord = spDS->GetMinCoord() - m_border;
RbtCoord maxCoord = spDS->GetMaxCoord() + m_border;
RbtVector recepExtent = maxCoord - minCoord;
RbtVector gridStep(m_gridStep, m_gridStep, m_gridStep);
RbtUInt nX = int(recepExtent.x / gridStep.x) + 1;
RbtUInt nY = int(recepExtent.y / gridStep.y) + 1;
RbtUInt nZ = int(recepExtent.z / gridStep.z) + 1;
return SmartPtr<T>(new T(minCoord, gridStep, nX, nY, nZ));
}

#endif //_RBTBASEIDXSF_H_
4 changes: 2 additions & 2 deletions src/lib/RbtAromIdxSF.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ void RbtAromIdxSF::SetupReceptor() {
ClearReceptor();
if (GetReceptor().Null()) return;

m_spAromGrid = CreateInteractionGrid();
m_spGuanGrid = CreateInteractionGrid();
m_spAromGrid = CreateGrid<RbtInteractionGrid>();
m_spGuanGrid = CreateGrid<RbtInteractionGrid>();

RbtDouble idxIncr = GetParameter(_INCR); // vdw Radius increment for indexing
RbtDouble maxError = GetMaxError();
Expand Down
53 changes: 0 additions & 53 deletions src/lib/RbtBaseIdxSF.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,59 +39,6 @@ RbtDouble RbtBaseIdxSF::GetBorder() const { return m_border; }

void RbtBaseIdxSF::SetBorder(RbtDouble border) { SetParameter(_BORDER, border); }

// DM 10 Apr 2002
// I know, I know, grids should be templated to avoid the need for two different CreateGrid methods...
RbtInteractionGridPtr RbtBaseIdxSF::CreateInteractionGrid() const {
// Create a grid covering the docking site
RbtDockingSitePtr spDS = GetWorkSpace()->GetDockingSite();
if (spDS.Null()) return RbtInteractionGridPtr();

// Extend grid by _BORDER, mainly to allow for the possibility of polar hydrogens
// falling outside of the docking site
RbtCoord minCoord = spDS->GetMinCoord() - m_border;
RbtCoord maxCoord = spDS->GetMaxCoord() + m_border;
RbtVector recepExtent = maxCoord - minCoord;
RbtVector gridStep(m_gridStep, m_gridStep, m_gridStep);
RbtUInt nX = int(recepExtent.x / gridStep.x) + 1;
RbtUInt nY = int(recepExtent.y / gridStep.y) + 1;
RbtUInt nZ = int(recepExtent.z / gridStep.z) + 1;
return RbtInteractionGridPtr(new RbtInteractionGrid(minCoord, gridStep, nX, nY, nZ));
}

RbtNonBondedGridPtr RbtBaseIdxSF::CreateNonBondedGrid() const {
// Create a grid covering the docking site
RbtDockingSitePtr spDS = GetWorkSpace()->GetDockingSite();
if (spDS.Null()) return RbtInteractionGridPtr();

// Extend grid by _BORDER, mainly to allow for the possibility of polar hydrogens
// falling outside of the docking site
RbtCoord minCoord = spDS->GetMinCoord() - m_border;
RbtCoord maxCoord = spDS->GetMaxCoord() + m_border;
RbtVector recepExtent = maxCoord - minCoord;
RbtVector gridStep(m_gridStep, m_gridStep, m_gridStep);
RbtUInt nX = int(recepExtent.x / gridStep.x) + 1;
RbtUInt nY = int(recepExtent.y / gridStep.y) + 1;
RbtUInt nZ = int(recepExtent.z / gridStep.z) + 1;
return RbtNonBondedGridPtr(new RbtNonBondedGrid(minCoord, gridStep, nX, nY, nZ));
}

RbtNonBondedHHSGridPtr RbtBaseIdxSF::CreateNonBondedHHSGrid() const {
// Create a grid covering the docking site
RbtDockingSitePtr spDS = GetWorkSpace()->GetDockingSite();
if (spDS.Null()) return RbtNonBondedHHSGridPtr();

// Extend grid by _BORDER, mainly to allow for the possibility of polar hydrogens
// falling outside of the docking site
RbtCoord minCoord = spDS->GetMinCoord() - m_border;
RbtCoord maxCoord = spDS->GetMaxCoord() + m_border;
RbtVector recepExtent = maxCoord - minCoord;
RbtVector gridStep(m_gridStep, m_gridStep, m_gridStep);
RbtUInt nX = int(recepExtent.x / gridStep.x) + 1;
RbtUInt nY = int(recepExtent.y / gridStep.y) + 1;
RbtUInt nZ = int(recepExtent.z / gridStep.z) + 1;
return RbtNonBondedHHSGridPtr(new RbtNonBondedHHSGrid(minCoord, gridStep, nX, nY, nZ));
}

RbtDouble RbtBaseIdxSF::GetMaxError() const {
// maxError is half a grid diagonal. This is the tolerance we have to allow when indexing the receptor atoms on the
// grid When retrieving the nearest neighbours to a ligand atom, we do the lookup on the nearest grid point to the
Expand Down
2 changes: 1 addition & 1 deletion src/lib/RbtNmrSF.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void RbtNmrSF::SetupReceptor() {
RbtInt iTrace = GetTrace();

// Create indexed grid for STD restraints penalty function
m_spGrid = CreateNonBondedGrid();
m_spGrid = CreateGrid<RbtNonBondedGrid>();
// Fixed distance range used for indexing the relevant receptor atoms
RbtDouble range = GetRange() + GetMaxError();
RbtDockingSitePtr spDS = GetWorkSpace()->GetDockingSite();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/RbtPMFIdxSF.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void RbtPMFIdxSF::SetupReceptor() {
cout << _CT << "WARNING: no receptor defined. " << endl;
return;
} else { // load PMFs from table files
theSurround = CreateNonBondedGrid();
theSurround = CreateGrid<RbtNonBondedGrid>();
RbtDockingSitePtr spDS = GetWorkSpace()->GetDockingSite();
RbtDouble range = GetRange() + GetMaxError();
RbtAtomList atomList = spDS->GetAtomList(GetReceptor()->GetAtomList(), 0.0, GetCorrectedRange());
Expand Down
8 changes: 4 additions & 4 deletions src/lib/RbtPolarIdxSF.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ void RbtPolarIdxSF::SetupReceptor() {
RbtInt nCoords = GetReceptor()->GetNumSavedCoords() - 1;
if (nCoords > 0) {
RbtAtomList atomList = GetReceptor()->GetAtomList();
m_spPosGrid = CreateInteractionGrid();
m_spPosGrid = CreateGrid<RbtInteractionGrid>();
m_recepPosList = CreateDonorInteractionCenters(atomList);
m_spNegGrid = CreateInteractionGrid();
m_spNegGrid = CreateGrid<RbtInteractionGrid>();
m_recepNegList = CreateAcceptorInteractionCenters(atomList);
for (RbtInt i = 1; i <= nCoords; i++) {
if (iTrace > 0) {
Expand All @@ -133,8 +133,8 @@ void RbtPolarIdxSF::SetupReceptor() {
}
} else {
RbtAtomList atomList = spDS->GetAtomList(GetReceptor()->GetAtomList(), 0.0, GetCorrectedRange());
m_spPosGrid = CreateInteractionGrid();
m_spNegGrid = CreateInteractionGrid();
m_spPosGrid = CreateGrid<RbtInteractionGrid>();
m_spNegGrid = CreateGrid<RbtInteractionGrid>();
m_recepPosList = CreateDonorInteractionCenters(atomList);
m_recepNegList = CreateAcceptorInteractionCenters(atomList);

Expand Down
2 changes: 0 additions & 2 deletions src/lib/RbtPsfFileSink.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ void RbtPsfFileSink::Render() {
bIter++;
ostr << setw(8) << (*bIter)->GetAtom1Ptr()->GetAtomId() << setw(8) << (*bIter)->GetAtom2Ptr()->GetAtomId();
bIter++;
ostr;
AddLine(ostr.str());
}
// Remaining bonds on final incomplete line
Expand All @@ -127,7 +126,6 @@ void RbtPsfFileSink::Render() {
ostr << setw(8) << (*bIter)->GetAtom1Ptr()->GetAtomId() << setw(8)
<< (*bIter)->GetAtom2Ptr()->GetAtomId();
}
ostr;
AddLine(ostr.str());
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/RbtSAIdxSF.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void RbtSAIdxSF::SetupReceptor() {
// and that they don't move very far (up to 2A)
m_bFlexRec = GetReceptor()->isFlexible();
RbtDouble flexDist = 2.0;
theIdxGrid = CreateNonBondedHHSGrid();
theIdxGrid = CreateGrid<RbtNonBondedHHSGrid>();
RbtDouble idxIncr = GetParameter(_INCR).Double() + GetMaxError();
RbtDouble flexIncr = idxIncr + flexDist;

Expand Down
4 changes: 2 additions & 2 deletions src/lib/RbtVdwIdxSF.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void RbtVdwIdxSF::SetupReceptor() {
m_bFlexRec = GetReceptor()->isFlexible();

m_recAtomList = GetReceptor()->GetAtomList();
m_spGrid = CreateNonBondedGrid();
m_spGrid = CreateGrid<RbtNonBondedGrid>();
RbtDouble maxError = GetMaxError();
RbtDouble flexDist = 2.0;
RbtDockingSitePtr spDS = GetWorkSpace()->GetDockingSite();
Expand Down Expand Up @@ -242,7 +242,7 @@ void RbtVdwIdxSF::SetupSolvent() {
// The interaction map can be partitioned in advance, based on the maximum displacement
// of any of the tethered atoms
if (!m_solventFixTethAtomList.empty()) {
m_spSolventGrid = CreateNonBondedGrid();
m_spSolventGrid = CreateGrid<RbtNonBondedGrid>();
RbtDouble maxError = GetMaxError();
RbtDouble maxFlexDist = 0.0;
for (RbtAtomRListConstIter iter = m_solventFixTethAtomList.begin(); iter != m_solventFixTethAtomList.end();
Expand Down

0 comments on commit cf10d12

Please sign in to comment.