diff --git a/.clang-tidy b/.clang-tidy index 747b59c06..596609f25 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,5 @@ --- -Checks: '-*,boost-use-to-string,modernize-use-auto,modernize-use-nullptr,modernize-loop-convert,modernize-use-override,modernize-pass-by-value,modernize-shrink-to-fit,readability-braces-around-statements' +Checks: '-*,boost-use-to-string,modernize-use-auto,modernize-use-nullptr,modernize-loop-convert,modernize-use-override,modernize-pass-by-value,modernize-shrink-to-fit,readability-braces-around-statements,readability-simplify-boolean-expr' HeaderFilterRegex: 'Code/' AnalyzeTemporaryDtors: false User: glandrum diff --git a/Code/DataStructs/SparseBitVect.cpp b/Code/DataStructs/SparseBitVect.cpp index c96915bcc..8afadfa5a 100644 --- a/Code/DataStructs/SparseBitVect.cpp +++ b/Code/DataStructs/SparseBitVect.cpp @@ -62,11 +62,7 @@ bool SparseBitVect::operator[](const unsigned int which) const { if (which >= d_size) { throw IndexErrorException(which); } - if (dp_bits->count(which)) { - return true; - } else { - return false; - } + return dp_bits->count(which) > 0u; } // """ ------------------------------------------------------- @@ -157,11 +153,7 @@ bool SparseBitVect::getBit(const unsigned int which) const { if (which >= d_size) { throw IndexErrorException(which); } - if (dp_bits->count(which)) { - return true; - } else { - return false; - } + return dp_bits->count(which) > 0u; } // """ ------------------------------------------------------- @@ -174,11 +166,7 @@ bool SparseBitVect::getBit(const IntVectIter which) const { if (*which < 0 || static_cast(*which) >= d_size) { throw IndexErrorException(*which); } - if (dp_bits->count(*which)) { - return true; - } else { - return false; - } + return dp_bits->count(*which) > 0u; } // """ ------------------------------------------------------- @@ -191,11 +179,7 @@ bool SparseBitVect::getBit(const IntSetIter which) const { if (*which < 0 || static_cast(*which) >= d_size) { throw IndexErrorException(*which); } - if (dp_bits->count(*which)) { - return true; - } else { - return false; - } + return dp_bits->count(*which) > 0u; } // """ ------------------------------------------------------- diff --git a/Code/ForceField/MMFF/AngleBend.cpp b/Code/ForceField/MMFF/AngleBend.cpp index 7130633e4..730d5a655 100644 --- a/Code/ForceField/MMFF/AngleBend.cpp +++ b/Code/ForceField/MMFF/AngleBend.cpp @@ -100,7 +100,7 @@ AngleBendContrib::AngleBendContrib(ForceField *owner, unsigned int idx1, d_at1Idx = idx1; d_at2Idx = idx2; d_at3Idx = idx3; - d_isLinear = (mmffPropParamsCentralAtom->linh ? true : false); + d_isLinear = mmffPropParamsCentralAtom->linh > 0u; d_theta0 = mmffAngleParams->theta0; d_ka = mmffAngleParams->ka; diff --git a/Code/ForceField/MMFF/Params.h b/Code/ForceField/MMFF/Params.h index 45e0308ec..0d5fa0cc8 100644 --- a/Code/ForceField/MMFF/Params.h +++ b/Code/ForceField/MMFF/Params.h @@ -162,10 +162,8 @@ class RDKIT_FORCEFIELD_EXPORT MMFFAromCollection { \return a pointer to the MMFFArom object, NULL on failure. */ bool isMMFFAromatic(const unsigned int atomType) const { - return ((std::find(d_params.begin(), d_params.end(), atomType) != - d_params.end()) - ? true - : false); + return std::find(d_params.begin(), d_params.end(), atomType) != + d_params.end(); } MMFFAromCollection(const std::vector *mmffArom = nullptr); diff --git a/Code/ForceField/MMFF/testMMFFForceField.cpp b/Code/ForceField/MMFF/testMMFFForceField.cpp index cd0f0053a..c5c28d9f1 100644 --- a/Code/ForceField/MMFF/testMMFFForceField.cpp +++ b/Code/ForceField/MMFF/testMMFFForceField.cpp @@ -39,8 +39,7 @@ using namespace RDKit; bool fexist(std::string filename) { std::ifstream ifStream(filename.c_str()); - - return (ifStream ? true : false); + return !ifStream.fail(); } bool fgrep(std::fstream &fStream, std::string key, std::string &line) { diff --git a/Code/Geometry/UniformGrid3D.cpp b/Code/Geometry/UniformGrid3D.cpp index 7bb5b0378..725931146 100644 --- a/Code/Geometry/UniformGrid3D.cpp +++ b/Code/Geometry/UniformGrid3D.cpp @@ -185,10 +185,7 @@ bool UniformGrid3D::compareParams(const UniformGrid3D &other) const { } Point3D dOffset = d_offSet; dOffset -= other.getOffset(); - if (dOffset.lengthSq() > OFFSET_TOL) { - return false; - } - return true; + return dOffset.lengthSq() <= OFFSET_TOL; } void UniformGrid3D::setSphereOccupancy(const Point3D ¢er, double radius, diff --git a/Code/GraphMol/Atom.cpp b/Code/GraphMol/Atom.cpp index 7b360256e..33783ae33 100644 --- a/Code/GraphMol/Atom.cpp +++ b/Code/GraphMol/Atom.cpp @@ -670,11 +670,8 @@ void Atom::updatePropertyCache(bool strict) { } bool Atom::needsUpdatePropertyCache() const { - if (this->d_explicitValence >= 0 && - (this->df_noImplicit || this->d_implicitValence >= 0)) { - return false; - } - return true; + return !(this->d_explicitValence >= 0 && + (this->df_noImplicit || this->d_implicitValence >= 0)); } // returns the number of swaps required to convert the ordering diff --git a/Code/GraphMol/CIPLabeler/catch_tests.cpp b/Code/GraphMol/CIPLabeler/catch_tests.cpp index b4aaff4d8..5eab4db1a 100644 --- a/Code/GraphMol/CIPLabeler/catch_tests.cpp +++ b/Code/GraphMol/CIPLabeler/catch_tests.cpp @@ -331,8 +331,7 @@ TEST_CASE("Tetrahedral assignment", "[accurateCIP]") { CIPLabeler::assignCIPLabels(*mol); std::string chirality; - CHECK(chiral_atom->getPropIfPresent(common_properties::_CIPCode, chirality) == - true); + CHECK(chiral_atom->getPropIfPresent(common_properties::_CIPCode, chirality)); CHECK(chirality == "S"); } @@ -350,12 +349,10 @@ TEST_CASE("Double bond stereo assignment", "[accurateCIP]") { CIPLabeler::assignCIPLabels(*mol); std::string chirality; - CHECK(bond_1->getPropIfPresent(common_properties::_CIPCode, chirality) == - true); + CHECK(bond_1->getPropIfPresent(common_properties::_CIPCode, chirality)); CHECK(chirality == "E"); - CHECK(bond_2->getPropIfPresent(common_properties::_CIPCode, chirality) == - true); + CHECK(bond_2->getPropIfPresent(common_properties::_CIPCode, chirality)); CHECK(chirality == "Z"); } @@ -373,7 +370,7 @@ TEST_CASE("phosphine and arsine chirality", "[accurateCIP]") { std::string chirality; CHECK(mol->getAtomWithIdx(1)->getPropIfPresent(common_properties::_CIPCode, - chirality) == true); + chirality)); CHECK(chirality == ref.second); } } @@ -386,8 +383,8 @@ TEST_CASE("assign specific atoms and bonds", "[accurateCIP]") { auto atom1 = mol->getAtomWithIdx(1); auto atom5 = mol->getAtomWithIdx(5); - REQUIRE(atom1->hasProp(common_properties::_CIPCode) == true); - REQUIRE(atom5->hasProp(common_properties::_CIPCode) == true); + REQUIRE(atom1->hasProp(common_properties::_CIPCode)); + REQUIRE(atom5->hasProp(common_properties::_CIPCode)); atom1->clearProp(common_properties::_CIPCode); atom5->clearProp(common_properties::_CIPCode); @@ -398,10 +395,9 @@ TEST_CASE("assign specific atoms and bonds", "[accurateCIP]") { CIPLabeler::assignCIPLabels(*mol, atoms, bonds); std::string chirality; - CHECK(atom1->getPropIfPresent(common_properties::_CIPCode, chirality) == - true); + CHECK(atom1->getPropIfPresent(common_properties::_CIPCode, chirality)); CHECK(chirality == "S"); - CHECK(atom5->hasProp(common_properties::_CIPCode) == false); + CHECK(!atom5->hasProp(common_properties::_CIPCode)); } SECTION("Assign bonds") { auto mol = R"(C\C=C\C=C/C)"_smiles; @@ -413,8 +409,8 @@ TEST_CASE("assign specific atoms and bonds", "[accurateCIP]") { REQUIRE(bond1->getBondType() == Bond::DOUBLE); REQUIRE(bond3->getBondType() == Bond::DOUBLE); - REQUIRE(bond1->hasProp(common_properties::_CIPCode) == false); - REQUIRE(bond3->hasProp(common_properties::_CIPCode) == false); + REQUIRE(!bond1->hasProp(common_properties::_CIPCode)); + REQUIRE(!bond3->hasProp(common_properties::_CIPCode)); boost::dynamic_bitset<> atoms; boost::dynamic_bitset<> bonds(mol->getNumBonds()); @@ -422,8 +418,8 @@ TEST_CASE("assign specific atoms and bonds", "[accurateCIP]") { CIPLabeler::assignCIPLabels(*mol, atoms, bonds); std::string stereo; - CHECK(bond1->hasProp(common_properties::_CIPCode) == false); - CHECK(bond3->getPropIfPresent(common_properties::_CIPCode, stereo) == true); + CHECK(!bond1->hasProp(common_properties::_CIPCode)); + CHECK(bond3->getPropIfPresent(common_properties::_CIPCode, stereo)); CHECK(stereo == "Z"); } } @@ -437,13 +433,13 @@ TEST_CASE("para-stereochemistry", "[accurateCIP]") { std::string chirality; CHECK(mol->getAtomWithIdx(3)->getPropIfPresent(common_properties::_CIPCode, - chirality) == true); + chirality)); CHECK(chirality == "R"); CHECK(mol->getAtomWithIdx(7)->getPropIfPresent(common_properties::_CIPCode, - chirality) == true); + chirality)); CHECK(chirality == "r"); CHECK(mol->getAtomWithIdx(9)->getPropIfPresent(common_properties::_CIPCode, - chirality) == true); + chirality)); CHECK(chirality == "S"); } SECTION("example 2") { @@ -454,13 +450,13 @@ TEST_CASE("para-stereochemistry", "[accurateCIP]") { std::string chirality; CHECK(mol->getAtomWithIdx(3)->getPropIfPresent(common_properties::_CIPCode, - chirality) == true); + chirality)); CHECK(chirality == "R"); CHECK(mol->getAtomWithIdx(7)->getPropIfPresent(common_properties::_CIPCode, - chirality) == true); + chirality)); CHECK(chirality == "r"); CHECK(mol->getAtomWithIdx(9)->getPropIfPresent(common_properties::_CIPCode, - chirality) == true); + chirality)); CHECK(chirality == "S"); } } diff --git a/Code/GraphMol/Canon.cpp b/Code/GraphMol/Canon.cpp index ebd50d687..8d1dc4e2f 100644 --- a/Code/GraphMol/Canon.cpp +++ b/Code/GraphMol/Canon.cpp @@ -40,11 +40,8 @@ bool hasSingleHQuery(const Atom::QUERYATOM_QUERY *q) { for (auto cIt = q->beginChildren(); cIt != q->endChildren(); ++cIt) { auto cDescr = (*cIt)->getDescription(); if (cDescr == "AtomHCount") { - if (!(*cIt)->getNegation() && - ((ATOM_EQUALS_QUERY *)(*cIt).get())->getVal() == 1) { - return true; - } - return false; + return !(*cIt)->getNegation() && + ((ATOM_EQUALS_QUERY *)(*cIt).get())->getVal() == 1; } else if (cDescr == "AtomAnd") { res = hasSingleHQuery((*cIt).get()); if (res) { diff --git a/Code/GraphMol/ChemReactions/Enumerate/CartesianProduct.h b/Code/GraphMol/ChemReactions/Enumerate/CartesianProduct.h index bbe18eed7..2a0a22b33 100644 --- a/Code/GraphMol/ChemReactions/Enumerate/CartesianProduct.h +++ b/Code/GraphMol/ChemReactions/Enumerate/CartesianProduct.h @@ -112,12 +112,8 @@ class RDKIT_CHEMREACTIONS_EXPORT CartesianProductStrategy bool hasNext() const { // Fix me -> use multiprecision int here??? - if (m_numPermutations == EnumerationStrategyBase::EnumerationOverflow || - m_numPermutationsProcessed < rdcast(m_numPermutations)) { - return true; - } else { - return false; - } + return m_numPermutations == EnumerationStrategyBase::EnumerationOverflow || + m_numPermutationsProcessed < rdcast(m_numPermutations); } void next(size_t rowToIncrement) { diff --git a/Code/GraphMol/ChemReactions/ReactionUtils.cpp b/Code/GraphMol/ChemReactions/ReactionUtils.cpp index 1faa86e46..dd4425c5a 100644 --- a/Code/GraphMol/ChemReactions/ReactionUtils.cpp +++ b/Code/GraphMol/ChemReactions/ReactionUtils.cpp @@ -161,12 +161,9 @@ bool isReactionTemplateMoleculeAgent(const ROMol &mol, double agentThreshold) { unsigned numMappedAtoms = MolOps::getNumAtomsWithDistinctProperty( mol, common_properties::molAtomMapNumber); unsigned numAtoms = mol.getNumHeavyAtoms(); - if (numAtoms > 0 && - static_cast(numMappedAtoms) / static_cast(numAtoms) >= - agentThreshold) { - return false; - } - return true; + return !(numAtoms > 0u && static_cast(numMappedAtoms) / + static_cast(numAtoms) >= + agentThreshold); } namespace { diff --git a/Code/GraphMol/Chirality.cpp b/Code/GraphMol/Chirality.cpp index dee1d2ed5..8376aeb85 100644 --- a/Code/GraphMol/Chirality.cpp +++ b/Code/GraphMol/Chirality.cpp @@ -605,11 +605,7 @@ void updateDoubleBondNeighbors(ROMol &mol, Bond *dblBond, const Conformer *conf, } double ang = RDGeom::computeDihedralAngle(bond1P, beginP, endP, bond2P); - if (ang < M_PI / 2) { - sameTorsionDir = false; - } else { - sameTorsionDir = true; - } + sameTorsionDir = ang >= M_PI / 2; // std::cerr << " angle: " << ang << " sameTorsionDir: " << sameTorsionDir // << "\n"; } else { @@ -742,15 +738,12 @@ void updateDoubleBondNeighbors(ROMol &mol, Bond *dblBond, const Conformer *conf, bool isBondCandidateForStereo(const Bond *bond) { PRECONDITION(bond, "no bond"); - if (bond->getBondType() == Bond::DOUBLE && - bond->getStereo() != Bond::STEREOANY && - bond->getBondDir() != Bond::EITHERDOUBLE && - bond->getBeginAtom()->getDegree() > 1 && - bond->getEndAtom()->getDegree() > 1 && - shouldDetectDoubleBondStereo(bond)) { - return true; - } - return false; + return bond->getBondType() == Bond::DOUBLE && + bond->getStereo() != Bond::STEREOANY && + bond->getBondDir() != Bond::EITHERDOUBLE && + bond->getBeginAtom()->getDegree() > 1u && + bond->getEndAtom()->getDegree() > 1u && + shouldDetectDoubleBondStereo(bond); } const Atom *findHighestCIPNeighbor(const Atom *atom, const Atom *skipAtom) { @@ -1235,11 +1228,7 @@ bool atomIsCandidateForRingStereochem(const ROMol &mol, const Atom *atom) { rank1) && nonRingNbrs[1]->getPropIfPresent(common_properties::_CIPRank, rank2)) { - if (rank1 == rank2) { - res = false; - } else { - res = true; - } + res = rank1 != rank2; } break; case 1: diff --git a/Code/GraphMol/ConjugHybrid.cpp b/Code/GraphMol/ConjugHybrid.cpp index 80caddd0f..9c5c05c48 100644 --- a/Code/GraphMol/ConjugHybrid.cpp +++ b/Code/GraphMol/ConjugHybrid.cpp @@ -28,12 +28,9 @@ bool isAtomConjugCand(const Atom *at) { // the first row of the periodic table. (Conjugation in aromatic rings // has already been attended to, so this is safe.) int nouter = PeriodicTable::getTable()->getNouterElecs(at->getAtomicNum()); - if (((at->getAtomicNum() <= 10) || (nouter != 5 && nouter != 6) || - (nouter == 6 && at->getTotalDegree() < 2)) && - (MolOps::countAtomElec(at) > 0)) { - return true; - } - return false; + return ((at->getAtomicNum() <= 10) || (nouter != 5 && nouter != 6) || + (nouter == 6 && at->getTotalDegree() < 2u)) && + (MolOps::countAtomElec(at) > 0); } void markConjAtomBonds(Atom *at) { diff --git a/Code/GraphMol/DistGeomHelpers/BoundsMatrixBuilder.cpp b/Code/GraphMol/DistGeomHelpers/BoundsMatrixBuilder.cpp index cab96d6b6..013c85157 100644 --- a/Code/GraphMol/DistGeomHelpers/BoundsMatrixBuilder.cpp +++ b/Code/GraphMol/DistGeomHelpers/BoundsMatrixBuilder.cpp @@ -1227,12 +1227,9 @@ bool _checkMacrocycleTwoInSameRingAmideEster14( unsigned int a3Num = atm3->getAtomicNum(); unsigned int a4Num = atm4->getAtomicNum(); - if (a1Num != 1 && a3Num == 6 && bnd3->getBondType() == Bond::DOUBLE && - (a4Num == 8 || a4Num == 7) && bnd1->getBondType() == Bond::SINGLE && - (a2Num == 8 || (a2Num == 7))) { - return true; - } - return false; + return a1Num != 1 && a3Num == 6 && bnd3->getBondType() == Bond::DOUBLE && + (a4Num == 8 || a4Num == 7) && bnd1->getBondType() == Bond::SINGLE && + (a2Num == 8 || a2Num == 7); } void _setMacrocycleTwoInSameRing14Bounds(const ROMol &mol, const Bond *bnd1, diff --git a/Code/GraphMol/DistGeomHelpers/Embedder.cpp b/Code/GraphMol/DistGeomHelpers/Embedder.cpp index 0651028f7..9de576bd8 100644 --- a/Code/GraphMol/DistGeomHelpers/Embedder.cpp +++ b/Code/GraphMol/DistGeomHelpers/Embedder.cpp @@ -303,11 +303,7 @@ bool _volumeTest(const DistGeom::ChiralSetPtr &chiralSet, if (verbose) { std::cerr << " " << fabs(vol) << std::endl; } - if (fabs(vol) < MIN_TETRAHEDRAL_CHIRAL_VOL) { - return false; - } - - return true; + return fabs(vol) >= MIN_TETRAHEDRAL_CHIRAL_VOL; } bool _sameSide(const RDGeom::Point3D &v1, const RDGeom::Point3D &v2, @@ -713,7 +709,7 @@ bool embedPoints(RDGeom::PointPtrVect *positions, detail::EmbedArgs eargs, bool gotCoords = false; unsigned int iter = 0; - while ((gotCoords == false) && (iter < embedParams.maxIterations)) { + while (!gotCoords && iter < embedParams.maxIterations) { ++iter; if (embedParams.callback != nullptr) { embedParams.callback(iter); @@ -964,10 +960,7 @@ bool multiplication_overflows_(T a, T b) { if (a == 0 || b == 0) { return false; } - if (a > std::numeric_limits::max() / b) { - return true; - } - return false; + return a > std::numeric_limits::max() / b; } void embedHelper_(int threadId, int numThreads, EmbedArgs *eargs, diff --git a/Code/GraphMol/FMCS/MaximumCommonSubgraph.cpp b/Code/GraphMol/FMCS/MaximumCommonSubgraph.cpp index 3aef42165..e1ee1f941 100644 --- a/Code/GraphMol/FMCS/MaximumCommonSubgraph.cpp +++ b/Code/GraphMol/FMCS/MaximumCommonSubgraph.cpp @@ -1001,7 +1001,7 @@ MCSResult MaximumCommonSubgraph::find(const std::vector& src_mols) { } areSeedsEmpty = Seeds.empty(); - res.Canceled = areSeedsEmpty || growSeeds() ? false : true; + res.Canceled = !(areSeedsEmpty || growSeeds()); // verify what MCS is equal to one of initial seed for chirality match if ((FinalMatchCheckFunction == Parameters.FinalMatchChecker && 1 == getMaxNumberBonds()) || diff --git a/Code/GraphMol/FMCS/testFMCS_Unit.cpp b/Code/GraphMol/FMCS/testFMCS_Unit.cpp index 08b9c409d..e8710459c 100644 --- a/Code/GraphMol/FMCS/testFMCS_Unit.cpp +++ b/Code/GraphMol/FMCS/testFMCS_Unit.cpp @@ -1023,15 +1023,15 @@ void testJSONParameters() { pj = MCSParameters(); // parsing of empty string keeps default values parseMCSParametersJSON("", &pj); - TEST_ASSERT(pj.MaximizeBonds == true && pj.Threshold == 1.0 && + TEST_ASSERT(pj.MaximizeBonds && pj.Threshold == 1.0 && pj.Timeout == (unsigned int)-1 && - pj.AtomCompareParameters.MatchValences == false && - pj.AtomCompareParameters.MatchChiralTag == false && - pj.BondCompareParameters.MatchStereo == false && - pj.BondCompareParameters.RingMatchesRingOnly == false && - pj.BondCompareParameters.CompleteRingsOnly == false && - pj.BondCompareParameters.MatchFusedRings == false && - pj.BondCompareParameters.MatchFusedRingsStrict == false); + !pj.AtomCompareParameters.MatchValences && + !pj.AtomCompareParameters.MatchChiralTag && + !pj.BondCompareParameters.MatchStereo && + !pj.BondCompareParameters.RingMatchesRingOnly && + !pj.BondCompareParameters.CompleteRingsOnly && + !pj.BondCompareParameters.MatchFusedRings && + !pj.BondCompareParameters.MatchFusedRingsStrict); { pj = MCSParameters(); @@ -1045,17 +1045,16 @@ void testJSONParameters() { ", \"InitialSeed\": \"CNC\"" "}"; parseMCSParametersJSON(json, &pj); - TEST_ASSERT(pj.MaximizeBonds == false && pj.Threshold == 0.7 && - pj.Timeout == 3 && - pj.AtomCompareParameters.MatchValences == true && - pj.AtomCompareParameters.MatchChiralTag == true && - pj.AtomCompareParameters.RingMatchesRingOnly == true && - pj.AtomCompareParameters.CompleteRingsOnly == false && - pj.BondCompareParameters.MatchStereo == true && - pj.BondCompareParameters.RingMatchesRingOnly == true && - pj.BondCompareParameters.CompleteRingsOnly == true && - pj.BondCompareParameters.MatchFusedRings == true && - pj.BondCompareParameters.MatchFusedRingsStrict == true && + TEST_ASSERT(!pj.MaximizeBonds && pj.Threshold == 0.7 && pj.Timeout == 3 && + pj.AtomCompareParameters.MatchValences && + pj.AtomCompareParameters.MatchChiralTag && + pj.AtomCompareParameters.RingMatchesRingOnly && + !pj.AtomCompareParameters.CompleteRingsOnly && + pj.BondCompareParameters.MatchStereo && + pj.BondCompareParameters.RingMatchesRingOnly && + pj.BondCompareParameters.CompleteRingsOnly && + pj.BondCompareParameters.MatchFusedRings && + pj.BondCompareParameters.MatchFusedRingsStrict && 0 == strcmp(pj.InitialSeed.c_str(), "CNC")); } { @@ -1076,17 +1075,16 @@ void testJSONParameters() { ", \"InitialSeed\": \"CNC\"" "}"; parseMCSParametersJSON(json, &pj); - TEST_ASSERT(pj.MaximizeBonds == false && pj.Threshold == 0.7 && - pj.Timeout == 3 && - pj.AtomCompareParameters.MatchValences == true && - pj.AtomCompareParameters.MatchChiralTag == true && - pj.AtomCompareParameters.RingMatchesRingOnly == true && - pj.AtomCompareParameters.CompleteRingsOnly == true && - pj.BondCompareParameters.MatchStereo == true && - pj.BondCompareParameters.RingMatchesRingOnly == true && - pj.BondCompareParameters.CompleteRingsOnly == true && - pj.BondCompareParameters.MatchFusedRings == true && - pj.BondCompareParameters.MatchFusedRingsStrict == true && + TEST_ASSERT(!pj.MaximizeBonds && pj.Threshold == 0.7 && pj.Timeout == 3 && + pj.AtomCompareParameters.MatchValences && + pj.AtomCompareParameters.MatchChiralTag && + pj.AtomCompareParameters.RingMatchesRingOnly && + pj.AtomCompareParameters.CompleteRingsOnly && + pj.BondCompareParameters.MatchStereo && + pj.BondCompareParameters.RingMatchesRingOnly && + pj.BondCompareParameters.CompleteRingsOnly && + pj.BondCompareParameters.MatchFusedRings && + pj.BondCompareParameters.MatchFusedRingsStrict && 0 == strcmp(pj.InitialSeed.c_str(), "CNC")); } @@ -1201,7 +1199,7 @@ void testGithubIssue481() { std::vector> vect; bool sub_res = SubstructMatch(*mols[1].get(), *mols[0].get(), vect, true, true); - if (sub_res == false) { // actually == true & 4, 3 !!! + if (!sub_res) { // actually == true & 4, 3 !!! TEST_ASSERT(mcs_res.NumAtoms == 0); TEST_ASSERT(mcs_res.NumBonds == 0); } @@ -1232,7 +1230,7 @@ void testGithubIssue481() { std::vector> vect; bool sub_res = SubstructMatch(*mols[1].get(), *mols[0].get(), vect, true, true); - if (sub_res == false) { + if (!sub_res) { TEST_ASSERT(mcs_res.NumAtoms == 1); TEST_ASSERT(mcs_res.NumBonds == 0); TEST_ASSERT(mcs_res.SmartsString == "[#17]"); diff --git a/Code/GraphMol/FileParsers/MolFileParser.cpp b/Code/GraphMol/FileParsers/MolFileParser.cpp index 2d9d09035..5e45aa298 100644 --- a/Code/GraphMol/FileParsers/MolFileParser.cpp +++ b/Code/GraphMol/FileParsers/MolFileParser.cpp @@ -3386,12 +3386,8 @@ RWMol *MolDataStreamToMol(std::istream *inStream, unsigned int &line, tempStr = getLine(inStream); ++line; } - if (!inStream->eof() || tempStr.substr(0, 6) == "M END" || - tempStr.substr(0, 4) == "$$$$") { - fileComplete = true; - } else { - fileComplete = false; - } + fileComplete = !inStream->eof() || tempStr.substr(0, 6) == "M END" || + tempStr.substr(0, 4) == "$$$$"; } catch (FileParseException &e) { // catch our exceptions and throw them back after cleanup delete res; diff --git a/Code/GraphMol/FileParsers/MolFileWriter.cpp b/Code/GraphMol/FileParsers/MolFileWriter.cpp index 07e2c6fb6..58e57358a 100644 --- a/Code/GraphMol/FileParsers/MolFileWriter.cpp +++ b/Code/GraphMol/FileParsers/MolFileWriter.cpp @@ -538,13 +538,9 @@ bool hasNonDefaultValence(const Atom *atom) { SmilesWrite ::inOrganicSubset(atom->getAtomicNum())) { // for the ones we "know", we may have to specify the valence if it's // not the default value - if (atom->getNoImplicit() && - (atom->getExplicitValence() != - PeriodicTable::getTable()->getDefaultValence(atom->getAtomicNum()))) { - return true; - } else { - return false; - } + return atom->getNoImplicit() && + (atom->getExplicitValence() != + PeriodicTable::getTable()->getDefaultValence(atom->getAtomicNum())); } return true; } diff --git a/Code/GraphMol/FileParsers/ProximityBonds.cpp b/Code/GraphMol/FileParsers/ProximityBonds.cpp index 78a2c5867..c7f902259 100644 --- a/Code/GraphMol/FileParsers/ProximityBonds.cpp +++ b/Code/GraphMol/FileParsers/ProximityBonds.cpp @@ -65,12 +65,8 @@ static bool IsBlacklistedAtom(Atom *atom) { // blacklist metals, noble gasses and halogens int elem = atom->getAtomicNum(); // make an inverse query (non-metals and metaloids) - if ((5 <= elem && elem <= 8) || (14 <= elem && elem <= 16) || - (32 <= elem && elem <= 34) || (51 <= elem && elem <= 52)) { - return false; - } else { - return true; - } + return !((5 <= elem && elem <= 8) || (14 <= elem && elem <= 16) || + (32 <= elem && elem <= 34) || (51 <= elem && elem <= 52)); } bool IsBlacklistedPair(Atom *beg_atom, Atom *end_atom) { diff --git a/Code/GraphMol/FileParsers/testMolSupplier.cpp b/Code/GraphMol/FileParsers/testMolSupplier.cpp index bef0e6751..33910b265 100644 --- a/Code/GraphMol/FileParsers/testMolSupplier.cpp +++ b/Code/GraphMol/FileParsers/testMolSupplier.cpp @@ -1774,7 +1774,7 @@ void testSetStreamIndices() { if (addIndex) { pos = ifs.tellg(); } - notEof = (std::getline(ifs, line) ? true : false); + notEof = !std::getline(ifs, line).fail(); if (notEof) { if (addIndex) { indices.push_back(pos); diff --git a/Code/GraphMol/Fingerprints/PatternFingerprints.cpp b/Code/GraphMol/Fingerprints/PatternFingerprints.cpp index 08aeebedc..c32a7c6b8 100644 --- a/Code/GraphMol/Fingerprints/PatternFingerprints.cpp +++ b/Code/GraphMol/Fingerprints/PatternFingerprints.cpp @@ -169,10 +169,7 @@ bool isPatternComplexQuery(const Bond *b) { std::string descr = b->getQuery()->getDescription(); // std::cerr<<" !!!!!! "<getIdx()<<" // "<getBeginAtomIdx()<<"-"<getEndAtomIdx()<<" "<d_mmffs = ((mmffVariant == "MMFF94s") ? true : false); + this->d_mmffs = mmffVariant == "MMFF94s"; } const std::string getMMFFVariant() { return (this->d_mmffs ? "MMFF94s" : "MMFF94"); diff --git a/Code/GraphMol/ForceFieldHelpers/UFF/AtomTyper.cpp b/Code/GraphMol/ForceFieldHelpers/UFF/AtomTyper.cpp index 1ff304d5d..89c8f44fc 100644 --- a/Code/GraphMol/ForceFieldHelpers/UFF/AtomTyper.cpp +++ b/Code/GraphMol/ForceFieldHelpers/UFF/AtomTyper.cpp @@ -424,12 +424,12 @@ bool getUFFBondStretchParams(const ROMol &mol, unsigned int idx1, AtomicParamVect paramVect(2); unsigned int i; const Bond *bond = mol.getBondBetweenAtoms(idx1, idx2); - bool res = (bond ? true : false); + bool res = bond != nullptr; for (i = 0; res && (i < 2); ++i) { const Atom *atom = mol.getAtomWithIdx(idx[i]); std::string atomKey = Tools::getAtomLabel(atom); paramVect[i] = (*params)(atomKey); - res = (paramVect[i] ? true : false); + res = paramVect[i] != nullptr; } if (res) { double bondOrder = bond->getBondTypeAsDouble(); @@ -453,13 +453,13 @@ bool getUFFAngleBendParams(const ROMol &mol, unsigned int idx1, for (i = 0; res && (i < 3); ++i) { if (i < 2) { bond[i] = mol.getBondBetweenAtoms(idx[i], idx[i + 1]); - res = (bond[i] ? true : false); + res = bond[i] != nullptr; } if (res) { const Atom *atom = mol.getAtomWithIdx(idx[i]); std::string atomKey = Tools::getAtomLabel(atom); paramVect[i] = (*params)(atomKey); - res = (paramVect[i] ? true : false); + res = paramVect[i] != nullptr; } } if (res) { @@ -487,7 +487,7 @@ bool getUFFTorsionParams(const ROMol &mol, unsigned int idx1, unsigned int idx2, bool hasSP2 = false; for (i = 0; res && (i < 4); ++i) { if (i < 3) { - res = (mol.getBondBetweenAtoms(idx[i], idx[i + 1]) ? true : false); + res = mol.getBondBetweenAtoms(idx[i], idx[i + 1]) != nullptr; } const Atom *atom = mol.getAtomWithIdx(idx[i]); if ((i == 1) || (i == 2)) { @@ -496,7 +496,7 @@ bool getUFFTorsionParams(const ROMol &mol, unsigned int idx1, unsigned int idx2, hyb[j] = atom->getHybridization(); std::string atomKey = Tools::getAtomLabel(atom); paramVect[j] = (*params)(atomKey); - res = (paramVect[j] ? true : false); + res = paramVect[j] != nullptr; } else if (atom->getHybridization() == Atom::SP2) { hasSP2 = true; } @@ -606,7 +606,7 @@ bool getUFFVdWParams(const ROMol &mol, unsigned int idx1, unsigned int idx2, const Atom *atom = mol.getAtomWithIdx(idx[i]); std::string atomKey = Tools::getAtomLabel(atom); paramVect[i] = (*params)(atomKey); - res = (paramVect[i] ? true : false); + res = paramVect[i] != nullptr; } if (res) { uffVdWParams.x_ij = diff --git a/Code/GraphMol/MolDraw2D/DrawMol.cpp b/Code/GraphMol/MolDraw2D/DrawMol.cpp index 2abe8baa8..adbc2f0b2 100644 --- a/Code/GraphMol/MolDraw2D/DrawMol.cpp +++ b/Code/GraphMol/MolDraw2D/DrawMol.cpp @@ -622,7 +622,7 @@ void DrawMol::extractBrackets() { Point2D longline = brkShp.points_[1] - brkShp.points_[2]; longline.normalize(); static const double cos45 = 1.0 / sqrt(2.0); - bool horizontal = fabs(longline.x) > cos45 ? true : false; + bool horizontal = fabs(longline.x) > cos45; size_t labelBrk = postShapes_.size() - 1; for (int i = 1; i < numBrackets; ++i) { const auto &brkShp = *postShapes_[postShapes_.size() - i - 1]; diff --git a/Code/GraphMol/MolDraw2D/DrawShape.cpp b/Code/GraphMol/MolDraw2D/DrawShape.cpp index 6094d2fea..cf3c29df5 100644 --- a/Code/GraphMol/MolDraw2D/DrawShape.cpp +++ b/Code/GraphMol/MolDraw2D/DrawShape.cpp @@ -276,10 +276,7 @@ bool DrawShapePolyLine::doesRectClash(const StringRect &rect, return true; } } - if (doesLineIntersect(rect, points_.front(), points_.back(), padding)) { - return true; - } - return false; + return doesLineIntersect(rect, points_.front(), points_.back(), padding); } // **************************************************************************** @@ -448,11 +445,8 @@ bool DrawShapeDashedWedge::doesRectClash(const StringRect &rect, double padding) const { size_t last_point = points_.size() - 1; padding = scaleLineWidth_ ? padding * lineWidth_ : padding; - if (doesTriangleIntersect(rect, at1Cds_, points_[last_point], - points_[last_point-1], padding)) { - return true; - } - return false; + return doesTriangleIntersect(rect, at1Cds_, points_[last_point], + points_[last_point - 1], padding); } // **************************************************************************** diff --git a/Code/GraphMol/MolDraw2D/MolDraw2DDetails.cpp b/Code/GraphMol/MolDraw2D/MolDraw2DDetails.cpp index d988cbb50..5263f3fa9 100644 --- a/Code/GraphMol/MolDraw2D/MolDraw2DDetails.cpp +++ b/Code/GraphMol/MolDraw2D/MolDraw2DDetails.cpp @@ -289,10 +289,7 @@ bool doesLineIntersectEllipse(const Point2D ¢re, double xradius, } xdisc = (end2.x - centre.x) * (end2.x - centre.x) / xr2; ydisc = (end2.y - centre.y) * (end2.y - centre.y) / yr2; - if (xdisc + ydisc <= 1.0) { - return true; - } - return false; + return xdisc + ydisc <= 1.0; } // **************************************************************************** @@ -339,10 +336,7 @@ bool doesLineIntersectArc(const Point2D ¢re, double xradius, double yradius, return true; } Point2D p2 = end2 - centre; - if (pointInArc(p2)) { - return true; - } - return false; + return pointInArc(p2); } // **************************************************************************** diff --git a/Code/GraphMol/MolDraw2D/MolDraw2DUtils.cpp b/Code/GraphMol/MolDraw2D/MolDraw2DUtils.cpp index 0034b66db..cdd3759e5 100644 --- a/Code/GraphMol/MolDraw2D/MolDraw2DUtils.cpp +++ b/Code/GraphMol/MolDraw2D/MolDraw2DUtils.cpp @@ -32,13 +32,10 @@ bool isAtomCandForChiralH(const RWMol &mol, const Atom *atom) { // conditions for needing a chiral H: // - stereochem specified // - in at least two rings - if (mol.getRingInfo()->isInitialized() && - mol.getRingInfo()->numAtomRings(atom->getIdx()) > 1 && - (atom->getChiralTag() == Atom::CHI_TETRAHEDRAL_CCW || - atom->getChiralTag() == Atom::CHI_TETRAHEDRAL_CW)) { - return true; - } - return false; + return mol.getRingInfo()->isInitialized() && + mol.getRingInfo()->numAtomRings(atom->getIdx()) > 1u && + (atom->getChiralTag() == Atom::CHI_TETRAHEDRAL_CCW || + atom->getChiralTag() == Atom::CHI_TETRAHEDRAL_CW); } } // end of anonymous namespace diff --git a/Code/GraphMol/MolDraw2D/StringRect.h b/Code/GraphMol/MolDraw2D/StringRect.h index d9160d8d1..066701474 100644 --- a/Code/GraphMol/MolDraw2D/StringRect.h +++ b/Code/GraphMol/MolDraw2D/StringRect.h @@ -75,10 +75,7 @@ struct StringRect { std::swap(tl, bl); std::swap(tr, br); } - if (pt.x >= tl.x && pt.x <= br.x && pt.y >= br.y && pt.y <= tl.y) { - return true; - } - return false; + return pt.x >= tl.x && pt.x <= br.x && pt.y >= br.y && pt.y <= tl.y; } bool doesItIntersect(const StringRect &other, double padding = 0.0) const { Point2D ttl, ttr, tbr, tbl; diff --git a/Code/GraphMol/QueryOps.cpp b/Code/GraphMol/QueryOps.cpp index ea28ad348..11635d0ec 100644 --- a/Code/GraphMol/QueryOps.cpp +++ b/Code/GraphMol/QueryOps.cpp @@ -890,11 +890,7 @@ bool isComplexQuery(const Atom *a) { if (_complexQueryHelper(a->getQuery(), hasAtNum)) { return true; } - if (hasAtNum) { - return false; - } else { - return true; - } + return !hasAtNum; } return true; diff --git a/Code/GraphMol/QueryOps.h b/Code/GraphMol/QueryOps.h index 452ac75a8..29d8d8b11 100644 --- a/Code/GraphMol/QueryOps.h +++ b/Code/GraphMol/QueryOps.h @@ -141,12 +141,7 @@ static inline void parseAtomType(int val, int &atomic_num, bool &aromatic) { atomic_num = val; } } -static inline bool getAtomTypeIsAromatic(int val) { - if (val > 1000) { - return true; - } - return false; -} +static inline bool getAtomTypeIsAromatic(int val) { return val > 1000; } static inline int getAtomTypeAtomicNum(int val) { if (val > 1000) { return val - 1000; diff --git a/Code/GraphMol/SmilesParse/CXSmilesOps.cpp b/Code/GraphMol/SmilesParse/CXSmilesOps.cpp index 5163a9c1b..cfe946de6 100644 --- a/Code/GraphMol/SmilesParse/CXSmilesOps.cpp +++ b/Code/GraphMol/SmilesParse/CXSmilesOps.cpp @@ -1086,10 +1086,7 @@ bool processRadicalSection(Iterator &first, Iterator last, RDKit::RWMol &mol, ->setNumRadicalElectrons(numRadicalElectrons); } } - if (first >= last) { - return false; - } - return true; + return first < last; } template diff --git a/Code/GraphMol/SmilesParse/SmilesWrite.cpp b/Code/GraphMol/SmilesParse/SmilesWrite.cpp index f092d8575..6c393009f 100644 --- a/Code/GraphMol/SmilesParse/SmilesWrite.cpp +++ b/Code/GraphMol/SmilesParse/SmilesWrite.cpp @@ -32,10 +32,7 @@ bool inOrganicSubset(int atomicNumber) { while (atomicSmiles[idx] < atomicNumber && atomicSmiles[idx] != -1) { ++idx; } - if (atomicSmiles[idx] == atomicNumber) { - return true; - } - return false; + return atomicSmiles[idx] == atomicNumber; } std::string GetAtomSmiles(const Atom *atom, bool doKekule, const Bond *, diff --git a/Code/Query/EqualityQuery.h b/Code/Query/EqualityQuery.h index 084eb5454..502d7303b 100644 --- a/Code/Query/EqualityQuery.h +++ b/Code/Query/EqualityQuery.h @@ -52,17 +52,9 @@ class RDKIT_QUERY_EXPORT EqualityQuery MatchFuncArgType mfArg = this->TypeConvert(what, Int2Type()); if (queryCmp(this->d_val, mfArg, this->d_tol) == 0) { - if (this->getNegation()) { - return false; - } else { - return true; - } + return !this->getNegation(); } else { - if (this->getNegation()) { - return true; - } else { - return false; - } + return this->getNegation(); } } diff --git a/Code/Query/GreaterEqualQuery.h b/Code/Query/GreaterEqualQuery.h index de7f154aa..16797f965 100644 --- a/Code/Query/GreaterEqualQuery.h +++ b/Code/Query/GreaterEqualQuery.h @@ -39,17 +39,9 @@ class RDKIT_QUERY_EXPORT GreaterEqualQuery MatchFuncArgType mfArg = this->TypeConvert(what, Int2Type()); if (queryCmp(this->d_val, mfArg, this->d_tol) >= 0) { - if (this->getNegation()) { - return false; - } else { - return true; - } + return !this->getNegation(); } else { - if (this->getNegation()) { - return true; - } else { - return false; - } + return this->getNegation(); } } Query *copy() diff --git a/Code/Query/GreaterQuery.h b/Code/Query/GreaterQuery.h index cbf6df2b0..aea9a5a96 100644 --- a/Code/Query/GreaterQuery.h +++ b/Code/Query/GreaterQuery.h @@ -39,17 +39,9 @@ class RDKIT_QUERY_EXPORT GreaterQuery MatchFuncArgType mfArg = this->TypeConvert(what, Int2Type()); if (queryCmp(this->d_val, mfArg, this->d_tol) > 0) { - if (this->getNegation()) { - return false; - } else { - return true; - } + return !this->getNegation(); } else { - if (this->getNegation()) { - return true; - } else { - return false; - } + return this->getNegation(); } } diff --git a/Code/Query/LessEqualQuery.h b/Code/Query/LessEqualQuery.h index f27e737c1..bbf869926 100644 --- a/Code/Query/LessEqualQuery.h +++ b/Code/Query/LessEqualQuery.h @@ -39,17 +39,9 @@ class RDKIT_QUERY_EXPORT LessEqualQuery MatchFuncArgType mfArg = this->TypeConvert(what, Int2Type()); if (queryCmp(this->d_val, mfArg, this->d_tol) <= 0) { - if (this->getNegation()) { - return false; - } else { - return true; - } + return !this->getNegation(); } else { - if (this->getNegation()) { - return true; - } else { - return false; - } + return this->getNegation(); } } diff --git a/Code/Query/LessQuery.h b/Code/Query/LessQuery.h index 581633953..d101e78cd 100644 --- a/Code/Query/LessQuery.h +++ b/Code/Query/LessQuery.h @@ -39,17 +39,9 @@ class RDKIT_QUERY_EXPORT LessQuery MatchFuncArgType mfArg = this->TypeConvert(what, Int2Type()); if (queryCmp(this->d_val, mfArg, this->d_tol) < 0) { - if (this->getNegation()) { - return false; - } else { - return true; - } + return !this->getNegation(); } else { - if (this->getNegation()) { - return true; - } else { - return false; - } + return this->getNegation(); } } diff --git a/Code/RDGeneral/RDLog.cpp b/Code/RDGeneral/RDLog.cpp index 0758e6897..e3c32a837 100644 --- a/Code/RDGeneral/RDLog.cpp +++ b/Code/RDGeneral/RDLog.cpp @@ -105,12 +105,7 @@ void disable_logs(const std::string &arg) { } }; -bool is_log_enabled(RDLogger log) { - if (log && log->df_enabled) { - return true; - } - return false; -} +bool is_log_enabled(RDLogger log) { return log && log->df_enabled; } void get_log_status(std::ostream &ss, const std::string &name, RDLogger log) { ss << name << ":"; diff --git a/External/GA/ga/StringChromosome.cpp b/External/GA/ga/StringChromosome.cpp index 31d9ee9e5..da3be8657 100644 --- a/External/GA/ga/StringChromosome.cpp +++ b/External/GA/ga/StringChromosome.cpp @@ -26,7 +26,7 @@ int StringChromosome::decodeToInt( int mask = 1, result = 0; bool *ptr = string.get() + start; for (int i = 0; i < nBits; i++, mask <<= 1) { - if (*ptr++ == true) { + if (*ptr++) { result |= mask; } }