diff --git a/Code/DataStructs/DiscreteValueVect.cpp b/Code/DataStructs/DiscreteValueVect.cpp index 926e96347..e4f718f7d 100644 --- a/Code/DataStructs/DiscreteValueVect.cpp +++ b/Code/DataStructs/DiscreteValueVect.cpp @@ -167,9 +167,10 @@ std::string DiscreteValueVect::toString() const { #if defined(BOOST_BIG_ENDIAN) std::uint32_t *td = new std::uint32_t[d_numInts]; - for (unsigned int i = 0; i < d_numInts; ++i) + for (unsigned int i = 0; i < d_numInts; ++i) { td[i] = EndianSwapBytes( d_data.get()[i]); + } ss.write((const char *)td, d_numInts * sizeof(tInt)); delete[] td; #else @@ -208,8 +209,9 @@ void DiscreteValueVect::initFromText(const char *pkl, const unsigned int len) { #if defined(BOOST_BIG_ENDIAN) std::uint32_t *td = new std::uint32_t[d_numInts]; - for (unsigned int i = 0; i < d_numInts; ++i) + for (unsigned int i = 0; i < d_numInts; ++i) { td[i] = EndianSwapBytes(data[i]); + } d_data.reset(td); delete[] data; #else diff --git a/Code/GraphMol/Aromaticity.cpp b/Code/GraphMol/Aromaticity.cpp index 0b80a6681..6686c37ef 100644 --- a/Code/GraphMol/Aromaticity.cpp +++ b/Code/GraphMol/Aromaticity.cpp @@ -791,7 +791,9 @@ int mmff94AromaticityHelper(RWMol &mol, const VECT_INT_VECT &srings) { break; } } - if (isAromRing) narom++; + if (isAromRing) { + narom++; + } } return narom; diff --git a/Code/GraphMol/ChemReactions/SanitizeRxn.cpp b/Code/GraphMol/ChemReactions/SanitizeRxn.cpp index 13e6e3b1c..76f4a3623 100644 --- a/Code/GraphMol/ChemReactions/SanitizeRxn.cpp +++ b/Code/GraphMol/ChemReactions/SanitizeRxn.cpp @@ -303,8 +303,9 @@ void fixReactantTemplateAromaticity(ChemicalReaction &rxn) { auto *rw = dynamic_cast(it->get()); if (rw) { sanitizeMol(*rw, ops, MolOps::SANITIZE_SETAROMATICITY); - } else + } else { PRECONDITION(rw, "Oops, not really a RWMol?"); + } } } @@ -361,8 +362,9 @@ void fixHs(ChemicalReaction &rxn) { auto *rw = dynamic_cast(it->get()); if (rw) { MolOps::mergeQueryHs(*rw, mergeUnmappedOnly); - } else + } else { PRECONDITION(rw, "Oops, not really an RWMol?"); + } } } @@ -372,8 +374,9 @@ void adjustTemplates(const MOL_SPTR_VECT &templates, auto *rw = dynamic_cast(templ.get()); if (rw) { adjustQueryProperties(*rw, ¶ms); - } else + } else { PRECONDITION(rw, "Oops, not really a RWMol?"); + } } } void sanitizeRxn(ChemicalReaction &rxn, unsigned int &operationsThatFailed, diff --git a/Code/GraphMol/Descriptors/DCLV.cpp b/Code/GraphMol/Descriptors/DCLV.cpp index b0e975f44..bfd0eb078 100644 --- a/Code/GraphMol/Descriptors/DCLV.cpp +++ b/Code/GraphMol/Descriptors/DCLV.cpp @@ -581,4 +581,4 @@ double DoubleCubicLatticeVolume::getPackingDensity() { } } // namespace Descriptors -} // namespace RDKit \ No newline at end of file +} // namespace RDKit diff --git a/Code/GraphMol/Descriptors/USRDescriptor.cpp b/Code/GraphMol/Descriptors/USRDescriptor.cpp index db79f39c4..105e35fac 100644 --- a/Code/GraphMol/Descriptors/USRDescriptor.cpp +++ b/Code/GraphMol/Descriptors/USRDescriptor.cpp @@ -117,10 +117,11 @@ void calcMoments(const std::vector &dist, } else { #ifdef WIN32 moments[2] = moments[2] / (moments[1] * moments[1] * moments[1]); - if (moments[2] >= 0) + if (moments[2] >= 0) { moments[2] = pow(moments[2], 1. / 3.); - else + } else { moments[2] = -1. * pow(-1. * moments[2], 1. / 3.); + } #else moments[2] = cbrt(moments[2] / (moments[1] * moments[1] * moments[1])); #endif diff --git a/Code/GraphMol/FileParsers/MultithreadedSDMolSupplier.cpp b/Code/GraphMol/FileParsers/MultithreadedSDMolSupplier.cpp index 875b8b29f..e551f7b3f 100644 --- a/Code/GraphMol/FileParsers/MultithreadedSDMolSupplier.cpp +++ b/Code/GraphMol/FileParsers/MultithreadedSDMolSupplier.cpp @@ -134,9 +134,10 @@ bool MultithreadedSDMolSupplier::extractNextRecord(std::string &record, } // ignore trailing new lines - if(record.find_first_not_of("\n\r") == std::string::npos) + if (record.find_first_not_of("\n\r") == std::string::npos) { return false; - + } + index = d_currentRecordId; ++d_currentRecordId; return true; diff --git a/Code/GraphMol/FileParsers/SDMolSupplier.cpp b/Code/GraphMol/FileParsers/SDMolSupplier.cpp index dfd43f19e..733f7bf97 100644 --- a/Code/GraphMol/FileParsers/SDMolSupplier.cpp +++ b/Code/GraphMol/FileParsers/SDMolSupplier.cpp @@ -311,7 +311,9 @@ void SDMolSupplier::buildIndexTo(unsigned int targetIdx) { while (true) { constexpr char dollarSigns[]{"$$$$"}; auto match = std::search(ptr, bufEnd, dollarSigns, dollarSigns + 4); - if (match == bufEnd) break; + if (match == bufEnd) { + break; + } if (*(match - 1) == '\n') { // ensure $$$$ is at start of line char *nlPos = match + 4; while (nlPos < bufEnd && *nlPos != '\n') { @@ -368,8 +370,9 @@ void SDMolSupplier::buildIndexTo(unsigned int targetIdx) { dp_inStream->seekg(chunkEndPos); } - if (bytesRead >= static_cast(OVERLAP)) + if (bytesRead >= static_cast(OVERLAP)) { std::memcpy(&buffer[0], bufEnd - OVERLAP, OVERLAP); + } currentStreamPos = chunkEndPos; } } diff --git a/Code/GraphMol/FileParsers/cdxml_parser_catch.cpp b/Code/GraphMol/FileParsers/cdxml_parser_catch.cpp index 9a259fed3..453780a1d 100644 --- a/Code/GraphMol/FileParsers/cdxml_parser_catch.cpp +++ b/Code/GraphMol/FileParsers/cdxml_parser_catch.cpp @@ -1417,18 +1417,20 @@ TEST_CASE("CDX and Formats") { } bool expected = false; - if(format == CDXMLFormat::CDX) - expected = check.cdxres; - else if(format == CDXMLFormat::CDXML) - expected = check.cdxmlres; - else - expected = check.autores; + if (format == CDXMLFormat::CDX) { + expected = check.cdxres; + } else if (format == CDXMLFormat::CDXML) { + expected = check.cdxmlres; + } else { + expected = check.autores; + } - if (exception) - CHECK(expected == false); - else - CHECK(expected == hasmols); - } + if (exception) { + CHECK(expected == false); + } else { + CHECK(expected == hasmols); + } + } } } } diff --git a/Code/GraphMol/FilterCatalog/filtercatalogtest.cpp b/Code/GraphMol/FilterCatalog/filtercatalogtest.cpp index addf43373..7648db8e9 100644 --- a/Code/GraphMol/FilterCatalog/filtercatalogtest.cpp +++ b/Code/GraphMol/FilterCatalog/filtercatalogtest.cpp @@ -312,7 +312,9 @@ void testFilterCatalogCHEMBL() { std::unique_ptr mol(SmilesToMol(test.first)); std::string matches; for (auto &match : catalog.getMatches(*mol)) { - if (matches.size()) matches += "|"; + if (matches.size()) { + matches += "|"; + } matches += match->getDescription(); } @@ -333,7 +335,9 @@ void testFilterCatalogCHEMBL() { std::unique_ptr mol(SmilesToMol(test.first)); std::string matches; for (auto &match : catalog.getMatches(*mol)) { - if (matches.size()) matches += "|"; + if (matches.size()) { + matches += "|"; + } matches += match->getDescription(); } TEST_ASSERT(matches == test.second); diff --git a/Code/GraphMol/MMPA/MMPA.cpp b/Code/GraphMol/MMPA/MMPA.cpp index e63a3cc55..e906039df 100644 --- a/Code/GraphMol/MMPA/MMPA.cpp +++ b/Code/GraphMol/MMPA/MMPA.cpp @@ -158,19 +158,21 @@ static void addResult(std::vector> mol.getAtomWithIdx(bonds_selected[bi].first) ->getPropIfPresent(common_properties::molAtomMapNumber, label); char a1[32]; - if (0 == label) + if (0 == label) { sprintf(a1, "\'%s\'", symbol.c_str(), label); - else + } else { sprintf(a1, "\'%s:%u\'", symbol.c_str(), label); + } symbol = mol.getAtomWithIdx(bonds_selected[bi].second)->getSymbol(); label = 0; mol.getAtomWithIdx(bonds_selected[bi].second) ->getPropIfPresent(common_properties::molAtomMapNumber, label); char a2[32]; - if (0 == label) + if (0 == label) { sprintf(a2, "\'%s\'", symbol.c_str(), label); - else + } else { sprintf(a2, "\'%s:%u\'", symbol.c_str(), label); + } std::cout << "(" << bonds_selected[bi].first << a1 << "," << bonds_selected[bi].second << a2 << ") "; @@ -249,9 +251,10 @@ static void addResult(std::vector> } else { // select the core fragment // DEBUG PRINT #ifdef MMPA_DEBUG - if (iCore != -1) + if (iCore != -1) { std::cout << "Next CORE found. iCore=" << iCore << " New i=" << i << " nAttachments=" << nAttachments << "\n"; + } #endif if (nAttachments >= maxAttachments) { // Choose a fragment with maximal // number of connection points as @@ -379,9 +382,10 @@ static void addResult(std::vector> res.emplace_back(core, side_chains); // } #ifdef MMPA_DEBUG - else + else { std::cout << res.size() + 1 << " --- DUPLICATE Result FOUND --- ri=" << ri << "\n"; + } #endif } @@ -441,10 +445,11 @@ bool fragmentMol(const ROMol &mol, mol.getAtomWithIdx(i)->getPropIfPresent(common_properties::molAtomMapNumber, label); char a1[32]; - if (0 == label) + if (0 == label) { sprintf(a1, "\'%s\'", symbol.c_str(), label); - else + } else { sprintf(a1, "\'%s:%u\'", symbol.c_str(), label); + } std::cout << "Atom " << i << ": " << a1; //<<" Bonds:"; std::cout << "\n"; } @@ -471,19 +476,21 @@ bool fragmentMol(const ROMol &mol, mol.getAtomWithIdx(matching_atoms[i][0].second) ->getPropIfPresent(common_properties::molAtomMapNumber, label); char a1[32]; - if (0 == label) + if (0 == label) { sprintf(a1, "\'%s\'", symbol.c_str(), label); - else + } else { sprintf(a1, "\'%s:%u\'", symbol.c_str(), label); + } symbol = mol.getAtomWithIdx(matching_atoms[i][1].second)->getSymbol(); label = 0; mol.getAtomWithIdx(matching_atoms[i][1].second) ->getPropIfPresent(common_properties::molAtomMapNumber, label); char a2[32]; - if (0 == label) + if (0 == label) { sprintf(a2, "\'%s\'", symbol.c_str(), label); - else + } else { sprintf(a2, "\'%s:%u\'", symbol.c_str(), label); + } std::cout << i << ": (" << matching_atoms[i][0].second << a1 << "," << matching_atoms[i][1].second << a2 << ") \n"; diff --git a/Code/GraphMol/MolDraw2D/Qt/Demo/stddefs.H b/Code/GraphMol/MolDraw2D/Qt/Demo/stddefs.H index cab95c1d0..94ed6354c 100644 --- a/Code/GraphMol/MolDraw2D/Qt/Demo/stddefs.H +++ b/Code/GraphMol/MolDraw2D/Qt/Demo/stddefs.H @@ -150,15 +150,16 @@ template inline T angle( const T vec1[3] , T len1 , T theta = fabs( asin( sin_theta ) ); // find the appropriate quadrant - if both positive, nothing to do - if( sin_theta > 0.0 && cos_theta < 0.0 ) + if( sin_theta > 0.0 && cos_theta < 0.0 ) { // 2nd quadrant - subtract from 180 theta = M_PI - theta; - else if( sin_theta < 0.0 && cos_theta < 0.0 ) + } else if( sin_theta < 0.0 && cos_theta < 0.0 ) { // 3rd quadrant, add 180 theta += M_PI; - else if( sin_theta < 0.0 && cos_theta > 0.0 ) + } else if( sin_theta < 0.0 && cos_theta > 0.0 ) { // 4th quadrant, subtract from 360 theta = 2 * M_PI - theta; + } return theta; @@ -275,10 +276,11 @@ template inline void translate( U coords[3] , inline bool touch_file( const std::string filename ) { std::ofstream tf( filename.c_str() ); - if( tf && tf.good() ) + if( tf && tf.good() ) { return true; - else + } else { return false; + } } @@ -287,8 +289,9 @@ inline bool touch_file( const std::string filename ) { template inline void vec_print( const T *vec , bool add_new_line = true ) { std::cout << vec[0] << " , " << vec[1] << " , " << vec[2]; - if( add_new_line ) + if( add_new_line ) { std::cout << std::endl; + } } @@ -360,13 +363,14 @@ template inline void calc_normal_to_2D_vec( T bond[2] , // deleted in two steps : delete [] t[0]; delete [] t; template inline void make_square_matrix( T **&t , int mat_size ) { - if( mat_size <= 0 ) + if( mat_size <= 0 ) { t = 0; - else { + } else { t = new T *[mat_size]; t[0] = new T[mat_size * mat_size]; - for( int i = 1 ; i < mat_size ; ++i ) + for( int i = 1 ; i < mat_size ; ++i ) { t[i] = t[i-1] + mat_size; + } } } @@ -385,13 +389,15 @@ template inline void destroy_square_matrix( T **&t ) { // make and destroy 2D matrix - more general case of above. template inline T** make_2d_matrix( int num_x , int num_y ) { - if( num_x <= 0 || num_y <= 0 ) + if( num_x <= 0 || num_y <= 0 ) { return 0; + } T **ret_mat = new T*[num_x]; ret_mat[0] = new T[num_x * num_y]; - for( int i = 1 ; i < num_x ; ++i ) + for( int i = 1 ; i < num_x ; ++i ) { ret_mat[i] = ret_mat[i-1] + num_y; + } return ret_mat; @@ -412,21 +418,24 @@ template inline void destroy_2d_matrix( T **&in_mat ) { template inline T*** make_3d_matrix( int num_x , int num_y , int num_z ) { - if( num_x <= 0 || num_y <= 0 || num_z <= 0 ) + if( num_x <= 0 || num_y <= 0 || num_z <= 0 ) { return 0; + } T ***ret_mat = new T**[num_x]; ret_mat[0] = new T*[num_x * num_y]; ret_mat[0][0] = new T[num_x * num_y * num_z]; - for( int j = 1 ; j < num_y ; ++j ) + for( int j = 1 ; j < num_y ; ++j ) { ret_mat[0][j] = ret_mat[0][j-1] + num_z; + } for( int i = 1 ; i < num_x ; ++i ) { ret_mat[i] = ret_mat[i-1] + num_y; ret_mat[i][0] = ret_mat[i-1][0] + num_y * num_z; - for( int j = 1 ; j < num_y ; ++j ) + for( int j = 1 ; j < num_y ; ++j ) { ret_mat[i][j] = ret_mat[i][j-1] + num_z; + } } return ret_mat; @@ -436,8 +445,9 @@ template inline T*** make_3d_matrix( int num_x , int num_y , //*************************************************************************** template inline void destroy_3d_matrix( T ***&in_mat ) { - if( !in_mat ) + if( !in_mat ) { return; + } delete [] in_mat[0][0]; delete [] in_mat[0]; @@ -453,8 +463,9 @@ inline double fac( int n ) { double fac = 1.0; if( n < 30 ) { - for( int i = 1 ; i <= n ; ++i ) + for( int i = 1 ; i <= n ; ++i ) { fac *= i; + } } else { // uses Gosper's approximation, more accurate than Stirling's double fltn = double( n ); diff --git a/Code/GraphMol/MolDraw2D/Qt/MolDraw2DQt.cpp b/Code/GraphMol/MolDraw2D/Qt/MolDraw2DQt.cpp index 3988f69f9..cc36b7a99 100644 --- a/Code/GraphMol/MolDraw2D/Qt/MolDraw2DQt.cpp +++ b/Code/GraphMol/MolDraw2D/Qt/MolDraw2DQt.cpp @@ -86,7 +86,9 @@ namespace { void setDashes(QPen &pen, const DashPattern &dashes) { if (dashes.size()) { QVector dd; - for (unsigned int di = 0; di < dashes.size(); ++di) dd << dashes[di]; + for (unsigned int di = 0; di < dashes.size(); ++di) { + dd << dashes[di]; + } pen.setDashPattern(dd); } else { pen.setStyle(Qt::SolidLine); diff --git a/Code/GraphMol/NontetrahedralStereo.cpp b/Code/GraphMol/NontetrahedralStereo.cpp index 97c489119..bb4569dac 100644 --- a/Code/GraphMol/NontetrahedralStereo.cpp +++ b/Code/GraphMol/NontetrahedralStereo.cpp @@ -253,7 +253,9 @@ int isTrigonalBipyramidalAxialBond(const Atom *cen, const Bond *qry) { } unsigned int perm = 0; cen->getPropIfPresent(RDKit::common_properties::_chiralPermutation, perm); - if (perm == 0 || perm > 20) return 0; + if (perm == 0 || perm > 20) { + return 0; + } unsigned int count = 0; for (const auto bnd : cen->getOwningMol().atomBonds(cen)) { @@ -438,19 +440,24 @@ Bond *getTrigonalBipyramidalAxialBond(const Atom *cen, int axial) { PRECONDITION(cen, "bad center pointer"); PRECONDITION(cen->hasOwningMol(), "no owning mol"); if (cen->getChiralTag() != RDKit::Atom::ChiralType::CHI_TRIGONALBIPYRAMIDAL || - cen->getDegree() > 5) + cen->getDegree() > 5) { return nullptr; + } unsigned int perm = 0; cen->getPropIfPresent(RDKit::common_properties::_chiralPermutation, perm); - if (perm == 0 || perm > 20) return nullptr; + if (perm == 0 || perm > 20) { + return nullptr; + } unsigned int idx = (axial != -1) ? trigonalbipyramidal_axial[perm][0] : trigonalbipyramidal_axial[perm][1]; unsigned int count = 0; for (const auto bnd : cen->getOwningMol().atomBonds(cen)) { - if (count == idx) return bnd; + if (count == idx) { + return bnd; + } count++; } return nullptr; @@ -526,8 +533,9 @@ unsigned int getChiralPermutation(const Atom *cen, const INT_LIST &probe, } // Missing (implicit) neighbors are at the end when in storage order - if (nbrPerm.size() < nbrIdx) + if (nbrPerm.size() < nbrIdx) { nbrPerm.insert(nbrPerm.end(), nbrIdx - nbrPerm.size(), -1); + } CHECK_INVARIANT(nbrPerm.size() == probePerm.size(), "probe vector size does not match"); diff --git a/Code/GraphMol/RWMol.cpp b/Code/GraphMol/RWMol.cpp index fafa8687b..f5cc0ad67 100644 --- a/Code/GraphMol/RWMol.cpp +++ b/Code/GraphMol/RWMol.cpp @@ -691,7 +691,9 @@ void RWMol::batchRemoveBonds() { auto &delBonds = *dp_delBonds; unsigned int min_idx = getNumBonds(); for (unsigned int i = rdcast(delBonds.size()); i > 0; --i) { - if (!delBonds[i - 1]) continue; + if (!delBonds[i - 1]) { + continue; + } unsigned int idx = rdcast(i - 1); Bond *bnd = getBondWithIdx(idx); if (!bnd) { @@ -776,10 +778,14 @@ void RWMol::batchRemoveAtoms() { auto &delAtoms = *dp_delAtoms; for (unsigned int i = rdcast(delAtoms.size()); i > 0; --i) { - if (!delAtoms[i - 1]) continue; + if (!delAtoms[i - 1]) { + continue; + } unsigned int idx = i - 1; Atom *atom = getAtomWithIdx(idx); - if (!atom) continue; + if (!atom) { + continue; + } // remove any bookmarks which point to this atom: ATOM_BOOKMARK_MAP *marks = getAtomBookmarks(); diff --git a/Code/GraphMol/SLNParse/sln.yy b/Code/GraphMol/SLNParse/sln.yy index 39bd8fdd9..2db1c7e95 100644 --- a/Code/GraphMol/SLNParse/sln.yy +++ b/Code/GraphMol/SLNParse/sln.yy @@ -77,9 +77,11 @@ yysln_error( const char *input, static void yyprint (FILE *file, int type, YYSTYPE value) { - if (type == TEXT_BLOCK) + if (type == TEXT_BLOCK) { fprintf (file, " %s", value.text_T->c_str()); - else fprintf (file, " %d", type); + } else { + fprintf (file, " %d", type); + } } %} diff --git a/Code/GraphMol/SmilesParse/CXSmilesOps.cpp b/Code/GraphMol/SmilesParse/CXSmilesOps.cpp index 9a03ddfd8..ed460ce3c 100644 --- a/Code/GraphMol/SmilesParse/CXSmilesOps.cpp +++ b/Code/GraphMol/SmilesParse/CXSmilesOps.cpp @@ -2131,9 +2131,10 @@ std::string get_bond_config_block( for (unsigned int bondAtomIndex = 0; bondAtomIndex < 2; ++bondAtomIndex) { - if (atomAndBondVecs[bondAtomIndex].first == firstAtom) + if (atomAndBondVecs[bondAtomIndex].first == firstAtom) { continue; // swapped atoms on the side where the wedge bond // is does NOT change the wedge bond + } if (atomAndBondVecs[bondAtomIndex].second.size() == 2) { unsigned int firstOtherAtomIdx = atomAndBondVecs[bondAtomIndex] diff --git a/Code/GraphMol/SmilesParse/smarts.ll b/Code/GraphMol/SmilesParse/smarts.ll index 2e3336b98..10c6d2ed6 100644 --- a/Code/GraphMol/SmilesParse/smarts.ll +++ b/Code/GraphMol/SmilesParse/smarts.ll @@ -53,16 +53,17 @@ size_t setup_smarts_string(const std::string &text,yyscan_t yyscanner){ /* Get memory for full buffer, including space for trailing EOB's. */ n = _yybytes_len + 2; buf = (char *) yysmarts_alloc(n ,yyscanner ); - if ( ! buf ) + if ( ! buf ) { smarts_lexer_error( "out of dynamic memory in yysmarts__scan_bytes()" ); + } // ltrim for(start = 0 ; start < _yybytes_len; ++start) { - if (yybytes[start] > 32) break; + if (yybytes[start] > 32) { break; } } for(end = _yybytes_len ; end > start; --end) { - if (yybytes[end] > 32) break; + if (yybytes[end] > 32) { break; } } _yybytes_len = end-start+1; @@ -73,8 +74,9 @@ size_t setup_smarts_string(const std::string &text,yyscan_t yyscanner){ buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; b = yysmarts__scan_buffer(buf,n ,yyscanner); - if ( ! b ) + if ( ! b ) { smarts_lexer_error( "bad buffer in yysmarts__scan_bytes()" ); + } /* It's okay to grow etc. this buffer, and we should throw it * away when we're done. diff --git a/Code/GraphMol/SmilesParse/smarts.yy b/Code/GraphMol/SmilesParse/smarts.yy index a4684b92b..c9084e3ea 100644 --- a/Code/GraphMol/SmilesParse/smarts.yy +++ b/Code/GraphMol/SmilesParse/smarts.yy @@ -487,14 +487,14 @@ hydrogen_atom: ATOM_OPEN_TOKEN H_TOKEN ATOM_CLOSE_TOKEN /* --------------------------------------------------------------- */ atom_expr: atom_expr AND_TOKEN atom_expr { $1->expandQuery($3->getQuery()->copy(),Queries::COMPOSITE_AND,true); - if($1->getChiralTag()==Atom::CHI_UNSPECIFIED) $1->setChiralTag($3->getChiralTag()); + if ($1->getChiralTag()==Atom::CHI_UNSPECIFIED) { $1->setChiralTag($3->getChiralTag()); } SmilesParseOps::ClearAtomChemicalProps($1); delete $3; $$ = $1; } | atom_expr OR_TOKEN atom_expr { $1->expandQuery($3->getQuery()->copy(),Queries::COMPOSITE_OR,true); - if($1->getChiralTag()==Atom::CHI_UNSPECIFIED) $1->setChiralTag($3->getChiralTag()); + if ($1->getChiralTag()==Atom::CHI_UNSPECIFIED) { $1->setChiralTag($3->getChiralTag()); } SmilesParseOps::ClearAtomChemicalProps($1); $1->setAtomicNum(0); delete $3; @@ -502,7 +502,7 @@ atom_expr: atom_expr AND_TOKEN atom_expr { } | atom_expr SEMI_TOKEN atom_expr { $1->expandQuery($3->getQuery()->copy(),Queries::COMPOSITE_AND,true); - if($1->getChiralTag()==Atom::CHI_UNSPECIFIED) $1->setChiralTag($3->getChiralTag()); + if ($1->getChiralTag()==Atom::CHI_UNSPECIFIED) { $1->setChiralTag($3->getChiralTag()); } SmilesParseOps::ClearAtomChemicalProps($1); delete $3; $$ = $1; diff --git a/Code/GraphMol/SmilesParse/smiles.ll b/Code/GraphMol/SmilesParse/smiles.ll index 69c18bfe9..21ab5cdb3 100644 --- a/Code/GraphMol/SmilesParse/smiles.ll +++ b/Code/GraphMol/SmilesParse/smiles.ll @@ -53,16 +53,17 @@ size_t setup_smiles_string(const std::string &text,yyscan_t yyscanner){ /* Get memory for full buffer, including space for trailing EOB's. */ n = _yybytes_len + 2; buf = (char *) yysmiles_alloc(n ,yyscanner ); - if ( ! buf ) + if ( ! buf ) { smiles_lexer_error( "out of dynamic memory in yysmiles__scan_bytes()" ); + } // ltrim for(start = 0 ; start < _yybytes_len; ++start) { - if (yybytes[start] > 32) break; + if (yybytes[start] > 32) { break; } } for(end = _yybytes_len ; end > start; --end) { - if (yybytes[end] > 32) break; + if (yybytes[end] > 32) { break; } } _yybytes_len = end-start+1; @@ -73,8 +74,9 @@ size_t setup_smiles_string(const std::string &text,yyscan_t yyscanner){ buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; b = yysmiles__scan_buffer(buf,n ,yyscanner); - if ( ! b ) + if ( ! b ) { smiles_lexer_error( "bad buffer in yysmiles__scan_bytes()" ); + } /* It's okay to grow etc. this buffer, and we should throw it * away when we're done. diff --git a/Code/GraphMol/StructChecker/AtomSymbolMatch.cpp b/Code/GraphMol/StructChecker/AtomSymbolMatch.cpp index 40dee7444..f972e58c7 100644 --- a/Code/GraphMol/StructChecker/AtomSymbolMatch.cpp +++ b/Code/GraphMol/StructChecker/AtomSymbolMatch.cpp @@ -65,7 +65,9 @@ class AtomSymbolMapper { public: AtomSymbolMapper() { - for (unsigned n = 0; n < 110; n++) SymbolMap[AtomSymbol[n]] = n; + for (unsigned n = 0; n < 110; n++) { + SymbolMap[AtomSymbol[n]] = n; + } } inline unsigned getAtomicNumber(const std::string symbol) const { return SymbolMap.find(symbol)->second; @@ -237,8 +239,11 @@ static const char *amino_acids[] = /* pseudosymbol "Ami" or "ami"*/ static bool IsInStringTable(const char *symbol, const char *table[]) { // Checks if the string symbol is listed in table[] const char **stringp; - for (stringp = table; *stringp; stringp++) - if (0 == strcmp(*stringp, symbol)) return true; + for (stringp = table; *stringp; stringp++) { + if (0 == strcmp(*stringp, symbol)) { + return true; + } + } return false; } @@ -263,68 +268,113 @@ bool AtomSymbolMatch(const std::string symbol, const std::string pattern) { tokp = strtok_r((char *)nullptr, ",", &context)) { if (islower(*tokp)) { if (0 == strcmp("alk", tokp)) { - if (IsInStringTable(atsym, alkali_metals)) return true; + if (IsInStringTable(atsym, alkali_metals)) { + return true; + } } else if (0 == strcmp("gr2", tokp)) { - if (IsInStringTable(atsym, gr2)) return true; + if (IsInStringTable(atsym, gr2)) { + return true; + } } else if (0 == strcmp("gr3", tokp)) { - if (IsInStringTable(atsym, gr3)) return true; + if (IsInStringTable(atsym, gr3)) { + return true; + } } else if (0 == strcmp("gr4", tokp)) { - if (IsInStringTable(atsym, gr4)) return true; + if (IsInStringTable(atsym, gr4)) { + return true; + } } else if (0 == strcmp("ons", tokp)) { - if (IsInStringTable(atsym, ONS_table)) return true; + if (IsInStringTable(atsym, ONS_table)) { + return true; + } } else if (0 == strcmp("on2", tokp)) { - if (IsInStringTable(atsym, on2)) return true; + if (IsInStringTable(atsym, on2)) { + return true; + } } else if (0 == strcmp("hal", tokp)) { - if (IsInStringTable(atsym, halogenes)) return true; + if (IsInStringTable(atsym, halogenes)) { + return true; + } } else if (0 == strcmp("ha2", tokp)) { - if (IsInStringTable(atsym, ha2)) return true; + if (IsInStringTable(atsym, ha2)) { + return true; + } } else if (0 == strcmp("trn", tokp)) { - if (IsInStringTable(atsym, transition_metals)) return true; + if (IsInStringTable(atsym, transition_metals)) { + return true; + } } else if (0 == strcmp("tra", tokp)) { - if (IsInStringTable(atsym, tra)) return true; + if (IsInStringTable(atsym, tra)) { + return true; + } } else if (0 == strcmp("trb", tokp)) { - if (IsInStringTable(atsym, trb)) return true; + if (IsInStringTable(atsym, trb)) { + return true; + } } else if (0 == strcmp("tm1", tokp)) { - if (IsInStringTable(atsym, tm1)) return true; + if (IsInStringTable(atsym, tm1)) { + return true; + } } else if (0 == strcmp("tm2", tokp)) { - if (IsInStringTable(atsym, tm2)) return true; + if (IsInStringTable(atsym, tm2)) { + return true; + } } else if (0 == strcmp("tm3", tokp)) { - if (IsInStringTable(atsym, tm3)) return true; + if (IsInStringTable(atsym, tm3)) { + return true; + } } else if (0 == strcmp("tm4", tokp)) { - if (IsInStringTable(atsym, tm4)) return true; + if (IsInStringTable(atsym, tm4)) { + return true; + } } else if (0 == strcmp("tm5", tokp)) { - if (IsInStringTable(atsym, tm5)) return true; + if (IsInStringTable(atsym, tm5)) { + return true; + } } else if (0 == strcmp("tm6", tokp)) { - if (IsInStringTable(atsym, tm6)) return true; + if (IsInStringTable(atsym, tm6)) { + return true; + } } else if (0 == strcmp("tm7", tokp)) { - if (IsInStringTable(atsym, tm7)) return true; + if (IsInStringTable(atsym, tm7)) { + return true; + } } else if (0 == strcmp("tm8", tokp)) { - if (IsInStringTable(atsym, tm8)) return true; + if (IsInStringTable(atsym, tm8)) { + return true; + } } else if (0 == strcmp("lan", tokp)) { - if (IsInStringTable(atsym, lanthanoids)) return true; + if (IsInStringTable(atsym, lanthanoids)) { + return true; + } } else if (0 == strcmp("ami", tokp)) { - if (IsInStringTable(atsym, amino_acids)) return true; + if (IsInStringTable(atsym, amino_acids)) { + return true; + } } } - if (0 == strcmp(atsym, tokp)) return true; + if (0 == strcmp(atsym, tokp)) { + return true; + } } - if (0 == strcmp("A", pattern.c_str())) + if (0 == strcmp("A", pattern.c_str())) { return (0 != strcmp("H", atsym)); - else if (0 == strcmp("Qs", pattern.c_str())) + } else if (0 == strcmp("Qs", pattern.c_str())) { return (IsInStringTable(atsym, non_metal_small_solution)); - else if (0 == strcmp("G", pattern.c_str())) + } else if (0 == strcmp("G", pattern.c_str())) { return (IsInStringTable(atsym, HC_table)); - else if (0 == strcmp("ONS", pattern.c_str())) + } else if (0 == strcmp("ONS", pattern.c_str())) { return (IsInStringTable(atsym, ONS_table)); - else if (0 == strcmp("X", pattern.c_str())) + } else if (0 == strcmp("X", pattern.c_str())) { return (IsInStringTable(atsym, halogenes)); - else if (0 == strcmp("Q", pattern.c_str())) + } else if (0 == strcmp("Q", pattern.c_str())) { return (IsInStringTable(atsym, non_metal_hetero_elements)); - else if (0 == strcmp("M", pattern.c_str())) + } else if (0 == strcmp("M", pattern.c_str())) { return (IsInStringTable(atsym, metals)); - else if (0 == strcmp("Ami", pattern.c_str())) + } else if (0 == strcmp("Ami", pattern.c_str())) { return (IsInStringTable(atsym, amino_acids)); + } return false; } diff --git a/Code/GraphMol/StructChecker/Pattern.cpp b/Code/GraphMol/StructChecker/Pattern.cpp index 0cbdc1805..839fbd3c0 100644 --- a/Code/GraphMol/StructChecker/Pattern.cpp +++ b/Code/GraphMol/StructChecker/Pattern.cpp @@ -33,9 +33,10 @@ static void verboseAtom(const ROMol &mol, int atom_idx, const Atom &a = *mol.getAtomWithIdx(j); snprintf(nstr + strlen(nstr), sizeof(nstr) - strlen(nstr), ", %s", a.getSymbol().c_str()); - if (0 != a.getFormalCharge()) + if (0 != a.getFormalCharge()) { snprintf(nstr + strlen(nstr), sizeof(nstr) - strlen(nstr), "%+d", a.getFormalCharge()); + } } BOOST_LOG(rdInfoLog) << "* CheckAtom idx=" << atom_idx << ", " << mol.getAtomWithIdx(atom_idx)->getSymbol() @@ -76,12 +77,16 @@ AABondType convertBondType(RDKit::Bond::BondType rdbt) { */ bool LigandMatches(const Atom &a, const Bond &b, const Ligand &l, bool use_charge) { - if (l.BondType != ANY_BOND && !isBondTypeMatch(b, l.BondType)) return false; - if (l.Radical != ANY_RADICAL && a.getNumRadicalElectrons() != l.Radical) + if (l.BondType != ANY_BOND && !isBondTypeMatch(b, l.BondType)) { return false; + } + if (l.Radical != ANY_RADICAL && a.getNumRadicalElectrons() != l.Radical) { + return false; + } if ((l.Charge != ANY_CHARGE || use_charge) && l.Charge != ANY_CHARGE && - a.getFormalCharge() != l.Charge) + a.getFormalCharge() != l.Charge) { return false; + } return (AtomSymbolMatch(a.getSymbol(), l.AtomSymbol)); } @@ -193,7 +198,7 @@ bool TransformAugmentedAtoms( for (size_t k = 0; k < neighbours[j].size(); k++) { const Atom *nbrAtom = mol.getAtomWithIdx(neighbours[j][k].AtomIdx); const Bond *nbrBond = mol.getBondWithIdx(neighbours[j][k].BondIdx); - for (size_t l = 0; l < aa1.Ligands.size(); l++) + for (size_t l = 0; l < aa1.Ligands.size(); l++) { if (!visited[l]) { const Ligand &ligand = aa1.Ligands[l]; if ((0 == ligand.SubstitutionCount || @@ -215,44 +220,55 @@ bool TransformAugmentedAtoms( break; } } + } } - if (matched != neighbours[j].size()) + if (matched != neighbours[j].size()) { continue; // go to next molecule's atom + } // Replace Augmented Atom. TransformAA() - if (verbose) + if (verbose) { BOOST_LOG(rdInfoLog) << "Replace " << LogNeighbourhood(mol, j, neighbours_d) << " with AAPair i=" << i << " " << aapair[i].first.AtomSymbol << " -> " << aapair[i].second.AtomSymbol << "\n"; + } // change central atom Atom *a = mol.getAtomWithIdx(j); - if (aa1.AtomSymbol != aa2.AtomSymbol) + if (aa1.AtomSymbol != aa2.AtomSymbol) { applyAtomSymbolList(mol, aa2.AtomSymbol, a); - if (a->getFormalCharge() != aa2.Charge) a->setFormalCharge(aa2.Charge); - if (a->getNumRadicalElectrons() != aa2.Radical) + } + if (a->getFormalCharge() != aa2.Charge) { + a->setFormalCharge(aa2.Charge); + } + if (a->getNumRadicalElectrons() != aa2.Radical) { a->setNumRadicalElectrons(aa2.Radical); + } // change ligand atoms and their bonds with central atom for (size_t l = 0; l < aa2.Ligands.size(); l++) { Atom *al = mol.getAtomWithIdx(match_a[l]); const Ligand &ligand = aa2.Ligands[l]; { // AVALON pattern.c:154 - if (aa1.Ligands[l].AtomSymbol != ligand.AtomSymbol) + if (aa1.Ligands[l].AtomSymbol != ligand.AtomSymbol) { applyAtomSymbolList(mol, ligand.AtomSymbol, al); + } // } } - if (al->getFormalCharge() != ligand.Charge) + if (al->getFormalCharge() != ligand.Charge) { al->setFormalCharge(ligand.Charge); - if (al->getNumRadicalElectrons() != ligand.Radical) + } + if (al->getNumRadicalElectrons() != ligand.Radical) { al->setNumRadicalElectrons(ligand.Radical); + } - if (BT_NONE == ligand.BondType) // remove bond + if (BT_NONE == ligand.BondType) { // remove bond bondsToRemove.push_back( std::pair(j, neighbours[j][l].AtomIdx)); - else if (aa1.Ligands[l].BondType != ligand.BondType) + } else if (aa1.Ligands[l].BondType != ligand.BondType) { mol.getBondWithIdx(match_b[l]) ->setBondType(convertBondType(ligand.BondType)); + } } transformed = true; } @@ -260,7 +276,9 @@ bool TransformAugmentedAtoms( } // remove bonds marked to delete // BT_NONE if (!bondsToRemove.empty()) { - for (auto &i : bondsToRemove) mol.removeBond(i.first, i.second); + for (auto &i : bondsToRemove) { + mol.removeBond(i.first, i.second); + } } return transformed; } @@ -273,29 +291,30 @@ bool isBondTypeMatch(const RDKit::Bond &b, AABondType lbt) { RDKit::Bond::BondType bt = b.getBondType(); bool aromatic = b.getIsAromatic(); - if (ANY_BOND == lbt) + if (ANY_BOND == lbt) { return true; - else if (lbt == AROMATIC) + } else if (lbt == AROMATIC) { return aromatic || bt == RDKit::Bond::AROMATIC || bt == RDKit::Bond::ONEANDAHALF || bt == RDKit::Bond::TWOANDAHALF || bt == RDKit::Bond::THREEANDAHALF; - else if (lbt == SINGLE_AROMATIC) + } else if (lbt == SINGLE_AROMATIC) { return (bt == RDKit::Bond::ONEANDAHALF || (aromatic && bt == RDKit::Bond::SINGLE)); - else if (lbt == DOUBLE_AROMATIC) + } else if (lbt == DOUBLE_AROMATIC) { return (bt == RDKit::Bond::TWOANDAHALF || (aromatic && bt == RDKit::Bond::DOUBLE)); - else if (lbt == SINGLE) + } else if (lbt == SINGLE) { return (bt == RDKit::Bond::SINGLE || bt == RDKit::Bond::ONEANDAHALF || bt == RDKit::Bond::AROMATIC || aromatic); - else if (lbt == DOUBLE) + } else if (lbt == DOUBLE) { return (bt == RDKit::Bond::DOUBLE || bt == RDKit::Bond::TWOANDAHALF || bt == RDKit::Bond::AROMATIC || aromatic); - else if (lbt == TRIPLE) + } else if (lbt == TRIPLE) { return (bt == RDKit::Bond::TRIPLE || bt == RDKit::Bond::THREEANDAHALF || bt == RDKit::Bond::AROMATIC); - else + } else { return false; + } } static bool RecMatchNeigh(std::vector &matched_pairs, @@ -307,7 +326,9 @@ static bool RecMatchNeigh(std::vector &matched_pairs, visited[i] = true; std::vector &pairs = matched_pairs[i].Atoms; for (unsigned int pair : pairs) { - if (used[pair]) continue; + if (used[pair]) { + continue; + } used[pair] = true; if (RecMatchNeigh(matched_pairs, visited, used)) { return true; @@ -316,10 +337,16 @@ static bool RecMatchNeigh(std::vector &matched_pairs, } visited[i] = false; } - for (auto &&j : visited) - if (!j) return false; - for (auto &&j : used) - if (!j) return false; + for (auto &&j : visited) { + if (!j) { + return false; + } + } + for (auto &&j : used) { + if (!j) { + return false; + } + } return true; } @@ -343,16 +370,23 @@ bool RecMatch(const ROMol &mol, unsigned atomIdx, const AugmentedAtom &aa, const Ligand &au_ligand = aa.Ligands[j]; if (au_ligand.Charge != ANY_CHARGE && - atom.getFormalCharge() != au_ligand.Charge) + atom.getFormalCharge() != au_ligand.Charge) { continue; + } if (au_ligand.Radical != ANY_RADICAL && - atom.getNumRadicalElectrons() != au_ligand.Radical) + atom.getNumRadicalElectrons() != au_ligand.Radical) { continue; + } if (au_ligand.SubstitutionCount != 0 && - nbp[nbph.Atoms[i]].Atoms.size() != au_ligand.SubstitutionCount) + nbp[nbph.Atoms[i]].Atoms.size() != au_ligand.SubstitutionCount) { continue; - if (!isBondTypeMatch(bond, au_ligand.BondType)) continue; - if (!AtomSymbolMatch(atom.getSymbol(), au_ligand.AtomSymbol)) continue; + } + if (!isBondTypeMatch(bond, au_ligand.BondType)) { + continue; + } + if (!AtomSymbolMatch(atom.getSymbol(), au_ligand.AtomSymbol)) { + continue; + } // found matched item: found = true; matched_pairs[i].Atoms.push_back(j); @@ -365,12 +399,17 @@ bool RecMatch(const ROMol &mol, unsigned atomIdx, const AugmentedAtom &aa, std::vector visited(nbph.Atoms.size()); std::vector used(aa.Ligands.size()); - for (auto &&j : visited) j = false; - for (auto &&j : used) j = false; + for (auto &&j : visited) { + j = false; + } + for (auto &&j : used) { + j = false; + } if (RecMatchNeigh(matched_pairs, visited, used)) { - if (verbose) + if (verbose) { BOOST_LOG(rdInfoLog) << "RecMatch ret TRUE " << aa.ShortName << "\n"; + } return true; } // if (verbose) @@ -481,9 +520,15 @@ static void RingState(const ROMol &mol, std::vector &atom_status, std::vector &bond_status) { atom_status.resize(mol.getNumAtoms()); bond_status.resize(mol.getNumBonds()); - for (unsigned int &i : atom_status) i = 0; - for (unsigned int &i : bond_status) i = 0; - if (mol.getNumBonds() == 0) return; + for (unsigned int &i : atom_status) { + i = 0; + } + for (unsigned int &i : bond_status) { + i = 0; + } + if (mol.getNumBonds() == 0) { + return; + } // for each bond compute amount of rings that contains the bond const RDKit::RingInfo &ringInfo = *mol.getRingInfo(); const VECT_INT_VECT &bondRings = ringInfo.bondRings(); @@ -492,12 +537,13 @@ static void RingState(const ROMol &mol, std::vector &atom_status, bond_status[i]++; } } - for (unsigned i = 0; i < bond_status.size(); i++) + for (unsigned i = 0; i < bond_status.size(); i++) { if (bond_status[i] > 0) { const Bond &bond = *mol.getBondWithIdx(i); atom_status[bond.getBeginAtomIdx()]++; atom_status[bond.getEndAtomIdx()]++; } + } } /* @@ -507,7 +553,9 @@ static void RingState(const ROMol &mol, std::vector &atom_status, */ bool CheckAtoms(const ROMol &mol, const std::vector &good_atoms, bool verbose) { - if (good_atoms.empty()) return true; + if (good_atoms.empty()) { + return true; + } std::vector neighbours(mol.getNumAtoms()); std::vector atom_status(mol.getNumAtoms()); std::vector bond_status(mol.getNumBonds()); @@ -540,19 +588,21 @@ bool CheckAtoms(const ROMol &mol, const std::vector &good_atoms, if (good_atoms[j].Topology == RING && 0 == atom_status[i]) { // DEBUG: if (verbose && // j >= 12 && j <= 21 && - mol.getAtomWithIdx(i)->getAtomicNum() == 6) // 'C' + mol.getAtomWithIdx(i)->getAtomicNum() == 6) { // 'C' BOOST_LOG(rdInfoLog) << "UNMATCHED ring state RING of atom idx=" << i << " " << mol.getAtomWithIdx(i)->getSymbol() << " status=" << atom_status[i] << "\n"; + } continue; } if (good_atoms[j].Topology == CHAIN && 0 != atom_status[i]) { // DEBUG: if (verbose && // j >= 12 && j <= 21 && - mol.getAtomWithIdx(i)->getAtomicNum() == 6) // 'C' + mol.getAtomWithIdx(i)->getAtomicNum() == 6) { // 'C' BOOST_LOG(rdInfoLog) << "UNMATCHED ring state CHAIN of atom idx=" << i << " " << mol.getAtomWithIdx(i)->getSymbol() << " status=" << atom_status[i] << "\n"; + } continue; } @@ -582,12 +632,13 @@ bool CheckAtoms(const ROMol &mol, const std::vector &good_atoms, // BOOST_LOG(rdInfoLog) << "AAMatch i=" << i << " j=" << j // << " ret FALSE\n"; } - if (verbose && nmatch == prevn) // UNMATCHED atom + if (verbose && nmatch == prevn) { // UNMATCHED atom BOOST_LOG(rdInfoLog) << "UNMATCHED atom idx=" << i << " " << mol.getAtomWithIdx(i)->getSymbol() << " status=" << atom_status[i] << " nmatch=" << nmatch << std::endl << LogNeighbourhood(mol, i, neighbours) << std::endl; + } if (verbose && j == good_atoms.size()) { // failed this atom .. log it BOOST_LOG(rdWarningLog) diff --git a/Code/GraphMol/StructChecker/ReCharge.cpp b/Code/GraphMol/StructChecker/ReCharge.cpp index 82e8dbf57..bfc7dea0b 100644 --- a/Code/GraphMol/StructChecker/ReCharge.cpp +++ b/Code/GraphMol/StructChecker/ReCharge.cpp @@ -52,23 +52,28 @@ bool AllCentersRefined(const ROMol &mol, std::vector &numbering) { if (parity == EVEN_PARITY || parity == ODD_PARITY) { // extraxt numbers of stereoligands nref = (unsigned)nbp.Atoms.size(); - for (unsigned j = 0; j < nref; j++) refnum[j] = numbering[nbp.Atoms[j]]; + for (unsigned j = 0; j < nref; j++) { + refnum[j] = numbering[nbp.Atoms[j]]; + } // sort ligands - for (unsigned j = nref; j > 0; j--) - for (unsigned k = j; k > 0; k--) + for (unsigned j = nref; j > 0; j--) { + for (unsigned k = j; k > 0; k--) { if (refnum[k] < refnum[k - 1]) { unsigned h = refnum[k]; refnum[k] = refnum[k - 1]; refnum[k - 1] = h; } + } + } // check if there is a duplicate - for (unsigned j = 1; j < nref; j++) + for (unsigned j = 1; j < nref; j++) { if (refnum[j] == refnum[j - 1]) { // sprintf(msg_buffer, "%10s unrefined parity at atom %d", // mp->name, i + 1); // AddMsgToList(msg_buffer); return false; } + } } } } @@ -106,8 +111,9 @@ bool ChargeFix::rechargeMolecule(unsigned &ndeprot, unsigned &nrefine) { // sprintf(msg_buffer, "pKa = %.2g", pKa_value); // AddMsgToList(msg_buffer); decrementMarkedCharges(); - } else + } else { break; + } ndeprot++; } @@ -115,14 +121,15 @@ bool ChargeFix::rechargeMolecule(unsigned &ndeprot, unsigned &nrefine) { nrefine++; //// ?? expl. H ?? numbering = TypeAlloc(mp->n_atoms, int); nacid = refineAcidicAtoms(numbering); - if (nacid == 1) + if (nacid == 1) { decrementMarkedCharges(); - else if (AllCentersRefined(Mol, numbering)) { - for (unsigned i = 0; i < Mol.getNumAtoms(); i++) // Select one mark + } else if (AllCentersRefined(Mol, numbering)) { + for (unsigned i = 0; i < Mol.getNumAtoms(); i++) { // Select one mark if (AtomColor[i] != 0 && nacid != 1) { nacid--; AtomColor[i] = 0; } + } decrementMarkedCharges(); } else { // sprintf(msg_buffer, "%10s: could not fix charges", @@ -142,13 +149,19 @@ bool ChargeFix::rechargeMolecule(unsigned &ndeprot, unsigned &nrefine) { void ChargeFix::resetColors() { BondColor.resize(Mol.getNumBonds()); AtomColor.resize(Mol.getNumAtoms()); - for (unsigned int &i : BondColor) i = 0; - for (unsigned int &i : AtomColor) i = 0; + for (unsigned int &i : BondColor) { + i = 0; + } + for (unsigned int &i : AtomColor) { + i = 0; + } } void ChargeFix::resetValues() { AtompKaValue.resize(Mol.getNumAtoms()); - for (unsigned i = 0; i < AtomColor.size(); i++) AtompKaValue[i] = 0.0; + for (unsigned i = 0; i < AtomColor.size(); i++) { + AtompKaValue[i] = 0.0; + } } /* @@ -182,7 +195,7 @@ bool ChargeFix::setpKaValues() { // Is atom acidic? bool found = false; const std::vector dummy_atom_ring_status; - for (const auto &AcidicAtom : Options.AcidicAtoms) + for (const auto &AcidicAtom : Options.AcidicAtoms) { if (AAMatch(Mol, i, AcidicAtom, dummy_atom_ring_status, neighbour_array, Options.Verbose)) { AtomColor[i]++; @@ -191,7 +204,10 @@ bool ChargeFix::setpKaValues() { found = true; break; } - if (!found) continue; // center not acidic -> goto next atom + } + if (!found) { + continue; // center not acidic -> goto next atom + } // if (charge_log && old_values[i] != 0.0) // Prints the header of an // atom prediction line. @@ -201,7 +217,7 @@ bool ChargeFix::setpKaValues() { // throw.. // add local charge increment - for (const auto &j : Options.ChargeIncTable) + for (const auto &j : Options.ChargeIncTable) { if (AtomSymbolMatch(ap->getSymbol(), j.AtomSymbol)) { AtompKaValue[i] += ap->getFormalCharge() * j.LocalInc; // if (charge_log && old_values[i] != 0 && ap->charge != @@ -210,9 +226,10 @@ bool ChargeFix::setpKaValues() { // fprintf(charge_log, "+%d*%c3", ap->charge, 'B' + j); break; } + } // add local atom acidity (atom_acidity_table) - for (const auto &j : Options.AtomAcidity) + for (const auto &j : Options.AtomAcidity) { if (AtomSymbolMatch(ap->getSymbol(), j.AtomSymbol)) { AtompKaValue[i] += j.LocalInc; // ip->LocalInc // if (charge_log && old_values[i] != 0) @@ -221,6 +238,7 @@ bool ChargeFix::setpKaValues() { // fprintf(charge_log, "+%c10", 'B' + j); break; } + } const Neighbourhood &nbp = neighbour_array[i]; // for all alpha neighbours for (unsigned j = 0; j < nbp.Atoms.size(); j++) { @@ -229,13 +247,14 @@ bool ChargeFix::setpKaValues() { const PathEntry *ppa = nullptr; // fetch alpha Path conductivity found = false; - for (const auto &k : Options.AlphaPathTable) + for (const auto &k : Options.AlphaPathTable) { if (AtomSymbolMatch(ap->getSymbol(), k.Path.AtomSymbol) && LigandMatches(aap, abp, k.Path.Ligands[0], false)) { ppa = &k; found = true; break; } + } if (!found) { // sprintf(msg_buffer, "%10s: no alpha Path for atom %d", mp->name, i + // 1); @@ -257,7 +276,7 @@ bool ChargeFix::setpKaValues() { // fetch alpha charge increment if (aap.getFormalCharge() != 0) { found = false; - for (const auto &k : Options.ChargeIncTable) + for (const auto &k : Options.ChargeIncTable) { if (AtomSymbolMatch(aap.getSymbol(), k.AtomSymbol)) { // if (charge_log && old_values[i] != 0) // fprintf(charge_log, "+%d*%c4", aap->charge, @@ -268,6 +287,7 @@ bool ChargeFix::setpKaValues() { found = true; break; } + } if (!found) { // sprintf(msg_buffer, "%10s: no alpha increment for atom %d", // mp->name, i + 1); @@ -279,7 +299,7 @@ bool ChargeFix::setpKaValues() { // fetch alpha acidity increment found = false; - for (const auto &k : Options.AtomAcidity) + for (const auto &k : Options.AtomAcidity) { if (AtomSymbolMatch(aap.getSymbol(), k.AtomSymbol)) { // if (charge_log && old_values[i] != 0) // fprintf(charge_log, "+%c16", 'B' + (ppa - @@ -294,6 +314,7 @@ bool ChargeFix::setpKaValues() { found = true; break; } + } if (!found) { // sprintf(msg_buffer, "%10s: no alpha increment for atom // %d", mp->name, i + 1); @@ -305,14 +326,16 @@ bool ChargeFix::setpKaValues() { // for all beta neighbours const Neighbourhood &nbph = neighbour_array[nbp.Atoms[j]]; for (unsigned k = 0; k < nbph.Atoms.size(); k++) { - if (nbph.Atoms[k] == i) continue; // no loop back + if (nbph.Atoms[k] == i) { + continue; // no loop back + } const Atom &bap = *Mol.getAtomWithIdx(nbph.Atoms[k]); // beta atom const Bond &bbp = *Mol.getBondWithIdx(nbph.Bonds[k]); // beta bond const PathEntry *ppb = nullptr; // fetch beta conductivity found = false; - for (const auto &l : Options.BetaPathTable) // ppb++ + for (const auto &l : Options.BetaPathTable) { // ppb++ if (AtomSymbolMatch(ap->getSymbol(), l.Path.AtomSymbol) && LigandMatches(aap, abp, ppb->Path.Ligands[0], false) && LigandMatches(bap, bbp, ppb->Path.Ligands[1], false)) { @@ -320,6 +343,7 @@ bool ChargeFix::setpKaValues() { found = true; break; } + } if (!found) { // sprintf(msg_buffer, "%10s: no beta increment for // atom %d", mp->name, i + 1); @@ -330,7 +354,7 @@ bool ChargeFix::setpKaValues() { // fetch beta acidity increment found = false; - for (const auto &l : Options.AtomAcidity) // ip++ + for (const auto &l : Options.AtomAcidity) { // ip++ if (AtomSymbolMatch(bap.getSymbol(), l.AtomSymbol)) { // if (charge_log && old_values[i] != 0) // fprintf(charge_log, "+%c20", (int)('B' + (ppb @@ -346,6 +370,7 @@ bool ChargeFix::setpKaValues() { found = true; break; } + } if (!found) { // sprintf(msg_buffer, "%10s: no beta increment for // atom %d", mp->name, i + 1); @@ -357,7 +382,7 @@ bool ChargeFix::setpKaValues() { // fetch beta charge increment if (bap.getFormalCharge() != 0) { found = false; - for (const auto &l : Options.ChargeIncTable) + for (const auto &l : Options.ChargeIncTable) { if (AtomSymbolMatch(bap.getSymbol(), l.AtomSymbol)) { // if (charge_log && old_values[i] != 0) // fprintf(charge_log, "+%d*%c5", @@ -367,6 +392,7 @@ bool ChargeFix::setpKaValues() { found = true; break; } + } if (!found) { // sprintf(msg_buffer, "%10s: no beta // increment for atom %d", mp->name, i + 1); @@ -402,19 +428,22 @@ int ChargeFix::markMostAcidicAtoms(double &pKa_value, double &gap) { unsigned na = Mol.getNumAtoms(); for (unsigned i = 0; i < na; i++) { - if (AtomColor[i] != 0 && AtompKaValue[i] < min_pKa) + if (AtomColor[i] != 0 && AtompKaValue[i] < min_pKa) { min_pKa = AtompKaValue[i]; + } } - for (unsigned i = 0; i < na; i++) + for (unsigned i = 0; i < na; i++) { if (AtomColor[i] != 0 && AtompKaValue[i] < min_pKa + epsilon) { result++; AtomColor[i] = 1; } else { - if (AtomColor[i] != 0 && AtompKaValue[i] < next_pKa) + if (AtomColor[i] != 0 && AtompKaValue[i] < next_pKa) { next_pKa = AtompKaValue[i]; + } AtomColor[i] = 0; AtompKaValue[i] = 0.; } + } pKa_value = min_pKa; gap = next_pKa - min_pKa; @@ -425,10 +454,12 @@ int ChargeFix::markMostAcidicAtoms(double &pKa_value, double &gap) { * Decrements the charges of all marked atoms. */ void ChargeFix::decrementMarkedCharges() { - for (unsigned i = 0; i < Mol.getNumAtoms(); i++) - if (0 != AtomColor[i]) + for (unsigned i = 0; i < Mol.getNumAtoms(); i++) { + if (0 != AtomColor[i]) { Mol.getAtomWithIdx(i)->setFormalCharge( Mol.getAtomWithIdx(i)->getFormalCharge() - 1); + } + } } struct atom_rank_t { @@ -457,41 +488,52 @@ int ChargeFix::refineAcidicAtoms(std::vector &numbering) { atom_ranks[i].rank = 0; atom_ranks[i].rank_sum = 0; auto elneg = Options.ElnegTable.find(Mol.getAtomWithIdx(i)->getAtomicNum()); - if (Options.ElnegTable.end() != elneg) + if (Options.ElnegTable.end() != elneg) { atom_ranks[i].elneg = elneg->second + 3.0 * Mol.getAtomWithIdx(i)->getFormalCharge() - Options.Elneg0; // elneg_table[0].value; - else { + } else { // fprintf(stderr, "atom symbol '%s' not in periodic table\n", // mp->atom_array[i].AtomSymbol); return -1; } } // do preliminary ranking based on el. neg. - for (unsigned i = 1; i < atom_ranks.size(); i++) // sort by decreasing elneg. - for (unsigned j = i; j > 0; j--) + for (unsigned i = 1; i < atom_ranks.size(); + i++) { // sort by decreasing elneg. + for (unsigned j = i; j > 0; j--) { if (atom_ranks[j].elneg > atom_ranks[j - 1].elneg + epsilon) { ar_tmp = atom_ranks[j]; atom_ranks[j] = atom_ranks[j - 1]; atom_ranks[j - 1] = ar_tmp; - } else + } else { break; + } + } + } atom_ranks[0].rank = 0; // set ranks for (unsigned i = 1, j = 0; i < atom_ranks.size(); i++) { - if (atom_ranks[i].elneg < atom_ranks[i - 1].elneg - epsilon) j = i; + if (atom_ranks[i].elneg < atom_ranks[i - 1].elneg - epsilon) { + j = i; + } atom_ranks[i].rank = j; } - for (unsigned i = 1; i < atom_ranks.size(); i++) // resort by atom number - for (unsigned j = i; j > 0; j--) + for (unsigned i = 1; i < atom_ranks.size(); i++) { // resort by atom number + for (unsigned j = i; j > 0; j--) { if (atom_ranks[j].atom < atom_ranks[j - 1].atom) { ar_tmp = atom_ranks[j]; atom_ranks[j] = atom_ranks[j - 1]; atom_ranks[j - 1] = ar_tmp; - } else + } else { break; + } + } + } // use unsaturation to split ranks (rank sum is misused here) - for (auto &atom_rank : atom_ranks) atom_rank.rank_sum = 0; + for (auto &atom_rank : atom_ranks) { + atom_rank.rank_sum = 0; + } for (unsigned i = 0; i < Mol.getNumBonds(); i++) { const Bond &bond = *Mol.getBondWithIdx(i); if (convertBondType(bond.getBondType()) != SINGLE) { @@ -500,32 +542,42 @@ int ChargeFix::refineAcidicAtoms(std::vector &numbering) { } } for (unsigned i = 1; i < atom_ranks.size(); - i++) // sort by rank(asc.) + unsat.(desc.) - for (unsigned j = i; j > 0; j--) + i++) { // sort by rank(asc.) + unsat.(desc.) + for (unsigned j = i; j > 0; j--) { if (atom_ranks[j].rank < atom_ranks[j - 1].rank || (atom_ranks[j].rank == atom_ranks[j - 1].rank && atom_ranks[j].rank_sum > atom_ranks[j - 1].rank_sum)) { ar_tmp = atom_ranks[j]; atom_ranks[j] = atom_ranks[j - 1]; atom_ranks[j - 1] = ar_tmp; - } else + } else { break; + } + } + } for (unsigned i = 1, j = 0; i < atom_ranks.size(); i++) { // set new ranks if (atom_ranks[i].rank > atom_ranks[i - 1].rank || - atom_ranks[i].rank_sum < atom_ranks[i - 1].rank_sum) + atom_ranks[i].rank_sum < atom_ranks[i - 1].rank_sum) { j = i; + } atom_ranks[i].rank = j; } - for (unsigned i = 1; i < atom_ranks.size(); i++) // restore atom number order - for (unsigned j = i; j > 0; j--) + for (unsigned i = 1; i < atom_ranks.size(); + i++) { // restore atom number order + for (unsigned j = i; j > 0; j--) { if (atom_ranks[j].atom < atom_ranks[j - 1].atom) { ar_tmp = atom_ranks[j]; atom_ranks[j] = atom_ranks[j - 1]; atom_ranks[j - 1] = ar_tmp; - } else + } else { break; + } + } + } - for (auto &atom_rank : atom_ranks) atom_rank.n_ligands = 0; + for (auto &atom_rank : atom_ranks) { + atom_rank.n_ligands = 0; + } for (unsigned i = 0; i < Mol.getNumBonds(); i++) { const Bond &bond = *Mol.getBondWithIdx(i); atom_ranks[bond.getBeginAtomIdx()].n_ligands++; @@ -535,10 +587,13 @@ int ChargeFix::refineAcidicAtoms(std::vector &numbering) { // refine ranking using neighbour rank sums do_cis_trans = false; do { - for (unsigned i = 0; i < atom_ranks.size(); i++) + for (unsigned i = 0; i < atom_ranks.size(); i++) { numbering[i] = atom_ranks[i].rank; + } // compute rank sums - for (auto &atom_rank : atom_ranks) atom_rank.rank_sum = 0; + for (auto &atom_rank : atom_ranks) { + atom_rank.rank_sum = 0; + } for (unsigned i = 0; i < Mol.getNumBonds(); i++) { const Bond &bond = *Mol.getBondWithIdx(i); atom_ranks[bond.getBeginAtomIdx()].rank_sum += @@ -548,8 +603,9 @@ int ChargeFix::refineAcidicAtoms(std::vector &numbering) { } if (do_cis_trans) { std::vector atomPoint; - if (getMolAtomPoints(Mol, atomPoint)) + if (getMolAtomPoints(Mol, atomPoint)) { CisTransPerception(Mol, atomPoint, numbering, BondColor); + } for (unsigned i = 0; i < BondColor.size(); i++) { const Bond &bond = *Mol.getBondWithIdx(i); @@ -559,51 +615,63 @@ int ChargeFix::refineAcidicAtoms(std::vector &numbering) { } } } - for (auto &atom_rank : atom_ranks) // use average rank sum + for (auto &atom_rank : atom_ranks) { // use average rank sum if (atom_rank.n_ligands > 0) { atom_rank.rank_sum *= 10; // shift dec. point atom_rank.rank_sum /= atom_rank.n_ligands; } - for (unsigned i = 1; i < atom_ranks.size(); i++) // sort by rank + ranksum - for (unsigned j = i; j > 0; j--) + } + for (unsigned i = 1; i < atom_ranks.size(); + i++) { // sort by rank + ranksum + for (unsigned j = i; j > 0; j--) { if (atom_ranks[j].rank < atom_ranks[j - 1].rank || (atom_ranks[j].rank == atom_ranks[j - 1].rank && atom_ranks[j].rank_sum < atom_ranks[j - 1].rank_sum)) { ar_tmp = atom_ranks[j]; atom_ranks[j] = atom_ranks[j - 1]; atom_ranks[j - 1] = ar_tmp; - } else + } else { break; + } + } + } // compute new ranks changed = false; for (unsigned i = 1, j = 0; i < atom_ranks.size(); i++) { if (atom_ranks[i].rank > atom_ranks[i - 1].rank || - atom_ranks[i].rank_sum > atom_ranks[i - 1].rank_sum) + atom_ranks[i].rank_sum > atom_ranks[i - 1].rank_sum) { j = i; + } changed = changed || atom_ranks[i].rank != j; atom_ranks[i].rank = j; } for (unsigned i = 1; i < atom_ranks.size(); - i++) // restore atom number order - for (unsigned j = i; j > 0; j--) + i++) { // restore atom number order + for (unsigned j = i; j > 0; j--) { if (atom_ranks[j].atom < atom_ranks[j - 1].atom) { ar_tmp = atom_ranks[j]; atom_ranks[j] = atom_ranks[j - 1]; atom_ranks[j - 1] = ar_tmp; - } else + } else { break; + } + } + } if (!changed && !do_cis_trans) { do_cis_trans = true; changed = true; - } else + } else { do_cis_trans = false; + } } while (changed); // find smalles rank of coloured atoms size_t min_rank = atom_ranks.size(); - for (unsigned i = 0; i < atom_ranks.size(); i++) - if (AtomColor[i] != 0 && atom_ranks[i].rank < min_rank) + for (unsigned i = 0; i < atom_ranks.size(); i++) { + if (AtomColor[i] != 0 && atom_ranks[i].rank < min_rank) { min_rank = atom_ranks[i].rank; + } + } for (unsigned i = 0; i < atom_ranks.size(); i++) { if (AtomColor[i] != 0 && atom_ranks[i].rank == min_rank) { // count members of minimum class @@ -615,12 +683,13 @@ int ChargeFix::refineAcidicAtoms(std::vector &numbering) { } } if (result > 1) { - for (unsigned int i : AtomColor) + for (unsigned int i : AtomColor) { if (i != 0) { // sprintf(msg_buffer, "atom %d in minimal rank class", i // + 1); // AddMsgToList(msg_buffer); } + } } return result; } diff --git a/Code/GraphMol/StructChecker/Stereo.cpp b/Code/GraphMol/StructChecker/Stereo.cpp index 573b50fef..b5a73bf40 100644 --- a/Code/GraphMol/StructChecker/Stereo.cpp +++ b/Code/GraphMol/StructChecker/Stereo.cpp @@ -41,17 +41,22 @@ static double Angle(double x1, double y1, double x2, double y2) { l1 = sqrt(x1 * x1 + y1 * y1); l2 = sqrt(x2 * x2 + y2 * y2); - if (l1 < 0.00001 || l2 < 0.00001) return (0.0); + if (l1 < 0.00001 || l2 < 0.00001) { + return (0.0); + } cos_alpha = (x1 * x2 + y1 * y2) / (l1 * l2); - if (cos_alpha > 1.0) // safeguard against round off errors + if (cos_alpha > 1.0) { // safeguard against round off errors cos_alpha = 1.0; - else if (cos_alpha < -1.0) + } else if (cos_alpha < -1.0) { cos_alpha = -1.0; + } sin_alpha = (x1 * y2 - x2 * y1) / (l1 * l2); result = acos(cos_alpha); - if (sin_alpha < 0.0) result = 2 * PI - result; + if (sin_alpha < 0.0) { + result = 2 * PI - result; + } return result; } @@ -110,11 +115,15 @@ int DubiousStereochemistry(RWMol &mol) { nmulti++; if (RDKit::Bond::DOUBLE == bond.getBondType()) { unsigned jatom = nbp.Atoms[j]; - for (unsigned int jj : neighbour_array[jatom].Bonds) - if (RDKit::Bond::DOUBLE == mol.getBondWithIdx(jj)->getBondType()) + for (unsigned int jj : neighbour_array[jatom].Bonds) { + if (RDKit::Bond::DOUBLE == mol.getBondWithIdx(jj)->getBondType()) { ndb++; + } + } + } + if (2 == ndb) { + is_allene = true; } - if (2 == ndb) is_allene = true; } } unsigned element = mol.getAtomWithIdx(i)->getAtomicNum(); @@ -132,8 +141,7 @@ int DubiousStereochemistry(RWMol &mol) { n_ligands > 2 && n_ligands <= 4) || ((14 == element && // "Si" n_ligands > 2 && n_ligands <= 4) && - nmulti == 0))) - + nmulti == 0))) { for (unsigned j = 0; j < n_ligands; j++) { const Bond &bj = *mol.getBondWithIdx(nbp.Bonds[j]); if (bj.getBeginAtomIdx() == i && @@ -148,6 +156,7 @@ int DubiousStereochemistry(RWMol &mol) { result |= STEREO_BOND_AT_NON_STEREO_ATOM; } } + } } return result; } @@ -172,8 +181,9 @@ int FixDubious3DMolecule(RWMol &mol) { non_zero_z = getMolAtomPoints(mol, atomPoint); // At first check if this is a trivial case i.e. designated '2D' // and count the number of stereo bonds - if (!non_zero_z) // check Z coordinate of each atom + if (!non_zero_z) { // check Z coordinate of each atom return 0; + } nstereo = 0; for (unsigned i = 0; i < mol.getNumBonds(); i++) { @@ -181,10 +191,13 @@ int FixDubious3DMolecule(RWMol &mol) { if (RDKit::Bond::BEGINWEDGE == bond->getBondDir() || RDKit::Bond::BEGINDASH == bond->getBondDir() //??? || RDKit::Bond::EITHERDOUBLE == bond->getBondDir() - ) + ) { nstereo++; + } + } + if (0 == nstereo) { + return 0; } - if (0 == nstereo) return 0; // compute average bond length to use in Volume significance testing double length = 0.0; @@ -206,24 +219,30 @@ int FixDubious3DMolecule(RWMol &mol) { SetupNeighbourhood(mol, neighbour_array); int nflat_sp3 = 0; for (unsigned i = 0; i < neighbour_array.size(); i++) { - if (neighbour_array[i].Atoms.size() < 3) continue; + if (neighbour_array[i].Atoms.size() < 3) { + continue; + } RDKit::Atom *atom = mol.getAtomWithIdx(i); unsigned element = atom->getAtomicNum(); if (6 != element && // "C" 7 == element && // "N" 15 == element && // "P" - 16 == element) // "S" + 16 == element) { // "S" continue; + } unsigned j; for (j = 0; j < mol.getNumBonds(); j++) { const Bond *bond = mol.getBondWithIdx(j); if (RDKit::Bond::BEGINWEDGE == bond->getBondDir() || (RDKit::Bond::BEGINDASH == bond->getBondDir() && - i == bond->getBeginAtomIdx())) + i == bond->getBeginAtomIdx())) { break; + } + } + if (j < mol.getNumBonds()) { + continue; // no stereo designation } - if (j < mol.getNumBonds()) continue; // no stereo designation double vol = 0.0; int stereo_triple; @@ -234,12 +253,16 @@ int FixDubious3DMolecule(RWMol &mol) { tetra[0].x = atomPoint[i].x; tetra[0].y = atomPoint[i].y; tetra[0].z = atomPoint[i].z; - for (i1 = 0; i1 < n_ligands; i1++) + for (i1 = 0; i1 < n_ligands; i1++) { if (mol.getBondWithIdx(nbp.Bonds[i1])->getBondType() != RDKit::Bond::SINGLE && - 16 != element && 15 != element) // "S" "P" + 16 != element && 15 != element) { // "S" "P" break; - if (i1 >= n_ligands) continue; // multiple bond found => no sp3 carbon + } + } + if (i1 >= n_ligands) { + continue; // multiple bond found => no sp3 carbon + } stereo_triple = 0; for (i1 = 0; i1 < n_ligands; i1++) { tetra[1].x = atomPoint[i1].x; @@ -248,8 +271,9 @@ int FixDubious3DMolecule(RWMol &mol) { if (mol.getBondWithIdx(nbp.Bonds[i1])->getBondDir() == RDKit::Bond::BEGINWEDGE || mol.getBondWithIdx(nbp.Bonds[i1])->getBondDir() == - RDKit::Bond::BEGINDASH) // UP DOWN + RDKit::Bond::BEGINDASH) { // UP DOWN stereo_triple |= 1; + } unsigned i2; for (i2 = i1 + 1; i2 < n_ligands; i2++) { tetra[2].x = atomPoint[i2].x; @@ -258,8 +282,9 @@ int FixDubious3DMolecule(RWMol &mol) { if (mol.getBondWithIdx(nbp.Bonds[i2])->getBondDir() == RDKit::Bond::BEGINWEDGE || mol.getBondWithIdx(nbp.Bonds[i2])->getBondDir() == - RDKit::Bond::BEGINDASH) // UP DOWN + RDKit::Bond::BEGINDASH) { // UP DOWN stereo_triple |= 2; + } unsigned i3; for (i3 = i2 + 1; i3 < n_ligands; i3++) { tetra[3].x = atomPoint[i3].x; @@ -268,11 +293,16 @@ int FixDubious3DMolecule(RWMol &mol) { if (mol.getBondWithIdx(nbp.Bonds[i3])->getBondDir() == RDKit::Bond::BEGINWEDGE || mol.getBondWithIdx(nbp.Bonds[i3])->getBondDir() == - RDKit::Bond::BEGINDASH) // UP DOWN + RDKit::Bond::BEGINDASH) { // UP DOWN stereo_triple |= 4; + } vol = Volume(tetra); - if (vol < 0.) vol = -vol; - if (!stereo_triple) continue; + if (vol < 0.) { + vol = -vol; + } + if (!stereo_triple) { + continue; + } if (vol < 0.01 * length * length * length) { nflat_sp3++; break; @@ -280,17 +310,23 @@ int FixDubious3DMolecule(RWMol &mol) { stereo_triple &= ~4; } stereo_triple &= ~2; - if (i3 >= n_ligands) break; + if (i3 >= n_ligands) { + break; + } } stereo_triple &= ~1; - if (i2 >= n_ligands) break; + if (i2 >= n_ligands) { + break; + } } } - if (non_zero_z && 0 == mol.getConformer().is3D()) // && mol dim is 2D - for (unsigned i = 0; i < mol.getNumAtoms(); i++) + if (non_zero_z && 0 == mol.getConformer().is3D()) { // && mol dim is 2D + for (unsigned i = 0; i < mol.getNumAtoms(); i++) { // TODO: ??? atomPoint[i].z = 0.0; // set in mol !!! + } + } result |= ZEROED_Z_COORDINATES; // Cleared z-coordinates in 2D MOL file if (non_zero_z && nstereo > 0 && nflat_sp3 > 0) { @@ -308,8 +344,9 @@ void RemoveDubiousStereochemistry(RWMol &mol) { // remove EITHER marks for (unsigned i = 0; i < mol.getNumBonds(); i++) { Bond *bond = mol.getBondWithIdx(i); - if (RDKit::Bond::UNKNOWN == bond->getBondDir()) //== EITHER + if (RDKit::Bond::UNKNOWN == bond->getBondDir()) { //== EITHER bond->setBondDir(RDKit::Bond::NONE); + } } // remove stereo marks to non-stereogenic atoms for (unsigned i = 0; i < neighbour_array.size(); i++) { @@ -317,7 +354,9 @@ void RemoveDubiousStereochemistry(RWMol &mol) { unsigned nmulti = 0; for (unsigned j = 0; j < nbp.Atoms.size(); j++) { const Bond &bond = *mol.getBondWithIdx(nbp.Bonds[j]); - if (RDKit::Bond::SINGLE != bond.getBondType()) nmulti++; + if (RDKit::Bond::SINGLE != bond.getBondType()) { + nmulti++; + } } unsigned element = mol.getAtomWithIdx(i)->getAtomicNum(); @@ -336,9 +375,10 @@ void RemoveDubiousStereochemistry(RWMol &mol) { for (unsigned j = 0; j < n_ligands; j++) { Bond &bj = *mol.getBondWithIdx(nbp.Bonds[j]); if (bj.getBeginAtomIdx() == i && - (RDKit::Bond::BEGINWEDGE == bj.getBondDir() // == UP - || RDKit::Bond::BEGINDASH == bj.getBondDir())) // == DOWN)) + (RDKit::Bond::BEGINWEDGE == bj.getBondDir() // == UP + || RDKit::Bond::BEGINDASH == bj.getBondDir())) { // == DOWN)) bj.setBondDir(RDKit::Bond::NONE); + } } } } @@ -366,7 +406,9 @@ static int Atom3Parity(struct stereo_bond_t ligands[3]) { maxnum = ligands[0].number; for (unsigned i = 1; i < 3; i++) { - if (maxnum < ligands[i].number) maxnum = ligands[i].number; + if (maxnum < ligands[i].number) { + maxnum = ligands[i].number; + } } reference = (-1); @@ -414,13 +456,13 @@ static int Atom3Parity(struct stereo_bond_t ligands[3]) { for (unsigned i = 0; i < 3; i++) { tetrahedron[i + 1].x = ligands[i].x; tetrahedron[i + 1].y = ligands[i].y; - if (ligands[i].direction == RDKit::Bond::BEGINWEDGE) // UP) + if (ligands[i].direction == RDKit::Bond::BEGINWEDGE) { // UP) tetrahedron[i + 1].z = 1.0; - else if (ligands[i].direction == RDKit::Bond::BEGINDASH) // DOWN) + } else if (ligands[i].direction == RDKit::Bond::BEGINDASH) { // DOWN) tetrahedron[i + 1].z = -1.0; - else if (ligands[i].direction == RDKit::Bond::NONE) + } else if (ligands[i].direction == RDKit::Bond::NONE) { tetrahedron[i + 1].z = 0.0; - else { + } else { // stereo_error = "three attachments: illegal bond symbol"; std::cerr << "three attachments illegal bond symbol" << std::endl; return (ILLEGAL_REPRESENTATION); @@ -428,14 +470,17 @@ static int Atom3Parity(struct stereo_bond_t ligands[3]) { tetrahedron[i + 1].number = ligands[i].number; } - for (unsigned i = 1; i < 4; i++) - for (unsigned j = i; j > 0; j--) + for (unsigned i = 1; i < 4; i++) { + for (unsigned j = i; j > 0; j--) { if (tetrahedron[j].number < tetrahedron[j - 1].number) { h = tetrahedron[j]; tetrahedron[j] = tetrahedron[j - 1]; tetrahedron[j - 1] = h; - } else + } else { break; + } + } + } return (Volume(tetrahedron) > 0.0 ? EVEN_PARITY : ODD_PARITY); } @@ -469,7 +514,9 @@ static int Atom4Parity(struct stereo_bond_t ligands[4]) { } } - if (nup == 0 && ndown == 0) return (UNDEFINED_PARITY); + if (nup == 0 && ndown == 0) { + return (UNDEFINED_PARITY); + } if (nup > 2 || ndown > 2) { // stereo_error = "too many stereobonds"; @@ -480,16 +527,21 @@ static int Atom4Parity(struct stereo_bond_t ligands[4]) { if (nup + ndown == 1) // check for 'umbrellas' { unsigned ij; - for (ij = 0; ij < 4; ij++) + for (ij = 0; ij < 4; ij++) { if (ligands[ij].direction == RDKit::Bond::BEGINWEDGE || - ligands[ij].direction == RDKit::Bond::BEGINDASH) + ligands[ij].direction == RDKit::Bond::BEGINDASH) { break; + } + } nopposite = 0; - for (unsigned j = 0; j < 4; j++) - if (ij == j) + for (unsigned j = 0; j < 4; j++) { + if (ij == j) { continue; - else if (ligands[ij].x * ligands[j].x + ligands[ij].y * ligands[j].y < 0) + } else if (ligands[ij].x * ligands[j].x + ligands[ij].y * ligands[j].y < + 0) { nopposite++; + } + } if (nopposite > 2) { // stereo_error = "UMBRELLA: all non-stereo bonds opposite to single // stereo bond"; @@ -498,7 +550,7 @@ static int Atom4Parity(struct stereo_bond_t ligands[4]) { } } - for (unsigned i = 0; i < 2; i++) + for (unsigned i = 0; i < 2; i++) { if ((ligands[i].direction == RDKit::Bond::BEGINWEDGE && ligands[i + 2].direction == RDKit::Bond::BEGINDASH) || (ligands[i].direction == RDKit::Bond::BEGINDASH && @@ -507,8 +559,9 @@ static int Atom4Parity(struct stereo_bond_t ligands[4]) { std::cerr << "up/down" << std::endl; return (ILLEGAL_REPRESENTATION); } + } - for (unsigned i = 0; i < 4; i++) + for (unsigned i = 0; i < 4; i++) { if ((ligands[i].direction == RDKit::Bond::BEGINWEDGE && ligands[(i + 1) % 4].direction == RDKit::Bond::BEGINWEDGE) // UP || (ligands[i].direction == RDKit::Bond::BEGINDASH // DOWN @@ -517,8 +570,9 @@ static int Atom4Parity(struct stereo_bond_t ligands[4]) { std::cerr << "adjacent like" << std::endl; return (ILLEGAL_REPRESENTATION); } + } - for (unsigned i = 0; i < 4; i++) + for (unsigned i = 0; i < 4; i++) { if (ligands[i].direction == RDKit::Bond::NONE && ligands[(i + 1) % 4].direction == RDKit::Bond::NONE && ligands[(i + 2) % 4].direction == RDKit::Bond::NONE) { @@ -532,15 +586,19 @@ static int Atom4Parity(struct stereo_bond_t ligands[4]) { return (ILLEGAL_REPRESENTATION); } } + } - for (unsigned i = 1; i < 4; i++) - for (unsigned j = i; j > 0; j--) + for (unsigned i = 1; i < 4; i++) { + for (unsigned j = i; j > 0; j--) { if (tetrahedron[j].number < tetrahedron[j - 1].number) { h = tetrahedron[j]; tetrahedron[j] = tetrahedron[j - 1]; tetrahedron[j - 1] = h; - } else + } else { break; + } + } + } return (Volume(tetrahedron) > 0.0 ? EVEN_PARITY : ODD_PARITY); } @@ -554,8 +612,9 @@ int AtomParity(const ROMol &mol, unsigned iatom, const Neighbourhood &nbp) { struct stereo_bond_t stereo_ligands[4], h; bool multiple = false, allene = false, stereo = false; - if (nbp.Atoms.size() < 3 || nbp.Atoms.size() > 4) + if (nbp.Atoms.size() < 3 || nbp.Atoms.size() > 4) { return ILLEGAL_REPRESENTATION; + } std::vector atomPoint( mol.getNumAtoms()); // X,Y,Z coordinates of each atom @@ -570,10 +629,15 @@ int AtomParity(const ROMol &mol, unsigned iatom, const Neighbourhood &nbp) { unsigned ndb = 0; for (unsigned j = 0; j < mol.getNumBonds(); j++) { const Bond &bond = *mol.getBondWithIdx(j); - if (bond.getBeginAtomIdx() == jatom || bond.getEndAtomIdx() == jatom) - if (bond.getBondType() == RDKit::Bond::DOUBLE) ndb++; + if (bond.getBeginAtomIdx() == jatom || bond.getEndAtomIdx() == jatom) { + if (bond.getBondType() == RDKit::Bond::DOUBLE) { + ndb++; + } + } + } + if (ndb == 2) { + allene = true; } - if (ndb == 2) allene = true; } stereo_ligands[i].x = atomPoint[i].x - atomPoint[iatom].x; @@ -582,35 +646,42 @@ int AtomParity(const ROMol &mol, unsigned iatom, const Neighbourhood &nbp) { if (bi.getBeginAtomIdx() == iatom) { stereo_ligands[i].direction = bi.getBondDir(); if (stereo_ligands[i].direction == RDKit::Bond::BEGINWEDGE || // UP || - stereo_ligands[i].direction == RDKit::Bond::BEGINDASH) // DOWN + stereo_ligands[i].direction == RDKit::Bond::BEGINDASH) { // DOWN stereo = true; - } else + } + } else { stereo_ligands[i].direction = RDKit::Bond::NONE; + } } unsigned element = mol.getAtomWithIdx(iatom)->getAtomicNum(); if (multiple && stereo && 15 != element && 16 != element) { // "P" && "S" - if (allene) + if (allene) { return (ALLENE_PARITY); - else { + } else { // stereo_error = "AtomParity: Stereobond at unsaturated atom"; std::cerr << "stereobond at unsaturated atom" << std::endl; return (ILLEGAL_REPRESENTATION); } - } else if (multiple && 16 != element) // "S" + } else if (multiple && 16 != element) { // "S" return (UNDEFINED_PARITY); + } stereo_ligands[0].angle = 0.0; /* comp. angle rel. to first ligand */ - for (unsigned i = 1; i < nbp.Atoms.size(); i++) + for (unsigned i = 1; i < nbp.Atoms.size(); i++) { stereo_ligands[i].angle = Angle(stereo_ligands[0].x, stereo_ligands[0].y, stereo_ligands[i].x, stereo_ligands[i].y); - for (unsigned i = 2; i < nbp.Atoms.size(); i++) /* sort ligands */ - for (unsigned j = i; j > 1; j--) + } + for (unsigned i = 2; i < nbp.Atoms.size(); i++) { /* sort ligands */ + for (unsigned j = i; j > 1; j--) { if (stereo_ligands[j].angle < stereo_ligands[j - 1].angle) { h = stereo_ligands[j]; stereo_ligands[j] = stereo_ligands[j - 1]; stereo_ligands[j - 1] = h; - } else + } else { break; + } + } + } return (nbp.Atoms.size() == 3 ? Atom3Parity(stereo_ligands) : Atom4Parity(stereo_ligands)); @@ -643,8 +714,9 @@ bool CheckStereo(const ROMol &mol) { const Atom *atom = mol.getAtomWithIdx(i); if (atom->getChiralTag() == Atom::CHI_TETRAHEDRAL_CW || - atom->getChiralTag() == Atom::CHI_TETRAHEDRAL_CCW) + atom->getChiralTag() == Atom::CHI_TETRAHEDRAL_CCW) { center_defined = true; + } if (parity == ILLEGAL_REPRESENTATION) { // stereo_error result = false; @@ -692,7 +764,9 @@ bool AtomClash(RWMol &mol, double clash_limit) { getMolAtomPoints(mol, atomPoint, twod); // compute median of square of bond length (quick/dirty) - if (mol.getNumBonds() == 0) return false; + if (mol.getNumBonds() == 0) { + return false; + } std::vector blengths(mol.getNumBonds()); blengths[0] = 1.0; @@ -711,15 +785,16 @@ bool AtomClash(RWMol &mol, double clash_limit) { h = blengths[j]; blengths[j] = blengths[j + 1]; blengths[j + 1] = h; - } else + } else { break; + } } } bond_square_median = blengths[mol.getNumBonds() / 2]; // Check if two atoms get too close to each other min_dist = bond_square_median; - for (unsigned i = 0; i < mol.getNumAtoms(); i++) + for (unsigned i = 0; i < mol.getNumAtoms(); i++) { for (unsigned j = i + 1; j < mol.getNumAtoms(); j++) { dist = (atomPoint[i].x - atomPoint[j].x) * @@ -730,8 +805,11 @@ bool AtomClash(RWMol &mol, double clash_limit) { return true; } - if (dist < min_dist) min_dist = dist; + if (dist < min_dist) { + min_dist = dist; + } } + } // check if atom lies on top of some bond for (unsigned i = 0; i < mol.getNumBonds(); i++) { @@ -739,7 +817,9 @@ bool AtomClash(RWMol &mol, double clash_limit) { unsigned a1 = bond->getBeginAtomIdx(); unsigned a2 = bond->getEndAtomIdx(); for (unsigned j = 0; j < mol.getNumAtoms(); j++) { - if (a1 == j || a2 == j) continue; + if (a1 == j || a2 == j) { + continue; + } rr = (atomPoint[j].x - atomPoint[a1].x) * (atomPoint[j].x - atomPoint[a1].x) + (atomPoint[j].y - atomPoint[a1].y) * @@ -784,11 +864,16 @@ int CisTransPerception(const ROMol &mol, std::vector nba(mol.getNumAtoms()); SetupNeighbourhood(mol, nba); - for (unsigned int &i : bondColor) i = 0; - for (unsigned i = 0; i < nba.size(); i++) // n_atoms - if (numbering[i] > maxnum) maxnum = numbering[i]; + for (unsigned int &i : bondColor) { + i = 0; + } + for (unsigned i = 0; i < nba.size(); i++) { // n_atoms + if (numbering[i] > maxnum) { + maxnum = numbering[i]; + } + } - for (unsigned i = 0; i < bondColor.size(); i++) + for (unsigned i = 0; i < bondColor.size(); i++) { if (RDKit::Bond::DOUBLE == mol.getBondWithIdx(i)->getBondType() // FIX: && mol.getBondWithIdx(i)->getBondDir() != // RDKit::Bond::ENDDOWNRIGHT @@ -798,49 +883,61 @@ int CisTransPerception(const ROMol &mol, RDKit::Bond::EITHERDOUBLE) { // != CIS_TRANS_EITHER unsigned j1 = mol.getBondWithIdx(i)->getBeginAtomIdx(); unsigned j2 = mol.getBondWithIdx(i)->getEndAtomIdx(); - if (6 != mol.getAtomWithIdx(j1)->getAtomicNum()) // C + if (6 != mol.getAtomWithIdx(j1)->getAtomicNum()) { // C continue; - if (16 != mol.getAtomWithIdx(j1)->getAtomicNum()) // N + } + if (16 != mol.getAtomWithIdx(j1)->getAtomicNum()) { // N continue; - if (6 != mol.getAtomWithIdx(j2)->getAtomicNum()) // C + } + if (6 != mol.getAtomWithIdx(j2)->getAtomicNum()) { // C continue; - if (16 != mol.getAtomWithIdx(j2)->getAtomicNum()) // N + } + if (16 != mol.getAtomWithIdx(j2)->getAtomicNum()) { // N continue; + } // n_ligands : if (nba[j1].Atoms.size() <= 1 || // no subst. - nba[j2].Atoms.size() <= 1) + nba[j2].Atoms.size() <= 1) { continue; + } if (nba[j1].Atoms.size() > 3 || // valence error in mol - nba[j2].Atoms.size() > 3) + nba[j2].Atoms.size() > 3) { continue; + } bool equal = false; // find lowest numbered neighbour of j1 unsigned at1 = 0; - for (unsigned k = 0, nmin = maxnum; k < nba[j1].Atoms.size(); k++) + for (unsigned k = 0, nmin = maxnum; k < nba[j1].Atoms.size(); k++) { if (nba[j1].Atoms[k] != j2) // no loop back { if (numbering[nba[j1].Atoms[k]] < nmin) { // numbering[nba[j1].atoms[k]] at1 = nba[j1].Atoms[k]; nmin = numbering[at1]; - } else if (numbering[nba[j1].Atoms[k]] == nmin) + } else if (numbering[nba[j1].Atoms[k]] == nmin) { equal = true; + } } - if (equal) // identical substituents - continue; // no stereochemistry + } + if (equal) { // identical substituents + continue; // no stereochemistry + } equal = false; // find lowest numbered neighbour of j1 unsigned at2 = 0; - for (unsigned k = 0, nmin = maxnum; k < nba[j2].Atoms.size(); k++) // + for (unsigned k = 0, nmin = maxnum; k < nba[j2].Atoms.size(); k++) { // if (nba[j2].Atoms[k] != j1) { // no loop back if (numbering[nba[j2].Atoms[k]] < nmin) { at2 = nba[j2].Atoms[k]; nmin = numbering[at2]; - } else if (numbering[nba[j2].Atoms[k]] == nmin) + } else if (numbering[nba[j2].Atoms[k]] == nmin) { equal = true; + } } - if (equal) // identical substituents - continue; // no stereochemistry + } + if (equal) { // identical substituents + continue; // no stereochemistry + } // Now, bp points to a double bond, at1 and at2 are the // indices (not numbers) of the atoms with lowest numbering @@ -861,10 +958,13 @@ int CisTransPerception(const ROMol &mol, x34 = points[at2].x - points[j2].x; y34 = points[at2].y - points[j2].y; sign = (x21 * y23 - x23 * y21) * (x32 * y34 - x34 * y32); - if (fabs(sign) < 0.001) continue; + if (fabs(sign) < 0.001) { + continue; + } result++; bondColor[i] = (sign > 0.0 ? CIS : TRANS); } + } return (result); } diff --git a/Code/GraphMol/StructChecker/StripSmallFragments.cpp b/Code/GraphMol/StructChecker/StripSmallFragments.cpp index 67261876a..34c18068a 100644 --- a/Code/GraphMol/StructChecker/StripSmallFragments.cpp +++ b/Code/GraphMol/StructChecker/StripSmallFragments.cpp @@ -30,7 +30,9 @@ void AddMWMF(RWMol &mol, double mass = 0.0; mass = RDKit::MolOps::getExactMolWt(mol); std::string formula = RDKit::MolOps::getMolFormula(mol); - if (!formula.empty()) mol.setProp((pre ? "MF_PRE" : "MF_POST"), formula); + if (!formula.empty()) { + mol.setProp((pre ? "MF_PRE" : "MF_POST"), formula); + } char propertyValue[64]; snprintf(propertyValue, sizeof(propertyValue), "%g", mass); mol.setProp((pre ? "MW_PRE" : "MW_POST"), mass); @@ -40,7 +42,9 @@ bool StripSmallFragments(RWMol &mol, bool verbose) { const bool sanitize = false; std::vector> frags = MolOps::getMolFrags(mol, sanitize); - if (frags.size() <= 1) return false; + if (frags.size() <= 1) { + return false; + } size_t maxFragSize = 0; size_t maxFragIdx = 0; diff --git a/Code/GraphMol/StructChecker/StructChecker.cpp b/Code/GraphMol/StructChecker/StructChecker.cpp index 118b86d68..026dd9147 100644 --- a/Code/GraphMol/StructChecker/StructChecker.cpp +++ b/Code/GraphMol/StructChecker/StructChecker.cpp @@ -31,7 +31,9 @@ unsigned StructChecker::checkMolStructure(RWMol &mol) const { return SIZE_CHECK_FAILED; } - if (!mol.getRingInfo()->isInitialized()) mol.getRingInfo()->initialize(); + if (!mol.getRingInfo()->isInitialized()) { + mol.getRingInfo()->initialize(); + } /* it uses SDL text if (Options.ConvertAtomTexts) @@ -68,27 +70,32 @@ unsigned StructChecker::checkMolStructure(RWMol &mol) const { AddMWMF(mol, true); // Add mol mass data field "MW_PRE" if (StripSmallFragments(mol, Options.Verbose)) { flags |= FRAGMENTS_FOUND; - if (Options.Verbose) + if (Options.Verbose) { BOOST_LOG(rdInfoLog) << "Striped SmallFragments" << MolToSmiles(mol) << "\n"; + } } AddMWMF(mol, false); // Add mol mass data field "MW_POST" } // do tautomer standardization for (unsigned i = 0; i < Options.FromTautomer.size(); i++) { - if (Options.Verbose) + if (Options.Verbose) { BOOST_LOG(rdInfoLog) << "tautomerizing with rule " << i << "\n"; + } // fprintf(stderr, "tautomerizing with rule %d\n", i); for (unsigned j = 0; j < 3; j++) // limit to 3 run per rule { StructCheckTautomer sct(mol, Options); - if (!sct.applyTautomer(i)) break; + if (!sct.applyTautomer(i)) { + break; + } flags |= TAUTOMER_TRANSFORMED; - if (Options.Verbose) + if (Options.Verbose) { BOOST_LOG(rdInfoLog) << "molecule: has been tautomerized with rule " << i << ":\n" << MolToSmiles(mol) << "\n"; + } // sprintf(msg_buffer,"%10s: has been tautomerized with // rule '%s'", mp->name, from_tautomer[i]->name); // AddMsgToList(msg_buffer); @@ -123,24 +130,30 @@ unsigned StructChecker::checkMolStructure(RWMol &mol) const { ChargeFix ch(Options, mol); if (ch.rechargeMolecule(ndeprot, nrefine)) { flags |= RECHARGED; - if (Options.Verbose) + if (Options.Verbose) { BOOST_LOG(rdInfoLog) << "Recharged Molecule:" << MolToSmiles(mol) << "\n"; + } } } // const double clashLimit = Options.CollisionLimitPercent / 100.0; if (Options.CheckCollisions && AtomClash(mol, clashLimit)) { flags |= ATOM_CLASH; - if (Options.Verbose) + if (Options.Verbose) { BOOST_LOG(rdInfoLog) << "AtomClash done:" << MolToSmiles(mol) << "\n"; + } } - if (!Options.GoodAtoms.empty()) - if (!CheckAtoms(mol, Options.GoodAtoms, Options.Verbose)) + if (!Options.GoodAtoms.empty()) { + if (!CheckAtoms(mol, Options.GoodAtoms, Options.Verbose)) { flags |= ATOM_CHECK_FAILED; + } + } - if (Options.CheckStereo && !CheckStereo(mol)) flags |= STEREO_ERROR; + if (Options.CheckStereo && !CheckStereo(mol)) { + flags |= STEREO_ERROR; + } // if (Options.GroupsToSGroups) // ConvertGroupsToSGroups(mol); @@ -188,7 +201,9 @@ unsigned StructChecker::checkMolStructure(RWMol &mol) const { // the end: if (0 != (flags & TRANSFORMED)) { // sanitize molecule // + ???? .............. ???? - if (mol.getRingInfo()->isInitialized()) mol.getRingInfo()->reset(); + if (mol.getRingInfo()->isInitialized()) { + mol.getRingInfo()->reset(); + } mol.getRingInfo()->initialize(); } return flags; diff --git a/Code/GraphMol/StructChecker/StructCheckerOptions.cpp b/Code/GraphMol/StructChecker/StructCheckerOptions.cpp index 8be5258cb..5676a546a 100644 --- a/Code/GraphMol/StructChecker/StructCheckerOptions.cpp +++ b/Code/GraphMol/StructChecker/StructCheckerOptions.cpp @@ -25,7 +25,9 @@ namespace RDKit { namespace StructureCheck { bool parseOptionsJSON(const std::string &json, StructCheckerOptions &op) { - if (json.empty()) return false; + if (json.empty()) { + return false; + } try { std::istringstream ss; ss.str(json); @@ -71,14 +73,21 @@ bool loadOptionsFromFiles( const std::string &stereoPatternFile, // file with stereo patterns const std::string &tautomerFile) { bool res = true; - if (!augmentedAtomTranslationsFile.empty()) + if (!augmentedAtomTranslationsFile.empty()) { res &= op.loadAugmentedAtomTranslations(augmentedAtomTranslationsFile); - if (!patternFile.empty()) res &= op.loadPatterns(patternFile); - if (!rotatePatternFile.empty()) + } + if (!patternFile.empty()) { + res &= op.loadPatterns(patternFile); + } + if (!rotatePatternFile.empty()) { res &= op.loadRotatePatterns(rotatePatternFile); - if (!stereoPatternFile.empty()) + } + if (!stereoPatternFile.empty()) { res &= op.loadStereoPatterns(stereoPatternFile); - if (!tautomerFile.empty()) res &= op.loadTautomerData(tautomerFile); + } + if (!tautomerFile.empty()) { + res &= op.loadTautomerData(tautomerFile); + } return res; } @@ -121,7 +130,9 @@ bool StringToAugmentedAtom(const char *str, AugmentedAtom &aa) { return false; } i = 0; - while (isalnum(str[i]) || str[i] == ',' || str[i] == '#') i++; + while (isalnum(str[i]) || str[i] == ',' || str[i] == '#') { + i++; + } aa.AtomSymbol = std::string(str, i); str += i; @@ -139,8 +150,9 @@ bool StringToAugmentedAtom(const char *str, AugmentedAtom &aa) { BOOST_LOG(rdErrorLog) << "syntax error '" << str - 1 << "'\n"; return false; } - } else + } else { aa.Charge = 0; // NONE; default + } // radical definition if (str == strpbrk(str, "|.:") && @@ -161,8 +173,9 @@ bool StringToAugmentedAtom(const char *str, AugmentedAtom &aa) { default: return false; // never }; - } else + } else { aa.Radical = RT_NONE; + } // read ligand descriptions while (*str == '(') { @@ -190,7 +203,9 @@ bool StringToAugmentedAtom(const char *str, AugmentedAtom &aa) { } i = 0; /* fetch atom symbol */ - while (isalnum(str[i]) || str[i] == ',' || str[i] == '#') i++; + while (isalnum(str[i]) || str[i] == ',' || str[i] == '#') { + i++; + } aa.Ligands.back().AtomSymbol = std::string(str, i); str += i; @@ -208,8 +223,9 @@ bool StringToAugmentedAtom(const char *str, AugmentedAtom &aa) { BOOST_LOG(rdErrorLog) << "syntax error '" << str - 1 << "'\n"; return false; } - } else + } else { aa.Ligands.back().Charge = 0; // NONE; default + } // radical definition if (str == strpbrk(str, "|.:") && @@ -230,19 +246,21 @@ bool StringToAugmentedAtom(const char *str, AugmentedAtom &aa) { default: return false; // never }; - } else + } else { aa.Ligands.back().Radical = RT_NONE; + } // substitution count descriptor if (str[0] == ':' && isdigit(str[1])) { aa.Ligands.back().SubstitutionCount = str[1] - '0'; str += 2; - } else + } else { aa.Ligands.back().SubstitutionCount = 0; + } - if (*str == ')') // check for close ')' + if (*str == ')') { // check for close ')' str++; - else { + } else { BOOST_LOG(rdErrorLog) << "unclosed ( '" << str << "'\n"; return false; } @@ -273,7 +291,9 @@ static bool ReadAugmentedAtoms(const std::string &path, char str[1024]; while (fgets(str, sizeof(str), fp)) { // comment block in '*.aci' file - if (*str != '#') break; + if (*str != '#') { + break; + } } sscanf(str, "%d", &n); @@ -300,11 +320,15 @@ static bool ReadAugmentedAtoms(const std::string &path, str[0] = '\0'; if (fgets(str, sizeof(str), fp)) { char *s = str; - while (*s >= ' ' && *s != '"') s++; + while (*s >= ' ' && *s != '"') { + s++; + } if (*s == '"') { s++; size_t len = 0; - while (s[len] >= ' ' && s[len] != '"') len++; + while (s[len] >= ' ' && s[len] != '"') { + len++; + } s[len] = '\0'; // == atom_string if (!StringToAugmentedAtom(s, atoms[i])) { BOOST_LOG(rdErrorLog) @@ -380,11 +404,15 @@ static bool ReadAAPairs( str[0] = '\0'; if (fgets(str, sizeof(str), fp)) { char *s = str; - while (*s >= ' ' && *s != '"') s++; + while (*s >= ' ' && *s != '"') { + s++; + } if (*s == '"') { s++; size_t len = 0; - while (s[len] >= ' ' && s[len] != '"') len++; + while (s[len] >= ' ' && s[len] != '"') { + len++; + } s[len] = '\0'; // == atom_string if (!StringToAugmentedAtom(s, trans_pairs[i].first)) { @@ -397,11 +425,15 @@ static bool ReadAAPairs( s += len; s++; // second atom quoted string - while (*s >= ' ' && *s != '"') s++; + while (*s >= ' ' && *s != '"') { + s++; + } if (*s == '"') { s++; len = 0; - while (s[len] >= ' ' && s[len] != '"') len++; + while (s[len] >= ' ' && s[len] != '"') { + len++; + } s[len] = '\0'; // == atom_string if (!StringToAugmentedAtom(s, trans_pairs[i].second)) { @@ -470,7 +502,9 @@ static void loadDefaultAugmentedAtoms(StructCheckerOptions &struchkOpts) { bool StructCheckerOptions::loadAugmentedAtomTranslations( const std::string &path) { AugmentedAtomPairs.clear(); - if (path.empty()) return false; + if (path.empty()) { + return false; + } return ReadAAPairs(path, AugmentedAtomPairs); } @@ -481,7 +515,9 @@ void StructCheckerOptions::setAugmentedAtomTranslations( bool StructCheckerOptions::loadAcidicAugmentedAtoms(const std::string &path) { AcidicAtoms.clear(); - if (path.empty()) return false; + if (path.empty()) { + return false; + } return ReadAugmentedAtoms(path, AcidicAtoms); } @@ -492,7 +528,9 @@ void StructCheckerOptions::setAcidicAugmentedAtoms( bool StructCheckerOptions::loadGoodAugmentedAtoms(const std::string &path) { GoodAtoms.clear(); - if (path.empty()) return false; + if (path.empty()) { + return false; + } return ReadAugmentedAtoms(path, GoodAtoms); } void StructCheckerOptions::setGoodAugmentedAtoms( @@ -520,7 +558,9 @@ static bool loadSDF(const std::string &path, std::vector &mols) { bool StructCheckerOptions::loadPatterns(const std::string &path) { Patterns.clear(); - if (path.empty()) return false; + if (path.empty()) { + return false; + } return loadSDF(path, Patterns); } @@ -530,7 +570,9 @@ void StructCheckerOptions::setPatterns(const std::vector &p) { bool StructCheckerOptions::loadRotatePatterns(const std::string &path) { RotatePatterns.clear(); - if (path.empty()) return false; + if (path.empty()) { + return false; + } return loadSDF(path, RotatePatterns); } @@ -540,7 +582,9 @@ void StructCheckerOptions::setRotatePatterns(const std::vector &p) { bool StructCheckerOptions::loadStereoPatterns(const std::string &path) { StereoPatterns.clear(); - if (path.empty()) return false; + if (path.empty()) { + return false; + } return loadSDF(path, StereoPatterns); } @@ -551,14 +595,18 @@ void StructCheckerOptions::setStereoPatterns(const std::vector &p) { bool StructCheckerOptions::loadTautomerData(const std::string &path) { ToTautomer.clear(); FromTautomer.clear(); - if (path.empty()) return false; + if (path.empty()) { + return false; + } try { std::string ext = path.substr(path.find_last_of(".") + 1); if (ext == "sdf" || ext == "SDF") { SDMolSupplier suppler(path); while (!suppler.atEnd()) { ROMol *m1 = suppler.next(); - if (suppler.atEnd()) break; + if (suppler.atEnd()) { + break; + } ROMol *m2 = suppler.next(); if (m1 && m2) { // ?? MakeHydrogensImplicit() @@ -633,7 +681,9 @@ static void parseSMARTS(std::vector &mols, mols.clear(); for (const auto &patt : smarts) { ROMol *m = SmartsToMol(patt); - if (m) mols.push_back(ROMOL_SPTR(m)); + if (m) { + mols.push_back(ROMOL_SPTR(m)); + } } } diff --git a/Code/GraphMol/StructChecker/StructureFlags.cpp b/Code/GraphMol/StructChecker/StructureFlags.cpp index e7d8566b0..b76174405 100644 --- a/Code/GraphMol/StructChecker/StructureFlags.cpp +++ b/Code/GraphMol/StructChecker/StructureFlags.cpp @@ -37,7 +37,9 @@ std::string StructChecker::StructureFlagsToString(unsigned f) { std::string s; for (unsigned bit = 0; bit < 16; bit++) { if (0 != (f & (1 << bit))) { - if (!s.empty()) s += ","; + if (!s.empty()) { + s += ","; + } s += flags[bit]; } } @@ -48,8 +50,11 @@ std::string StructChecker::StructureFlagsToString(unsigned f) { class FMap : public std::map { public: FMap() { - for (unsigned bit = 0; bit < 16; bit++) - if (*flags[bit]) (*this)[std::string(flags[bit])] = (1 << bit); + for (unsigned bit = 0; bit < 16; bit++) { + if (*flags[bit]) { + (*this)[std::string(flags[bit])] = (1 << bit); + } + } } }; @@ -58,17 +63,25 @@ unsigned StructChecker::StringToStructureFlags(const std::string &str) { unsigned int f = 0; const char *token = str.c_str(); while (*token) { - while (*token && *token <= ' ') // skip whitespaces (|...) + while (*token && *token <= ' ') { // skip whitespaces (|...) token++; + } unsigned len = 0; - while (token[len] && !(token[len] == ',' || token[len] <= ' ')) len++; - if (0 == len) continue; + while (token[len] && !(token[len] == ',' || token[len] <= ' ')) { + len++; + } + if (0 == len) { + continue; + } std::string name(token, len); auto it = fmap.find(name); - if (fmap.end() != it) f |= it->second; + if (fmap.end() != it) { + f |= it->second; + } while (token[len] && - (token[len] == ',' || token[len] <= ' ')) // skip delimeter + (token[len] == ',' || token[len] <= ' ')) { // skip delimeter len++; + } token += len; } return f; diff --git a/Code/GraphMol/StructChecker/Tautomer.cpp b/Code/GraphMol/StructChecker/Tautomer.cpp index 529dc9612..2744296fb 100644 --- a/Code/GraphMol/StructChecker/Tautomer.cpp +++ b/Code/GraphMol/StructChecker/Tautomer.cpp @@ -17,17 +17,19 @@ namespace StructureCheck { bool StructCheckTautomer::applyTautomer(unsigned it) { if (Options.FromTautomer.size() <= it || Options.ToTautomer.size() <= it) { - if (Options.Verbose) + if (Options.Verbose) { BOOST_LOG(rdInfoLog) << "ERROR: incorrect Tautomer index it=" << it << "\n"; + } return false; } const ROMol &fromTautomer = *Options.FromTautomer[it]; const ROMol &toTautomer = *Options.ToTautomer[it]; if (toTautomer.getNumAtoms() != fromTautomer.getNumAtoms()) { - if (Options.Verbose) + if (Options.Verbose) { BOOST_LOG(rdInfoLog) << "ERROR: incorrect data toTautomer.getNumAtoms() " "!= fromTautomer.getNumAtoms()\n"; + } // incorrect data // throw(.....); return false; @@ -36,11 +38,13 @@ bool StructCheckTautomer::applyTautomer(unsigned it) { MatchVectType match; // The format is (queryAtomIdx, molAtomIdx) if (!SubstructMatch(Mol, *Options.FromTautomer[it], - match)) // SSMatch(mp, from_tautomer, SINGLE_MATCH); + match)) { // SSMatch(mp, from_tautomer, SINGLE_MATCH); return false; - if (Options.Verbose) + } + if (Options.Verbose) { BOOST_LOG(rdInfoLog) << "found match for from_tautomer with " << nta << " atoms\n"; + } // init size_t invalid_idx = 1 + Mol.getNumAtoms(); std::vector atomIdxMap(Mol.getNumAtoms(), diff --git a/Code/GraphMol/StructChecker/Utilites.cpp b/Code/GraphMol/StructChecker/Utilites.cpp index 423adb37c..c47331944 100644 --- a/Code/GraphMol/StructChecker/Utilites.cpp +++ b/Code/GraphMol/StructChecker/Utilites.cpp @@ -40,18 +40,21 @@ bool getMolAtomPoints(const ROMol &mol, std::vector &atomPoint, bool non_zero_z = false; atomPoint.resize(mol.getNumAtoms()); // take X,Y,Z coordinates of each atom - if (0 != mol.getNumConformers()) + if (0 != mol.getNumConformers()) { for (auto cnfi = mol.beginConformers(); cnfi != mol.endConformers(); cnfi++) { const Conformer &conf = **cnfi; // mol.getConformer(confId); if (twod || conf.is3D()) { for (unsigned i = 0; i < mol.getNumAtoms(); i++) { atomPoint[i] = conf.getAtomPos(i); - if (fabs(atomPoint[i].z) >= 1.e-7) non_zero_z = true; + if (fabs(atomPoint[i].z) >= 1.e-7) { + non_zero_z = true; + } } break; } } + } if (atomPoint.empty()) { // compute XYZ // TODO: // ???? .......... @@ -62,16 +65,30 @@ bool getMolAtomPoints(const ROMol &mol, std::vector &atomPoint, typedef std::tuple NbrData; bool lessTuple(const NbrData &left, const NbrData &right) { - if (std::get<0>(left) < std::get<0>(right)) return true; - if (std::get<0>(left) > std::get<0>(right)) return false; + if (std::get<0>(left) < std::get<0>(right)) { + return true; + } + if (std::get<0>(left) > std::get<0>(right)) { + return false; + } - if (std::get<1>(left) < std::get<1>(right)) return true; - if (std::get<1>(left) > std::get<1>(right)) return false; + if (std::get<1>(left) < std::get<1>(right)) { + return true; + } + if (std::get<1>(left) > std::get<1>(right)) { + return false; + } - if (std::get<2>(left) < std::get<2>(right)) return true; - if (std::get<2>(left) > std::get<2>(right)) return false; + if (std::get<2>(left) < std::get<2>(right)) { + return true; + } + if (std::get<2>(left) > std::get<2>(right)) { + return false; + } - if (std::get<3>(left) < std::get<3>(right)) return true; + if (std::get<3>(left) < std::get<3>(right)) { + return true; + } return false; } @@ -87,10 +104,13 @@ std::string LogNeighbourhood( const Atom &atm = *mol.getAtomWithIdx(idx); oss << atm.getSymbol(); - if (atm.getFormalCharge()) + if (atm.getFormalCharge()) { oss << (atm.getFormalCharge() > 0 ? "+" : "") << atm.getFormalCharge(); + } - if (atm.getNumRadicalElectrons()) oss << atm.getNumRadicalElectrons(); + if (atm.getNumRadicalElectrons()) { + oss << atm.getNumRadicalElectrons(); + } // these neighbors should be sorted properly? size_t numNbrs = neighbour_array[idx].Atoms.size(); @@ -123,15 +143,19 @@ std::string LogNeighbourhood( bs = "~"; break; } - if (bs.size()) + if (bs.size()) { oss << "(" << bs << std::get<0>(nbr); - else + } else { oss << "(" << "?" << (int)std::get<1>(nbr) << "?" << std::get<0>(nbr); - if (std::get<2>(nbr)) + } + if (std::get<2>(nbr)) { oss << (std::get<2>(nbr) > 0 ? "+" : "") << std::get<2>(nbr); + } - if (std::get<3>(nbr)) oss << std::get<3>(nbr); + if (std::get<3>(nbr)) { + oss << std::get<3>(nbr); + } oss << ")"; } return oss.str(); diff --git a/Code/GraphMol/StructChecker/testStructChecker.cpp b/Code/GraphMol/StructChecker/testStructChecker.cpp index f225b780c..5fac894f9 100644 --- a/Code/GraphMol/StructChecker/testStructChecker.cpp +++ b/Code/GraphMol/StructChecker/testStructChecker.cpp @@ -97,21 +97,25 @@ void doLoadOptionsFromFiles(StructCheckerOptions &options, } else { testDataDir = dirBase; } - if (options.Verbose) + if (options.Verbose) { BOOST_LOG(rdInfoLog) << "testDataDir: " << testDataDir << "\n"; + } - if (options.Verbose) + if (options.Verbose) { BOOST_LOG(rdInfoLog) << "loadGoodAugmentedAtoms checkfgs.chk\n"; + } ok = options.loadGoodAugmentedAtoms(testDataDir + "checkfgs.chk"); TEST_ASSERT(ok); - if (options.Verbose) + if (options.Verbose) { BOOST_LOG(rdInfoLog) << "loadAcidicAugmentedAtoms checkfgs.aci\n"; + } ok = options.loadAcidicAugmentedAtoms(testDataDir + "checkfgs.aci"); TEST_ASSERT(!strict || ok); - if (options.Verbose) + if (options.Verbose) { BOOST_LOG(rdInfoLog) << "loadAugmentedAtomTranslations checkfgs.trn\n"; + } ok = options.loadAugmentedAtomTranslations(testDataDir + "checkfgs.trn"); TEST_ASSERT(ok); @@ -121,13 +125,15 @@ void doLoadOptionsFromFiles(StructCheckerOptions &options, //.... - if (options.Verbose) + if (options.Verbose) { BOOST_LOG(rdInfoLog) << "loadTautomerData tautomer.sdf\n"; + } ok = options.loadTautomerData(testDataDir + "tautomer.sdf"); TEST_ASSERT(!strict || ok); - if (options.Verbose) + if (options.Verbose) { BOOST_LOG(rdInfoLog) << "loadTautomerData tautomer.rdf\n"; + } ok = options.loadTautomerData(testDataDir + "tautomer.rdf"); TEST_ASSERT(!strict || ok); @@ -535,9 +541,11 @@ void testCheckMatch() { // options.Verbose = true; options.setGoodAugmentedAtoms(aa); - if (!options.GoodAtoms.empty()) - if (!CheckAtoms(*mol, options.GoodAtoms, options.Verbose)) + if (!options.GoodAtoms.empty()) { + if (!CheckAtoms(*mol, options.GoodAtoms, options.Verbose)) { BOOST_LOG(rdInfoLog) << "ATOM_CHECK_FAILED\n"; + } + } delete mol; BOOST_LOG(rdInfoLog) << "\tdone" << std::endl; diff --git a/Code/GraphMol/Subset.cpp b/Code/GraphMol/Subset.cpp index 689829f4a..fb0b30c71 100644 --- a/Code/GraphMol/Subset.cpp +++ b/Code/GraphMol/Subset.cpp @@ -19,7 +19,9 @@ namespace { inline void copyComputedProps(const ROMol &src, ROMol &dst) { dst.updateProps(src); for (auto &v : dst.getPropList(true, false)) { - if (v != RDKit::detail::computedPropName) dst.clearProp(v); + if (v != RDKit::detail::computedPropName) { + dst.clearProp(v); + } } } diff --git a/Code/GraphMol/Substruct/ullmann.hpp b/Code/GraphMol/Substruct/ullmann.hpp index 2476c54a5..b73e03e5a 100644 --- a/Code/GraphMol/Substruct/ullmann.hpp +++ b/Code/GraphMol/Substruct/ullmann.hpp @@ -90,8 +90,9 @@ bool forward_checking(const Graph& g1, const Graph& g2, UblasMatrix& M, M(k, l) = 1; } else if (!flag1_1 && !flag2_1) { // or both edges are not present M(k, l) = 1; - } else + } else { M(k, l) = 0; // if not, there's no mapping + } ++fi; } } @@ -101,12 +102,15 @@ bool forward_checking(const Graph& g1, const Graph& g2, UblasMatrix& M, size_t cero_row(0); for (size_t k = 0; k < num_vert_g1; ++k) { for (size_t l = 0; l < num_vert_g2; ++l) { - if (M(k, l)) + if (M(k, l)) { break; - else + } else { ++cero_row; + } + } + if (cero_row == num_vert_g2) { + return false; // if there is a cero row } - if (cero_row == num_vert_g2) return false; // if there is a cero row cero_row = 0; } return true; @@ -205,8 +209,9 @@ void prepareM(const Graph& g1, const Graph& g2, VertexLabeling& vertex_labeling, for (size_t j = 0; j < cols; ++j) { if (out_degree(j, g2) >= out_degree(i, g1) && vertex_labeling(i, j)) { M(i, j) = 1; - } else + } else { M(i, j) = 0; + } } } } diff --git a/Code/GraphMol/SynthonSpaceSearch/SearchResults.cpp b/Code/GraphMol/SynthonSpaceSearch/SearchResults.cpp index a8f923622..be30702d5 100644 --- a/Code/GraphMol/SynthonSpaceSearch/SearchResults.cpp +++ b/Code/GraphMol/SynthonSpaceSearch/SearchResults.cpp @@ -30,8 +30,12 @@ SearchResults::SearchResults(const SearchResults &other) void SearchResults::mergeResults(SearchResults &other) { d_maxNumResults += other.d_maxNumResults; - if (other.d_timedOut) d_timedOut = true; - if (other.d_cancelled) d_cancelled = true; + if (other.d_timedOut) { + d_timedOut = true; + } + if (other.d_cancelled) { + d_cancelled = true; + } if (d_molNames.empty()) { for (const auto &mol : d_hitMolecules) { d_molNames.insert(mol->getProp(common_properties::_Name)); diff --git a/Code/GraphMol/Wrap/Queries.cpp b/Code/GraphMol/Wrap/Queries.cpp index 69eaeb99d..39d575ecd 100644 --- a/Code/GraphMol/Wrap/Queries.cpp +++ b/Code/GraphMol/Wrap/Queries.cpp @@ -31,30 +31,38 @@ namespace RDKit { QueryAtom *_funcname_##EqualsQueryAtom(_typ_ val, bool negate) { \ QueryAtom *res = new QueryAtom(); \ res->setQuery(_func_(val)); \ - if (negate) res->getQuery()->setNegation(true); \ + if (negate) { \ + res->getQuery()->setNegation(true); \ + } \ return res; \ } \ QueryAtom *_funcname_##LessQueryAtom(_typ_ val, bool negate) { \ QueryAtom *res = new QueryAtom(); \ res->setQuery( \ _func_(val, std::string(#_funcname_ "Less"))); \ - if (negate) res->getQuery()->setNegation(true); \ + if (negate) { \ + res->getQuery()->setNegation(true); \ + } \ return res; \ } \ QueryAtom *_funcname_##GreaterQueryAtom(_typ_ val, bool negate) { \ QueryAtom *res = new QueryAtom(); \ res->setQuery( \ _func_(val, std::string(#_funcname_ "Greater"))); \ - if (negate) res->getQuery()->setNegation(true); \ + if (negate) { \ + res->getQuery()->setNegation(true); \ + } \ return res; \ } -#define QAFUNC2(_funcname_, _func_, _typ_) \ - QueryAtom *_funcname_(bool negate) { \ - QueryAtom *res = new QueryAtom(); \ - res->setQuery(_func_()); \ - if (negate) res->getQuery()->setNegation(true); \ - return res; \ +#define QAFUNC2(_funcname_, _func_, _typ_) \ + QueryAtom *_funcname_(bool negate) { \ + QueryAtom *res = new QueryAtom(); \ + res->setQuery(_func_()); \ + if (negate) { \ + res->getQuery()->setNegation(true); \ + } \ + return res; \ } QAFUNC1(AtomNum, makeAtomNumQuery, int); QAFUNC1(ExplicitValence, makeAtomExplicitValenceQuery, int); diff --git a/Code/GraphMol/Wrap/props.hpp b/Code/GraphMol/Wrap/props.hpp index eb1984681..2f205e366 100644 --- a/Code/GraphMol/Wrap/props.hpp +++ b/Code/GraphMol/Wrap/props.hpp @@ -104,8 +104,9 @@ boost::python::dict GetPropsAsDict(const T &obj, bool includePrivate, STR_VECT keys = obj.getPropList(includePrivate, includeComputed); for (auto &rdvalue : data) { - if (std::find(keys.begin(), keys.end(), rdvalue.key) == keys.end()) + if (std::find(keys.begin(), keys.end(), rdvalue.key) == keys.end()) { continue; + } try { const auto tag = rdvalue.val.getTag(); switch (tag) { @@ -218,12 +219,13 @@ python::object autoConvertString(const RDOb *ob, const std::string &key) { double dvalue; std::string svalue; - if (ob->getPropIfPresent(key, ivalue)) + if (ob->getPropIfPresent(key, ivalue)) { return python::object(ivalue); - else if (ob->getPropIfPresent(key, dvalue)) + } else if (ob->getPropIfPresent(key, dvalue)) { return python::object(dvalue); - else if (ob->getPropIfPresent(key, svalue)) + } else if (ob->getPropIfPresent(key, svalue)) { return python::object(svalue); + } return python::object(); } diff --git a/Code/GraphMol/molopstest.cpp b/Code/GraphMol/molopstest.cpp index 35a0386e2..9e51da8a7 100644 --- a/Code/GraphMol/molopstest.cpp +++ b/Code/GraphMol/molopstest.cpp @@ -6537,7 +6537,9 @@ TEST_CASE("Testing MMFF94 aromaticity") { MolOps::setAromaticity(*m, MolOps::AROMATICITY_RDKIT); int arombondcount = 0; for (auto b : m->bonds()) { - if (b->getIsAromatic()) arombondcount++; + if (b->getIsAromatic()) { + arombondcount++; + } } // all bonds, except the fused one, should be aromatic REQUIRE(arombondcount == 10); @@ -6546,7 +6548,9 @@ TEST_CASE("Testing MMFF94 aromaticity") { MolOps::setAromaticity(*m, MolOps::AROMATICITY_MMFF94); arombondcount = 0; for (auto b : m->bonds()) { - if (b->getIsAromatic()) arombondcount++; + if (b->getIsAromatic()) { + arombondcount++; + } } // no aromatics here REQUIRE(arombondcount == 0); diff --git a/Code/JavaWrappers/DiversityPick.h b/Code/JavaWrappers/DiversityPick.h index 48946b6ed..1e463fa10 100644 --- a/Code/JavaWrappers/DiversityPick.h +++ b/Code/JavaWrappers/DiversityPick.h @@ -38,8 +38,9 @@ std::vector pickUsingFingerprints( const std::vector &ebvs, unsigned int nToPick, int seed = -1, std::vector firstPicks = std::vector(), bool useCache = true) { - if (nToPick >= ebvs.size()) + if (nToPick >= ebvs.size()) { throw ValueErrorException("nToPick is larger than the vector size"); + } std::vector res; RDPickers::MaxMinPicker picker; diff --git a/Code/PgSQL/rdkit/guc.c b/Code/PgSQL/rdkit/guc.c index fcdc32238..080a2dfd1 100644 --- a/Code/PgSQL/rdkit/guc.c +++ b/Code/PgSQL/rdkit/guc.c @@ -78,7 +78,9 @@ static int rdkit_difference_FP_weight_agents = REACTION_DFP_WEIGHT_AGENTS; static int rdkit_difference_FP_weight_nonagents = REACTION_DFP_WEIGHT_NONAGENTS; static void initRDKitGUC() { - if (rdkit_guc_inited) return; + if (rdkit_guc_inited) { + return; + } DefineCustomRealVariable( "rdkit.tanimoto_threshold", "Lower threshold of Tanimoto similarity", @@ -206,121 +208,167 @@ static void initRDKitGUC() { } double getTanimotoLimit(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_tanimoto_smlar_limit; } double getDiceLimit(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_dice_smlar_limit; } bool getDoChiralSSS(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_do_chiral_sss; } bool getDoEnhancedStereoSSS(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_do_enhanced_stereo_sss; } int getSubstructFpSize(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_sss_fp_size; } int getMorganFpSize(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_morgan_fp_size; } int getFeatMorganFpSize(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_featmorgan_fp_size; } int getLayeredFpSize(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_layered_fp_size; } int getRDKitFpSize(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_rdkit_fp_size; } int getHashedTorsionFpSize(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_hashed_torsion_fp_size; } int getHashedAtomPairFpSize(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_hashed_atompair_fp_size; } int getAvalonFpSize(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_avalon_fp_size; } int getReactionSubstructFpSize(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_reaction_sss_fp_size; } int getReactionDifferenceFpSize(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_reaction_difference_fp_size; } int getReactionSubstructFpType(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_reaction_sss_fp_type; } int getReactionDifferenceFpType(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_reaction_difference_fp_type; } bool getIgnoreReactionAgents(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_ignore_reaction_agents; } double getReactionStructuralFPAgentBitRatio(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_agent_FP_bit_ratio; } bool getMoveUnmappedReactantsToAgents(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_move_unmmapped_reactants_to_agents; } double getThresholdUnmappedReactantAtoms(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_threshold_unmapped_reactant_atoms; } bool getInitReaction(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_init_reaction; } int getReactionDifferenceFPWeightAgents(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_difference_FP_weight_agents; } int getReactionDifferenceFPWeightNonagents(void) { - if (!rdkit_guc_inited) initRDKitGUC(); + if (!rdkit_guc_inited) { + initRDKitGUC(); + } return rdkit_difference_FP_weight_nonagents; } diff --git a/Code/PgSQL/rdkit/low_gist.c b/Code/PgSQL/rdkit/low_gist.c index 2a8ce4c91..a5736d94a 100644 --- a/Code/PgSQL/rdkit/low_gist.c +++ b/Code/PgSQL/rdkit/low_gist.c @@ -84,10 +84,13 @@ static void adjustKey(IntRange *s, IntRange *k) { for (j = 0; j < NUMRANGE; j++) { /* set minimal non-zero value */ - if (k[j].low > 0 && (s[j].low == 0 || k[j].low < s[j].low)) + if (k[j].low > 0 && (s[j].low == 0 || k[j].low < s[j].low)) { s[j].low = k[j].low; + } /* set maximum value */ - if (k[j].high > s[j].high) s[j].high = k[j].high; + if (k[j].high > s[j].high) { + s[j].high = k[j].high; + } } } @@ -140,18 +143,21 @@ static uint32 distance(bytea *a, bytea *b) { uint32 dist = 0; IntRange *as = (IntRange *)VARDATA(a), *bs = (IntRange *)VARDATA(b); - if (VARSIZE(a) != VARSIZE(b)) + if (VARSIZE(a) != VARSIZE(b)) { elog(ERROR, "All fingerprints should be the same length"); + } for (i = 0; i < NUMRANGE; i++) { - if (as[i].low > bs[i].low) + if (as[i].low > bs[i].low) { dist += as[i].low - bs[i].low; - else if (as[i].low < bs[i].low) + } else if (as[i].low < bs[i].low) { dist += bs[i].low - as[i].low; + } - if (as[i].high > bs[i].high) + if (as[i].high > bs[i].high) { dist += as[i].high - bs[i].high; - else if (as[i].high < bs[i].high) + } else if (as[i].high < bs[i].high) { dist += bs[i].high - as[i].high; + } } return dist; } @@ -162,18 +168,22 @@ static uint32 penalty(bytea *origval, bytea *newval) { IntRange *as = (IntRange *)VARDATA(origval), *bs = (IntRange *)VARDATA(newval); - if (VARSIZE(origval) != VARSIZE(newval)) + if (VARSIZE(origval) != VARSIZE(newval)) { elog(ERROR, "All fingerprints should be the same length"); + } for (i = 0; i < NUMRANGE; i++) { if (bs[i].low > 0) { - if (as[i].low == 0) + if (as[i].low == 0) { dist += bs[i].low; - else if (bs[i].low < as[i].low) + } else if (bs[i].low < as[i].low) { dist += as[i].low - bs[i].low; + } } - if (bs[i].high > as[i].high) dist += bs[i].high - as[i].high; + if (bs[i].high > as[i].high) { + dist += bs[i].high - as[i].high; + } } return dist; @@ -210,10 +220,11 @@ static int comparecost(const void *va, const void *vb) { SPLITCOST *a = (SPLITCOST *)va; SPLITCOST *b = (SPLITCOST *)vb; - if (a->cost == b->cost) + if (a->cost == b->cost) { return 0; - else + } else { return (a->cost > b->cost) ? 1 : -1; + } } PGDLLEXPORT Datum gslfp_picksplit(PG_FUNCTION_ARGS); diff --git a/Code/PgSQL/rdkit/rdkit.h b/Code/PgSQL/rdkit/rdkit.h index 12f7be4c6..6c92fb5b0 100644 --- a/Code/PgSQL/rdkit/rdkit.h +++ b/Code/PgSQL/rdkit/rdkit.h @@ -48,9 +48,11 @@ extern "C" { #endif #endif -#define RDKIT_FREE_IF_COPY_P(ptrsrc, ptrori) \ - do { \ - if ((Pointer)(ptrsrc) != (Pointer)(ptrori)) pfree(ptrsrc); \ +#define RDKIT_FREE_IF_COPY_P(ptrsrc, ptrori) \ + do { \ + if ((Pointer)(ptrsrc) != (Pointer)(ptrori)) { \ + pfree(ptrsrc); \ + } \ } while (0) typedef bytea Mol; diff --git a/Code/PgSQL/rdkit/rdkit_gist.c b/Code/PgSQL/rdkit/rdkit_gist.c index ac95d2bc4..07f027d0c 100644 --- a/Code/PgSQL/rdkit/rdkit_gist.c +++ b/Code/PgSQL/rdkit/rdkit_gist.c @@ -224,10 +224,11 @@ static int soergeldistsign(bytea *a, bytea *b) { static int hemdist(bytea *a, bytea *b) { if (ISALLTRUE(a)) { - if (ISALLTRUE(b)) + if (ISALLTRUE(b)) { return 0; - else + } else { return SIGLENBIT(b) - bitstringWeight(SIGLEN(b), (uint8 *)VARDATA(b)); + } } else if (ISALLTRUE(b)) { return SIGLENBIT(a) - bitstringWeight(SIGLEN(a), (uint8 *)VARDATA(a)); } @@ -238,11 +239,12 @@ static int soergeldist(bytea *a, bytea *b) { double d; if (ISALLTRUE(a)) { - if (ISALLTRUE(b)) + if (ISALLTRUE(b)) { return 0; - else + } else { // FIXME shouldn't it be double(sizebitvec(b))/SIGLENBIT(b); ? return SIGLENBIT(b) - bitstringWeight(SIGLEN(b), (uint8 *)VARDATA(b)); + } } else if (ISALLTRUE(b)) { // FIXME shouldn't it be double(sizebitvec(a))/SIGLENBIT(a); ? return SIGLENBIT(a) - bitstringWeight(SIGLEN(a), (uint8 *)VARDATA(a)); diff --git a/Code/RDGeneral/RDValue-doublemagic.h b/Code/RDGeneral/RDValue-doublemagic.h index ef6495863..c64cade7b 100644 --- a/Code/RDGeneral/RDValue-doublemagic.h +++ b/Code/RDGeneral/RDValue-doublemagic.h @@ -183,8 +183,9 @@ struct RDValue { // quiet NaNs are used for other types. otherBits = RDTypeTag::NaN; assert(boost::math::isnan(doubleBits)); - } else + } else { doubleBits = number; + } } inline RDValue(float number) { @@ -455,21 +456,24 @@ inline float rdvalue_cast(RDValue_cast_t v) { // and enable_if template <> inline int rdvalue_cast(RDValue_cast_t v) { - if (rdvalue_is(v)) + if (rdvalue_is(v)) { return static_cast(v.otherBits & ~RDTypeTag::IntTag); + } throw std::bad_any_cast(); } template <> inline unsigned int rdvalue_cast(RDValue_cast_t v) { - if (rdvalue_is(v)) + if (rdvalue_is(v)) { return static_cast(v.otherBits & ~RDTypeTag::UnsignedIntTag); + } throw std::bad_any_cast(); } template <> inline bool rdvalue_cast(RDValue_cast_t v) { - if (rdvalue_is(v)) + if (rdvalue_is(v)) { return static_cast(v.otherBits & ~RDTypeTag::BoolTag); + } throw std::bad_any_cast(); } diff --git a/Code/SimDivPickers/pickersCLI.cpp b/Code/SimDivPickers/pickersCLI.cpp index ae008c754..10aa47d9a 100644 --- a/Code/SimDivPickers/pickersCLI.cpp +++ b/Code/SimDivPickers/pickersCLI.cpp @@ -35,7 +35,9 @@ static unsigned int LoadDatabase(FILE *fp) { unsigned int result = 0; while (fgets(buffer, sizeof(buffer), fp)) { - if (buffer[0] == '#' || buffer[0] == ' ' || buffer[0] == '\t') continue; + if (buffer[0] == '#' || buffer[0] == ' ' || buffer[0] == '\t') { + continue; + } char *ptr = buffer; while (*ptr && *ptr != ' ' && *ptr != '\t') ptr++; if (*ptr) { @@ -67,12 +69,15 @@ static unsigned int LoadDatabase(FILE *fp) { static unsigned int LoadDatabase(const char *fname) { if (fname && strcmp(fname, "-")) { FILE *fp = fopen(fname, "rb"); - if (!fp) return 0; + if (!fp) { + return 0; + } unsigned int result = LoadDatabase(fp); fclose(fp); return result; - } else + } else { return LoadDatabase(stdin); + } } #ifdef UNUSED @@ -81,15 +86,18 @@ static void GenerateFingerprints() { unsigned int size = (unsigned int)(count * sizeof(void *)); fps = (ExplicitBitVect **)malloc(size); - for (unsigned int i = 0; i < count; i++) + for (unsigned int i = 0; i < count; i++) { fps[i] = RDKit::MorganFingerprints::getFingerprintAsBitVect(*mols[i], 2, 2048); + } fprintf(stderr, "%u Fingerprints\n", count); } static void DestroyFingerprints() { unsigned int count = (unsigned int)mols.size(); - for (unsigned int i = 0; i < count; i++) delete fps[i]; + for (unsigned int i = 0; i < count; i++) { + delete fps[i]; + } free(fps); } #endif @@ -109,17 +117,21 @@ static void ProcessCommandLine(int argc, char *argv[]) { if (ptr[0] == '-' && ptr[1]) { if (ptr[1] >= '0' && ptr[1] <= '9') { newpicks = atoi(ptr + 1); - } else + } else { DisplayUsage(); + } } else if (!poolname) { poolname = ptr; } else if (!pickname) { pickname = ptr; - } else + } else { DisplayUsage(); + } } - if (!poolname) DisplayUsage(); + if (!poolname) { + DisplayUsage(); + } } double MyDist(int i, int j) { @@ -147,10 +159,13 @@ int main(int argc, char *argv[]) { elapsed = (end.tv_sec + 0.000001 * end.tv_usec) - (beg.tv_sec + 0.000001 * beg.tv_usec); fprintf(stderr, "Elapsed time: %g secs\n", elapsed); - } else + } else { picksize = 0; + } poolsize = origsize + picksize; - if (newpicks == 0) newpicks = origsize; + if (newpicks == 0) { + newpicks = origsize; + } #ifdef UNUSED gettimeofday(&beg, (struct timezone *)0); @@ -164,8 +179,9 @@ int main(int argc, char *argv[]) { RDKit::INT_VECT firstPicks; if (picksize) { firstPicks.reserve(picksize); - for (unsigned int i = 0; i < picksize; i++) + for (unsigned int i = 0; i < picksize; i++) { firstPicks.push_back((int)(i + origsize)); + } } // RDPickers::MaxMinPicker mmpicker; diff --git a/External/CoordGen/CoordGen.h b/External/CoordGen/CoordGen.h index d2a19d860..f3603871c 100644 --- a/External/CoordGen/CoordGen.h +++ b/External/CoordGen/CoordGen.h @@ -53,7 +53,9 @@ static CoordGenParams defaultParams; */ template unsigned int addCoords(T &mol, const CoordGenParams *params = nullptr) { - if (!params) params = &defaultParams; + if (!params) { + params = &defaultParams; + } // FIX: the default value of this should be handled once in a threadsafe way std::string templateFileDir; if (params->templateFileDir != "") {