Skip to content

Commit

Permalink
implemented suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnaBruenisholz committed May 8, 2024
1 parent a486b39 commit f56e8f0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 56 deletions.
71 changes: 22 additions & 49 deletions Code/ForceField/MMFF/Params.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ class RDKIT_FORCEFIELD_EXPORT MMFFDefCollection {
*/
const MMFFDef *operator()(const unsigned int atomType) const {
#ifdef RDKIT_MMFF_PARAMS_USE_STD_MAP
std::map<const unsigned int, MMFFDef>::const_iterator res =
d_params.find(atomType);
const auto res = d_params.find(atomType);
return ((res != d_params.end()) ? &((*res).second) : NULL);
#else
return ((atomType && (atomType <= d_params.size()))
Expand All @@ -199,16 +198,12 @@ class RDKIT_FORCEFIELD_EXPORT MMFFPropCollection {
*/
const MMFFProp *operator()(const unsigned int atomType) const {
#ifdef RDKIT_MMFF_PARAMS_USE_STD_MAP
const auto res =
d_params.find(atomType);
const auto res = d_params.find(atomType);

return ((res != d_params.end()) ? &((*res).second) : NULL);
#else
std::pair<std::vector<std::uint8_t>::const_iterator,
std::vector<std::uint8_t>::const_iterator>
bounds =
std::equal_range(d_iAtomType.begin(), d_iAtomType.end(), atomType);

auto bounds =
std::equal_range(d_iAtomType.begin(), d_iAtomType.end(), atomType);
return ((bounds.first != bounds.second)
? &d_params[bounds.first - d_iAtomType.begin()]
: nullptr);
Expand Down Expand Up @@ -270,9 +265,7 @@ class RDKIT_FORCEFIELD_EXPORT MMFFChgCollection {
sign = 1;
}
#ifdef RDKIT_MMFF_PARAMS_USE_STD_MAP
std::map<const unsigned int,
std::map<const unsigned int, MMFFChg>>::const_iterator res1 =
d_params[bondType].find(canIAtomType);
const auto res1 = d_params[bondType].find(canIAtomType);
std::map<const unsigned int, MMFFChg>::const_iterator res2;
if (res1 != d_params[bondType].end()) {
res2 = ((*res1).second).find(canJAtomType);
Expand All @@ -281,10 +274,8 @@ class RDKIT_FORCEFIELD_EXPORT MMFFChgCollection {
}
}
#else
std::pair<std::vector<std::uint8_t>::const_iterator,
std::vector<std::uint8_t>::const_iterator>
bounds = std::equal_range(d_iAtomType.begin(), d_iAtomType.end(),
canIAtomType);
auto bounds =
std::equal_range(d_iAtomType.begin(), d_iAtomType.end(), canIAtomType);
if (bounds.first != bounds.second) {
bounds = std::equal_range(
d_jAtomType.begin() + (bounds.first - d_iAtomType.begin()),
Expand Down Expand Up @@ -354,10 +345,8 @@ class RDKIT_FORCEFIELD_EXPORT MMFFBondCollection {
}
}
#else
std::pair<std::vector<std::uint8_t>::const_iterator,
std::vector<std::uint8_t>::const_iterator>
bounds = std::equal_range(d_iAtomType.begin(), d_iAtomType.end(),
canAtomType);
auto bounds =
std::equal_range(d_iAtomType.begin(), d_iAtomType.end(), canAtomType);
if (bounds.first != bounds.second) {
bounds = std::equal_range(
d_jAtomType.begin() + (bounds.first - d_iAtomType.begin()),
Expand Down Expand Up @@ -418,10 +407,8 @@ class RDKIT_FORCEFIELD_EXPORT MMFFBndkCollection {
}
}
#else
std::pair<std::vector<std::uint8_t>::const_iterator,
std::vector<std::uint8_t>::const_iterator>
bounds = std::equal_range(d_iAtomicNum.begin(), d_iAtomicNum.end(),
canAtomicNum);
auto bounds = std::equal_range(d_iAtomicNum.begin(), d_iAtomicNum.end(),
canAtomicNum);
if (bounds.first != bounds.second) {
bounds = std::equal_range(
d_jAtomicNum.begin() + (bounds.first - d_iAtomicNum.begin()),
Expand Down Expand Up @@ -473,9 +460,7 @@ class RDKIT_FORCEFIELD_EXPORT MMFFHerschbachLaurieCollection {
}
}
#else
std::pair<std::vector<std::uint8_t>::const_iterator,
std::vector<std::uint8_t>::const_iterator>
bounds = std::equal_range(d_iRow.begin(), d_iRow.end(), canIRow);
auto bounds = std::equal_range(d_iRow.begin(), d_iRow.end(), canIRow);
if (bounds.first != bounds.second) {
bounds = std::equal_range(
d_jRow.begin() + (bounds.first - d_iRow.begin()),
Expand Down Expand Up @@ -515,11 +500,8 @@ class RDKIT_FORCEFIELD_EXPORT MMFFCovRadPauEleCollection {

return ((res != d_params.end()) ? &((*res).second) : NULL);
#else
std::pair<std::vector<std::uint8_t>::const_iterator,
std::vector<std::uint8_t>::const_iterator>
bounds =
std::equal_range(d_atomicNum.begin(), d_atomicNum.end(), atomicNum);

auto bounds =
std::equal_range(d_atomicNum.begin(), d_atomicNum.end(), atomicNum);
return ((bounds.first != bounds.second)
? &d_params[bounds.first - d_atomicNum.begin()]
: nullptr);
Expand Down Expand Up @@ -591,10 +573,8 @@ class RDKIT_FORCEFIELD_EXPORT MMFFAngleCollection {
++iter;
}
#else
std::pair<std::vector<std::uint8_t>::const_iterator,
std::vector<std::uint8_t>::const_iterator>
jBounds =
std::equal_range(d_jAtomType.begin(), d_jAtomType.end(), jAtomType);
auto jBounds =
std::equal_range(d_jAtomType.begin(), d_jAtomType.end(), jAtomType);
std::pair<std::vector<std::uint8_t>::const_iterator,
std::vector<std::uint8_t>::const_iterator>
bounds;
Expand Down Expand Up @@ -699,10 +679,8 @@ class RDKIT_FORCEFIELD_EXPORT MMFFStbnCollection {
}
}
#else
std::pair<std::vector<std::uint8_t>::const_iterator,
std::vector<std::uint8_t>::const_iterator>
jBounds =
std::equal_range(d_jAtomType.begin(), d_jAtomType.end(), jAtomType);
auto jBounds =
std::equal_range(d_jAtomType.begin(), d_jAtomType.end(), jAtomType);
std::pair<std::vector<std::uint8_t>::const_iterator,
std::vector<std::uint8_t>::const_iterator>
bounds;
Expand Down Expand Up @@ -849,10 +827,8 @@ class RDKIT_FORCEFIELD_EXPORT MMFFOopCollection {
++iter;
}
#else
std::pair<std::vector<std::uint8_t>::const_iterator,
std::vector<std::uint8_t>::const_iterator>
jBounds =
std::equal_range(d_jAtomType.begin(), d_jAtomType.end(), jAtomType);
auto jBounds =
std::equal_range(d_jAtomType.begin(), d_jAtomType.end(), jAtomType);
std::pair<std::vector<std::uint8_t>::const_iterator,
std::vector<std::uint8_t>::const_iterator>
bounds;
Expand Down Expand Up @@ -1093,11 +1069,8 @@ class RDKIT_FORCEFIELD_EXPORT MMFFVdWCollection {
d_params.find(atomType);
return (res != d_params.end() ? &((*res).second) : NULL);
#else
std::pair<std::vector<std::uint8_t>::const_iterator,
std::vector<std::uint8_t>::const_iterator>
bounds =
std::equal_range(d_atomType.begin(), d_atomType.end(), atomType);

auto bounds =
std::equal_range(d_atomType.begin(), d_atomType.end(), atomType);
return ((bounds.first != bounds.second)
? &d_params[bounds.first - d_atomType.begin()]
: nullptr);
Expand Down
3 changes: 2 additions & 1 deletion Code/ForceField/MMFF/StretchBend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ void StretchBendContrib::getGrad(double *pos, double *grad) const {
double cosTheta = p12.dotProduct(p32);
clipToOne(cosTheta);
double sinThetaSq = 1.0 - cosTheta * cosTheta;
double sinTheta = std::max(sqrt(sinThetaSq), 1.0e-8);
double sinTheta =
std::max(((sinThetaSq > 0.0) ? sqrt(sinThetaSq) : 0.0), 1.0e-8);
double angleTerm = RAD2DEG * acos(cosTheta) - d_theta0;
double distTerm = RAD2DEG * (d_forceConstants.first * (dist1 - d_restLen1) +
d_forceConstants.second * (dist2 - d_restLen2));
Expand Down
4 changes: 2 additions & 2 deletions Code/ForceField/UFF/AngleBend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ void AngleBendContrib::getGrad(double *pos, double *grad) const {
double cosTheta = r[0].dotProduct(r[1]);
clipToOne(cosTheta);
double sinThetaSq = 1.0 - cosTheta * cosTheta;
double sinTheta = std::max(sqrt(sinThetaSq), 1.0e-8);

double sinTheta =
std::max(((sinThetaSq > 0.0) ? sqrt(sinThetaSq) : 0.0), 1.0e-8);
// std::cerr << "GRAD: " << cosTheta << " (" << acos(cosTheta)<< "), ";
// std::cerr << sinTheta << " (" << asin(sinTheta)<< ")" << std::endl;

Expand Down
5 changes: 3 additions & 2 deletions Code/ForceField/UFF/Inversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ void InversionContrib::getGrad(double *pos, double *grad) const {
double cosY = n.dotProduct(rJL);
clipToOne(cosY);
double sinYSq = 1.0 - cosY * cosY;
double sinY = std::max(sqrt(sinYSq), 1.0e-8);
double sinY = std::max(((sinYSq > 0.0) ? sqrt(sinYSq) : 0.0), 1.0e-8);
double cosTheta = rJI.dotProduct(rJK);
clipToOne(cosTheta);
double sinThetaSq = 1.0 - cosTheta * cosTheta;
double sinTheta = std::max(sqrt(sinThetaSq), 1.0e-8);
double sinTheta =
std::max(((sinThetaSq > 0.0) ? sqrt(sinThetaSq) : 0.0), 1.0e-8);
// sin(2 * W) = 2 * sin(W) * cos(W) = 2 * cos(Y) * sin(Y)
double dE_dW = -d_forceConstant * (d_C1 * cosY - 4.0 * d_C2 * cosY * sinY);
RDGeom::Point3D t1 = rJL.crossProduct(rJK);
Expand Down
2 changes: 0 additions & 2 deletions Code/ForceField/Wrap/ForceField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ python::tuple PyForceField::minimizeTrajectory(unsigned int snapshotFreq,
int resInt = this->field->minimize(snapshotFreq, &snapshotVect, maxIts,
forceTol, energyTol);
python::list l;
// for (RDKit::SnapshotVect::const_iterator it = snapshotVect.begin();
// it != snapshotVect.end(); ++it) {
for (auto it : snapshotVect) {
l.append(new RDKit::Snapshot(it));
}
Expand Down

0 comments on commit f56e8f0

Please sign in to comment.