Commit Graph

115 Commits

Author SHA1 Message Date
Greg Landrum
25ce3f3602 Fixes #9020 (#9025)
* Fixes #9020

* add another test

---------

Co-authored-by: = <=>
2026-01-30 05:00:55 +01:00
Greg Landrum
8800e1556b Do not reset the ringInfo information when adding bonds to RWMol (#8934)
* Do not reset the ringInfo information when adding bonds

This call was inconsistent (for example, the version of addBond() in ROMol did not do it)
and is unnecessary since the standard assumption is molecules need
to be re-sanitized after adding atoms and bonds

* response to review

clear the property cache on atoms after adding a bond.

* add a property cache update to the reaction runner

* add something to the release notes
2025-11-27 17:21:07 +01:00
Ricardo Rodriguez
eac676c625 Fixes #8726 (#8874)
* do not remove hydrides by default

* add a minimal test

* add release note about behavior change

* require Hydrides to have degree 1

* also allow hydrides with degree 0 (ionic bond)

* suggested changes

---------

Co-authored-by: greg landrum <greg.landrum@gmail.com>
2025-10-31 13:46:57 +01:00
Greg Landrum
231f711c05 fix a logic error in needsHs (#8442)
* fix a logic error in needsHs

* add another test
2025-04-16 14:36:45 +02:00
Greg Landrum
b40f99eee3 Fixes #8304 (#8316)
* first pass, does not pass all tests

* add an option to control the new behavior

* add that to the python wrapper too

Fixes #8304

* Update Code/GraphMol/MolOps.h

Co-authored-by: Ricardo Rodriguez <ricrogz@users.noreply.github.com>

* undo some extra comment reformatting

* typo

Co-authored-by: Ricardo Rodriguez <ricrogz@users.noreply.github.com>

---------

Co-authored-by: Ricardo Rodriguez <ricrogz@users.noreply.github.com>
2025-03-04 14:56:08 +01:00
Greg Landrum
fa048eacc5 Replace GetImplicitValence() and GetExplicitValence() with GetValence() (#7926) 2025-01-28 21:09:03 +01:00
Ricardo Rodriguez
c01ca64ac1 Fixes #8065 (#8066)
* add test + fix

* simplification

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>

---------

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
2024-12-12 06:11:23 +01:00
Brian Kelley
7b31d5307b MergeQueryHs better detects hydrogens in OR queries (#8043)
* Fixes #7687

* Make sure high and low precedence ands also work

* really fix the issue

* Fix merge conflict

* Add AtomType to MergeH check with test
2024-11-26 04:44:32 +01:00
Ricardo Rodriguez
39d4662ae7 Throw when attempting to normalize a Zero RDGeom::Point (#8008)
* throw if close to zero

* fix moldraw2DTestCatch

* Fix testRGroupDecomp

* fix one test in distGeomHelpersCatch

* fix tests in distGeomHelpersCatch

* retry finding a dir vector when adding Hs

* push UFF fixes to calculateCosY

* fix the setTerminalAtomCoords deg 4 patch

* add a test

* reduce zero tolerance
2024-11-19 04:33:22 +01:00
Rachel Walker
94c902ba54 Postpone clearing computed properties until after all Hs removed (#7241) 2024-03-16 06:14:24 +01:00
Ric
8d6e6aa00c Fixes #7123 (#7124)
* don't set noimplicit

* remove the (unused) origNoImplicit property

* update old test

* add check to test
2024-02-02 05:27:47 +01:00
Ric
897de1d92d Fixes #6944 (#6950)
* fix issue

* add a test

* add copyright note
2023-12-01 05:41:14 +01:00
Brian Kelley
cccee15a91 Add hasQueryHs (#6702) 2023-09-15 08:59:56 +02:00
Ric
3167c06544 Fixes Issue 6437 (#6438)
* Add tests

* fix

* rename function
2023-06-06 17:41:03 +02:00
Desmond Gilmour
295ade0fd4 fixes #6119 (#6183)
* fixes #6119

* fixed comments and made the logic more readable

* modified test cases

---------

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
2023-04-16 05:38:06 +02:00
Calvin Josenhans
b6345a816b Using Chiral Tag instead of CIPCode to ensure preservation of chirality in addHs (#6259)
* Changing flags if doIsomericSmiles is false

* Ignoring cis-trans bonds as well

* Tests for removing enhanced stereo

* Fix #6237 by checking chiral tag instead of CIP

* Remove unnecesary calls to fabs

* Modify AddHs

* Tets for #6237

* Rerun Checks
2023-04-14 09:03:35 +02:00
Greg Landrum
1f4584b2ca run clang_format (#5676) 2022-11-01 04:14:26 +01:00
Gareth Jones
cc613ba660 By default mergeQueryHs now will not remove isotopes (#5563) 2022-09-16 17:29:32 +02:00
Ric
0d8ad69541 fix warnings (#5561) 2022-09-14 06:36:42 +02:00
Ric
b06bd882c7 Allow removal of non-special H atoms in SGroups (#5399)
* do not remoge H if it has a special purpose in an SGroup

* flip the removeinSGroup default

* do not remove H from H-only SGroups

* remove atoms/bonds from SGroups

* update existing tests

* add tests

* Apply suggestions from code review

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
2022-07-07 11:05:18 +02:00
Greg Landrum
cd74dc2207 Initial support for non-tetrahedral stereochemistry (#5084)
* very basics: actually parsing the new atom stereochem features

* add some input verification for the chiral permutations

* fix a typo
add quadruple bond SMILES/SMARTS extension

* add forgotten files

* patch from Roger

* add Roger's parsing examples

* typo

* new tests

* adjusted version of next PR from Roger:
- add SP2D hybridization for square planar (this may change)
- some modernizationof Chirality.cpp
- stop using < HybridizationType in Chirality.cpp (should probably do this elsewhere too)
- improved handling of hybridization assignment for new stereochem
- handle new stereo/hybridization in UFF
- tests for the above

* perception of non-tetrahedral stereo from 3D (from Roger S)
Basic testing of SP and TB based on opensmiles docs

* potential fixes for octahedral assignment
more tests

* docs update
need way more!

* map the TH tags directly to @ tags

* very basics of SMILES writing
this does not work with anything that changes the permutation order
like canonicalization or writing things in rings.

* start to support the getChiralAcross API

* more testing

* consistency

* add hasNonTetrahedralStereo() and getIdealAngleBetweenLigands()

* assignStereochemistry should only remove non-tetrahedral stereo

* re-simplify those tests

* cleanup matrix stream output

* initial pass at supporting nontet stereo in distgeom

* backup

* start on the reference docs

* TBP reference

* first pass at Oh finished

* update SP section

* more doc updates

* fix a typo

* add param to not remove Hs connected to non-tetrahedral atoms

* VERY basic coord generation for square planar

* TBP basics

* basic OH depiction

* start testing missing ligands
allow non-tet stereo in rings (ugly, but correct)

* add new TBP functions from Roger

* update depiction code for new API

* backup, the new tests work so far

* Finish the TB tests

* OH tests pass too

* cleanup

* first pass at getting correct SMILES with reordering
need way more testing than this

* ensure permutation 0 is correctly preserved

* some progress towards adding non-tetrahedral stereo to StereoInfo

* doc update

* add non-tet chiral classes to python wrappers

* make sure removeAllHs also gets neighbors of non-tetrahedral centers
more testing

* a bit of depictor cleanup

* make the assignment from 3D more tolerant
more testing

* improve the bulk testing

* cleanup

* remove a bit of redundant code

* ensure we don't write bogus permutation values to SMILES

* fix some rebase problems

* allow assignStereochemistryFrom3D() to be called without sanitization

* allow disabling the non-tetrahedral stereo when it's not explicit

* get that working on windows too
2022-05-20 09:07:16 +02:00
Ric
00460547a0 fix + test (#5100) 2022-03-17 04:53:17 +01:00
Greg Landrum
db15b372a1 Fix some problems turned up by ossfuzz (#4927)
* resolves oss-fuzz #24399

* clean up some undefined behavior

* fix some UB in mergeQueryHs

* be more defensive

* defensive programming

* fix a _cxsmilesBondIdx bug

* more defensive programming
2022-01-22 04:30:06 +01:00
Paolo Tosco
0e3aa77fd0 Make sure that added R-groups have non-zero coordinates (#3877)
* Make sure that added R-groups have non-zero coordinates

* - renamed setHydrogenCoords to setTerminalAtomCoords (and parameters accordingly)
- switched from ROMol* to RoMol& to remove a PRECONDITION
- documented the newly exposed C++ function
- added a Python wrapper
- added C++ and Python tests

* fixed conflicts and added a test

* Update Code/GraphMol/RGroupDecomposition/testRGroupDecomp.cpp

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>

* Update Code/GraphMol/RGroupDecomposition/testRGroupDecomp.cpp

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>

* Update Code/GraphMol/MolOps.h

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>

* Update Code/GraphMol/Wrap/MolOps.cpp

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>

* changes in response to review

Co-authored-by: Paolo Tosco <paolo.tosco@novartis.com>
Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
2021-03-19 08:17:56 +01:00
Greg Landrum
f0896508f3 Fixes #3932 (#3933) 2021-03-15 17:21:50 +01:00
Greg Landrum
2e3f31990d Allow batch editing of molecules: removal only (#3875)
* backup

* simple first pass, passes all tests

* cleanup a bunch of existing uses

* ensure that we can safely add atoms/bonds while in edit mode

* add context manager on python side

* handle exceptions properly in those

* changes in response to review
2021-03-11 05:10:43 +01:00
Gareth Jones
81d3705358 R group match any issue (#3767)
* RGD modifications for any atom and index labels

* Continued development

* All tests working

* Added comment

* CR changes suggested by PTosco

* Fix catch_rgd for autocrlf

* Core dummy matches on output. RGroups on heavy atom. Dummy atoms User rgroups only when they are degree 1.

* Start work on test fixes

* testRGroupDecomp test working

* CPP and Python tests working

* Removed options for matching core query atoms on sidechains

* Windows build fix

* R groups off ring. User group matches single heavy substituent. Remove extraneous hydrogens

* Updated fingerprint variance score and tie selection

* Refactor fingerprint variance score functions to class

* Removed fingerprint distance score

* Boost::trim fix

* Updated RGD test notebook

* Fixed AddHs.cpp

* - fixes the kekulization issue
- avoids that empty R-group labels are included in cores
- makes sure that SMILES cores are always canonical
- adds a few missing const declarations and avoids unintentional copying

* Support for allowNonTerminalRGroups parameter. Remove R groups that contain H or Nothing.  Ignore R group labels on non-dummy atoms

* Fixed tests for Paolo's changes. Rebuilt test notebook.  Increased weighting of rgroup penalty in fingerprint variance score

* remove some debug output

Co-authored-by: Brian Kelley <fustigator@gmail.com>
Co-authored-by: greg landrum <greg.landrum@gmail.com>
2021-03-10 12:56:42 +01:00
Greg Landrum
9277bd56a7 Fixes 3879: bad placement of Hs with fused rings (#3899)
* backup

* Fixes #3879
also simplifies the code to place Hs

* switch to bisecting the angle

* reapply the fix for #3854
2021-03-10 05:38:36 +01:00
Paolo Tosco
f04a9c9a42 - switched to using std::vector<unsigned int> for isotopichs property (#3878)
- switched to using std::vector<int> instead of std::list<int> for _ErGAtomTypes property
- added RegisterListConverter<std::vector<unsigned int>>

Co-authored-by: Paolo Tosco <paolo.tosco@novartis.com>
2021-03-05 16:37:43 +01:00
Ric
bd712483cd Addresses #3854 (#3855)
* add fix

* add test

* fix the referenced issue

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
2021-03-01 05:38:27 +01:00
Greg Landrum
5747c4f283 Issue a warning when embedding a molecule with no Hs (#3807)
* add "needsHs()" query

* add warning for embedding without Hs

* add H checks to UFF and MMFF as well;
a small amount of cleanup in the MMFF atom typing
2021-02-22 06:57:50 +01:00
Ric
703fe5a225 Remove boost::foreach from public headers (#3820)
* remove include from headers

* update implementation files

* completely remove BOOST_FOREACH (#7)

* convert those changes to use auto

* get rid of all usage of BOOST_FOREACH

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
2021-02-17 14:15:48 +01:00
Paolo Tosco
7d0d7df5f0 Fixes a number of issues flagged by clang (#3498)
* - fixes a number of issues flagged by clang

* - removed commented line
2020-10-15 15:03:34 +02:00
Paolo Tosco
24e644dd29 Add better support for isotopic Hs to removeHs() and addHs() (#3396)
* Add better support for isotopic Hs to removeHs() and addHs()

* simplify the new code to add Hs back

* Changes in response to review

* revert FindCairo.cmake that I pushed by mistake (grrr)

Co-authored-by: greg landrum <greg.landrum@gmail.com>
2020-09-24 05:09:42 +02:00
Paolo Tosco
d372865b67 Fixes a bug in AddHs() involving sp2 centers with degree 1 (#3383)
* Fixes a bug in AddHs() involving sp2 centers with degree 1

* Changes in response to review

* forgot to run clang-format
2020-08-31 13:42:37 +02:00
Greg Landrum
45b9aef28b clang-tidy modernize-use-default-member-init and modernize-use-emplace (#3190)
* run clang-tidy with modernize-use-default-member-init

* results from modernize-use-emplace

* one uniform initialization per line
otherwise SWIG is unhappy

Co-authored-by: Brian Kelley <fustigator@gmail.com>
2020-05-28 09:07:58 +02:00
Greg Landrum
95613b6279 Allow SubstanceGroups to survive molecule edits (#3170)
* Progress on #3168

* Fixes #3167

* Fixes #3169

* deal with CBONDS too

* test PATOMS

* Fixes #3175

* a bit of code simplification and test updates

still needs more testing

* more testing

* handle s-group hierarchy
also a couple of other changes in response to the review

* add forgotten test file

* changes in response to review
2020-05-19 17:35:08 +02:00
Manan Goel
2a413a9399 Fixes #3150 (#3166)
* Fixes #3150
Fixes removeHs removing Hydrides by adding a removeHydrides flag to RemoveHsParameters.
If removeHydrides is false, Hydrogen atoms with formal charge -1 and degree less than or equal to 1 are kept
removeHydrides is kept true by default

* Made suggested changes
Removed extraneous comments and redundant code
Added tests for both ```removeHydrides = true``` and ```removeHydrides = false```
Added tests that ```removeAllHs()``` also removes hydrides
Exposed ```removeHydrides``` parameter to python

* Explicity Added removeHydrides=true in removeAllHs
Corrected typo for removeHydrides

* make formatting consistent

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
2020-05-19 14:12:53 +02:00
Ric
66a38d3751 Address build warnings (#3082)
* do not throw in desctructor

* remove unused var; reserve

* provide operator= for DiscreteValueVect

* provide operator= for SparseIntVect

* remove unknown 'omp' #pragmas; refactor loop

* remove unused var

* remove unused variables

* give EmbeddedAtom a default constructor & early exit on self assignç

* handle unused vars/args

* catch exception by ref

* address unused args

* fix signed type comparison; refactor extra checks

* remove unused variable

* suppress switch fallthtough warning

* handle signed type comparison

* handle signed type comparison

* potentially uninitialized vars

* fix abs() of bool

* unused vars in catch statements

* remove unused variables

* python::list returns will be copied

* give ValidationMethod constructor & virtual destructor

* remove extra semicolon
2020-04-17 14:40:15 +02:00
Greg Landrum
d41752d558 run clang-tidy with readability-braces-around-statements (#2899)
* run clang-tidy with readability-braces-around-statements
clang-format the results
clean up all the parts that clang-tidy-8 broke

* fix problem on windows
2020-01-25 14:19:32 +01:00
Greg Landrum
a32016d665 Fix #2848: add options to control removeHs (#2872)
* backup commit; won't even compile

* backup commit

* Fixes #2848

* A few changes
- add a bunch of tests
- some fixes
- add ROMol version to API

* add python wrapper and associated tests

* add RemoveAllHs()

* changes in response to review
- add removedMapped option
- add docstrings for options

* changes in response to review
2020-01-16 16:48:43 +01:00
Eisuke Kawashima
5cd27a242f Fix typo (#2862)
* Fix typo

* Reflect the comments

* Fix more typos
2019-12-31 06:43:27 +01:00
Greg Landrum
66a53bc3f7 Fixes #2782 (#2783)
* Fixes #2782

* update in response to review
2019-11-15 16:46:55 +01:00
Greg Landrum
02cff7dfe4 Fix #2722 and #2721 (#2723)
* Fixes #2722

* Fixes and tests #2721
2019-10-17 11:35:32 -04:00
Greg Landrum
d8c49e6dab Code cleanups from PVS/Studio (#2531)
* first round of cleanups based on PVS-studio suggestions

* a couple more

* a few more cleanups

* another round of cleanups

* undo one of those cleanups
we want the integer rounding behavior here

* add a comment to make that clear

* Fix for filter catalog PRECONDITION redundancy
2019-07-13 07:25:37 +02:00
Greg Landrum
26c07e67d6 fixes #908 (#2328)
Code is a mess and really should be refactored
2019-03-10 21:43:20 -04:00
Greg Landrum
069e920645 Fixes #2224 (#2234)
* Fixes #2224

* test the basics
2019-01-21 11:31:02 -05:00
Greg Landrum
17323d11bf Modify removeHs so that it does not remove degree 0 atoms (#2089)
* Modify removeHs so that it does not remove degree 0 atoms
Update the docs at the same time.

* include a warning when not removing some Hs

* clear up a problem with the warning log
2018-10-05 13:43:09 -04:00
Greg Landrum
ffc123a665 Fixes #2062 (#2079) 2018-10-02 11:41:22 -04:00
Dan N
8bed437c5f Addresses several minor warning messages during the build (#1935)
* Address minor compilation warning messages

Addresses trivial compilation warning messages:

    [ 11%] Building CXX object Code/GraphMol/CMakeFiles/GraphMol.dir/AddHs.cpp.o
    rdkit/Code/GraphMol/AddHs.cpp:497:9: warning: unused variable 'dblBond' [-Wunused-variable]
      Bond *dblBond = nullptr;
            ^
    1 warning generated.

    [ 11%] Building CXX object Code/GraphMol/CMakeFiles/GraphMol.dir/Chirality.cpp.o
    rdkit/Code/GraphMol/Chirality.cpp:1738:62: warning: unused parameter 'mol' [-Wunused-parameter]
    bool isBondCandidateForStereo(const Bond *bond, const ROMol &mol) {
                                                                 ^
    1 warning generated.

    [ 44%] Building CXX object Code/GraphMol/CMakeFiles/graphmolMolOpsTest.dir/molopstest.cpp.o
    rdkit/Code/GraphMol/molopstest.cpp:4694:12: warning: unused variable 'nm' [-Wunused-variable]
        ROMol *nm = MolOps::renumberAtoms(*m, nVect);
               ^
    rdkit/Code/GraphMol/molopstest.cpp:6941:16: warning: unused variable 'm' [-Wunused-variable]
            RWMol *m = SmilesToMol(smiles);
                   ^
    2 warnings generated.

    [ 42%] Building CXX object Code/GraphMol/CMakeFiles/graphmoltestPicklerGlobalSetting.dir/testPicklerGlobalSettings.cpp.o
    rdkit/Code/GraphMol/testPicklerGlobalSettings.cpp:257:14: warning: unused parameter 'argc' [-Wunused-parameter]
    int main(int argc, char *argv[]) {
                 ^
    rdkit/Code/GraphMol/testPicklerGlobalSettings.cpp:257:26: warning: unused parameter 'argv' [-Wunused-parameter]
    int main(int argc, char *argv[]) {
                             ^
    2 warnings generated.

    [ 55%] Building CXX object Code/GraphMol/FilterCatalog/CMakeFiles/FilterCatalog.dir/FunctionalGroupHierarchy.cpp.o
    rdkit/Code/GraphMol/FilterCatalog/FunctionalGroupHierarchy.cpp:176:20: warning: unused variable 'NUM_FUNCS' [-Wunused-const-variable]
    const unsigned int NUM_FUNCS =
                       ^
    1 warning generated.

    [ 84%] Building CXX object Code/GraphMol/StructChecker/CMakeFiles/StructChecker.dir/ReCharge.cpp.o
    rdkit/Code/GraphMol/StructChecker/ReCharge.cpp:405:17: warning: unused variable 'atom' [-Wunused-variable]
        const Atom &atom = *Mol.getAtomWithIdx(i);
                    ^
    1 warning generated.

    [ 84%] Building CXX object Code/GraphMol/StructChecker/CMakeFiles/StructChecker.dir/Tautomer.cpp.o
    rdkit/Code/GraphMol/StructChecker/Tautomer.cpp:61:12: warning: comparison of integers of different signs: 'int' and 'unsigned int' [-Wsign-compare]
        if (-1 == ti || -1 == tj) continue;
            ~~ ^  ~~
    rdkit/Code/GraphMol/StructChecker/Tautomer.cpp:61:24: warning: comparison of integers of different signs: 'int' and 'unsigned int' [-Wsign-compare]
        if (-1 == ti || -1 == tj) continue;
                        ~~ ^  ~~
    2 warnings generated.

    [ 88%] Building CXX object Code/GraphMol/RGroupDecomposition/CMakeFiles/testRGroupDecomp.dir/testRGroupDecomp.cpp.o
    rdkit/Code/GraphMol/RGroupDecomposition/testRGroupDecomp.cpp:428:9: warning: unused variable 'res' [-Wunused-variable]
        int res = decomp.add(*mol);
            ^
    1 warning generated.

    [ 96%] Building CXX object Code/SimDivPickers/CMakeFiles/testSimDivPickers.dir/testPickers.cpp.o
    rdkit/Code/SimDivPickers/testPickers.cpp:19:10: warning: using integer absolute value function 'abs' when argument is of floating point type [-Wabsolute-value]
      return abs((double)i - (double)j);
             ^
    rdkit/Code/SimDivPickers/testPickers.cpp:19:10: note: use function 'std::abs' instead
      return abs((double)i - (double)j);
             ^~~
             std::abs
    1 warning generated.

* Close open file handles during build set-up

Under Python3, the update_pains.py file generated warning
messages like:

    == Done updating pains files
    /Code/GraphMol/FilterCatalog/update_pains.py:140: ResourceWarning:
unclosed file <_io.TextIOWrapper
name='/Code/GraphMol/FilterCatalog/../../../Data/Pains/wehi_pains.csv'
mode='r' encoding='UTF-8'>
      for smiles, name in csv.reader(open(PAINS_CSV)):
    /Code/GraphMol/FilterCatalog/update_pains.py:169: ResourceWarning:
unclosed file <_io.TextIOWrapper
name='/Code/GraphMol/FilterCatalog/pains_a.in' mode='r'
encoding='UTF-8'>
      t = open(filename).read()
    /Code/GraphMol/FilterCatalog/update_pains.py:169: ResourceWarning:
unclosed file <_io.TextIOWrapper
name='/Code/GraphMol/FilterCatalog/pains_b.in' mode='r'
encoding='UTF-8'>
      t = open(filename).read()
    /Code/GraphMol/FilterCatalog/update_pains.py:169: ResourceWarning:
unclosed file <_io.TextIOWrapper
name='/Code/GraphMol/FilterCatalog/pains_c.in' mode='r'
encoding='UTF-8'>
      t = open(filename).read()
2018-06-26 13:57:22 -07:00