85 Commits

Author SHA1 Message Date
Eisuke Kawashima
e89c9f656a style: apply readability-braces-around-statements (#8136)
Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
2026-02-09 12:10:50 +01:00
Greg Landrum
adf72c984f 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-07 14:41:01 +01:00
Ricardo Rodriguez
fbf4990709 Fixes a leak in ChemDraw code (#8828)
* clang format

* refactor code

* fix typos

* do not leak bonds when deleting in batch mode

* check sizes
2025-10-02 06:04:24 +02:00
Greg Landrum
21d694e88a fix a problem with stereogroups involving bonds and getMolFrags() (#8558)
This is a continuation of #8542
2025-05-27 16:43:20 +02:00
Greg Landrum
86141183c1 Moving towards getting all tests to pass when using the new stereo code (#8409)
* Fixes #8379

* check in some working tests

* test passes

* test passes

* test passes

* test passes

* test passes

* ensure that the invariants flush the streams on failure

* tests pass

* test passes

* tests pass

* tests pass

* tests pass

* tests pass

* tests pass

* tests pass

* tests pass

* tests pass

* tests pass

* tests pass

* tests pass

* tests pass

* tests pass

* tests pass

* Fixes #8391

* tests pass

* fix a test with legacy
not clear why this was not causing problems before

* make a test work

* Fixes #8396

* gcc builds work

* fingerprint tests pass

* mention backwards incompatible change

* fix a problem with FindMolChiralCenters

* more testing details

* enable the test status output

* Fixes #8432

fix a bug in double-bond stereo handling for template matching

* all depictor tests pass

* use the new-stereo chiral ranks in the depiction code

* always assign new-stereo chiral ranks

* make _ChiralAtomRank a computed property
This is analogous to _CIPRank

* tweak to the way the atom ordering is computed for 2D coordinate generation

* update two expected results

* backup

* response to review

* tests pass

* tests pass

---------

Co-authored-by: = <=>
2025-04-15 14:00:32 +02:00
Paolo Tosco
71c4103475 Suppress large amounts of 'BOOST_NO_CXX98_FUNCTION_BASE macro redefined' warnings in clang/emcc builds (#7747) 2025-03-29 20:04:58 +01:00
Paolo Tosco
7aca92b914 fix #7782 (#7783)
Co-authored-by: ptosco <paolo.tosco@novartis.com>
2024-10-03 06:52:34 +02:00
Ricardo Rodriguez
a085df44a5 Fix performance issue in PR 7327 (#7391)
* use references, skip batch remove if nothing to remove

* fix commitBatchEdit

* reword comment
2024-04-28 06:16:20 +02:00
Greg Landrum
6664dd7fe4 Some modernization of core GraphMol classes (#7228)
* simple modernization

* more

* done with RWMol for this pass

* the ROMol.cpp variant

* Atom

* minor change to bond

* simplify Conformer

* monomerinfo, queryatom, querybond

queryatom and querybond cpp files still need to be done

* typos

* revert a dumb change

* suggestion from review
2024-03-17 06:04:04 +01:00
Rachel Walker
94c902ba54 Postpone clearing computed properties until after all Hs removed (#7241) 2024-03-16 06:14:24 +01:00
Brian Kelley
499700ff1d optimize batch operations when editing molecules (#7145)
* Add private functions for batch removal of atoms/bonds

* Reset the unique_ptr not the bitvector

* Remove unused variable

* Forgot to reset stero atoms

* Remove unecessary post batch edit check

* Set min_idx to the number of bonds, this makes it a sentinel

* Don't need rdcast

* Responses to review

* Removed unused variable

* Add missing braces

* Consolidate bond removal loops

---------

Co-authored-by: Brian Kelley <bkelley@relaytx.com>
2024-03-05 16:03:34 +01:00
Ric
ae4a7dbf1f Fixes #7064 (#7141)
* insert stereogroups

* insert Substance Groups

* fix ownership, bond indexes

* add test

* fix comparison signednedss

* update test

* Brian's suggestion

* allow more than one ABS group
2024-02-22 06:46:39 +01:00
Ric
8dae48b7a1 Fixes #7128 (#7129)
* update explicit Hs on bond replacement

* add a test
2024-02-04 06:40:31 +01:00
tadhurst-cdd
eb2606d617 fragmentation of mol loses any sgroups (#7056)
* fragmentatin of mol loses any sgroups

* removed unneeded test

* Fixes #7071

* simplification. tests do not pass

* Changed test for sgroup retention as per PR review

* Fix testing errors

* attempt to get CI windows to build

* removed files incorrectly committed, and removed code no longer needed

---------

Co-authored-by: greg landrum <greg.landrum@gmail.com>
2024-01-25 13:32:55 +01:00
tadhurst-cdd
d5d4d194ec atropisomer handling added (#6903)
* atropisomer handling added

* fixed non-used variables,  linking directives

* BOOST LIB start/stop fixes, linking fix

* Fixes for RDKIT CI errors

* minimalLib fix

* changed vector<enum> for java builds

* check for extra chars in CIP labeling

* removed wrong deprecated message

* fix ostrstream output error?

* restored _ChiralAtomRank to lowercase first letter

* changes for merged master

* Fixed catch label for new Catch package

* update expected psql results

* get swig wrappers building

* restore MolFileStereochem to FileParsers

* fix java wrapper for reapplyMolBlockWedging

* some suggestions

* move a couple functions out of Bond

* Merge branch 'master' into pr/atropisomers2

* merged master

* Renamed setStereoanyFromSquiggleBond

* atropisomers in cdxml, rationalize atrop wedging, stereoGroups in drawMol

* fix for CI build

* attempt to fix java build in CI

* attempt to fix java build in CI #2

* New routine to remove non-explicit  3D-geneated chirality

* changed to use pair for atrop atoms and related bonds

* Changes as per PR reviews

* PR review respnses

* PR review reponse - more

* Fix merge from master

* fixing java ci after merge

* Updated the help doc for atripisomers

* update the atropisomer docs

* improve the images

* add the source CXSMILES

---------

Co-authored-by: greg landrum <greg.landrum@gmail.com>
2023-12-22 04:58:18 +01:00
Brian Kelley
ee8c35a236 Removing stereoatoms requires removing CIS/Trans stereo flags (#6901)
* Removing stereoatoms requires removing CIS/Trans stereo flags

* Added test when removing nbrs of cis/trans bonds

---------

Co-authored-by: Brian Kelley <bkelley@relaytx.com>
2023-11-21 08:01:37 +01:00
thomp-j
7053e97a15 Fix vulnerabilities found by fuzzer. (#6579)
* Fix vulnerabilities found by fuzzer.

* Fix Typo in RWMol.cpp

* Update RWMol.cpp

This is an attempt to double check where the test failure is coming from.

* Update RWMol.cpp

Re-adding changes to test tests.
2023-08-06 06:33:08 +02:00
David Cosgrove
5fe20d270f Improved handling of organometallics (#6139)
* First stab at disconnecting organometallics the Syngenta way.

* Add support for Li and Na compounds, with tests.

* Correct docstrings.

* Add -1 valence to sodium.

* Add changes from PR 5997.

* Move declaration of disconnectOrganometallics.

* Re-factor tests for disconnectOrganometallics to read V3000 files rather than hard-code in file.

* Add optional options to constructor.

* Python wrapping for disconnectOrganometallics.

* Python tests.

* Correct docString.

* Test using in place overload of disconnect free function.

* options_ should not be a reference.

* Re-work the wrappers.

* Added test MOL files.

* Correct charge on iron atoms.

* Fix tests for charged iron.

* Added some more test complexes.

* Port Marco's oxidation number Python to C++ Descriptor.

* Rename functions.

* Another test.

* Python wrappers.

* Comment in test.

* Throws exception if atom-based function called with non-kekulized parent.

* Fix typo.

* Allow potassium as well.

* Whole molecule calculations for oxidation number only.
Rename prop to OxidationNumber.

* Add OxidationNumber to common_properties.

* Extra comment.

* When deleting atom, update any ENDPTS props on bonds.
Copied in from stale PR ExtraDoc.

* Added hapticBondsToDative with python wrapper.

* Extra test.

* Re-factor endpts parsing.

* Typo.

* Add function for haptic end points inc. Python wrapper.

* Add dative bonds in separate step.

* C++ version of dativeBondstoHaptic.

* Update test mols.

* Python wrapper.

* Fix indents in Python test script.

* Corrected expected test result.

* Only do non-metal to metal conversion of single bond to dative if the explicit valence of the non-metal allows it.

* Fix test broken in a non-material way by previous change.

* Export for DLL.

* Remove redundant function declaration.

* Dave hates Windows.

* Move hapticBondEndpoints to Molops::details.

* And take it out of the Python wrappers.

* Run yapf on reformatted test script.

* Get the DLL builds going.

* addDativeBond -> addHapticBond.

* Batch edits.

* Position arithmetic.

* setQuery.

* Dummy positions for all confs.

* Fix tests for dummy positions for all confs.

* Move tests to catch_organometallics.cpp.

* Modern docString.

* Change member variable names.

* sProp length, bonus batchEdit.

* Add options object to disconnectOrganometallics.

* Tidied license.
Atom precondition.

* GetIntProp.

* Test opts aren't defaults.

* Python wrapper for disconnectOrganometallics with options.

* Minor edit.

* Slightly random attempt to fix Java build.

* Response to review.

* Another stab at the doc strings.

---------

Co-authored-by: David Cosgrove <david@cozchemix.co.uk>
Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
2023-03-18 04:36:38 +01:00
Alex Rebert
e2b0a850d7 Fix memory safety issues found by OSS-Fuzz (#4983)
* RWMol: replace atom in stereo groups

Fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=36998, a
use-after-free in initFromOther.

* Fix out-of-bounds write in iterateCIPRanks

If the rank has not changed in the current iteration, the cipEntries
vectors might not have increased in size. Accessing `numIts + 1`
resulted in an out-of-bounds write. This commit skip the cipEntries
update when the rank is unchanged.

Fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28660

* Fix use of uninitialized values in MolSGroupParsing

`stream >> count` may silently fail without an exception. In that case,
`count` was uninitialized but used. This commit initalizes `count` to 0,
as well as other variables that may be read without being initialized.

Fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25220
Fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25225

* Fix vector size cast in streamReadVec

In 32-bit systems, the implicit conversions from 64-bit to a 32-bit
size_t could lead to an underallocation of the vector. This would follow
by a out-of-bounds write while trying to populate the vector. Now, the
code throws an exception in case of a cast that would change the size.

Fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28034

* RWMol: improve atom replacement in stereo groups

This code is cleaner and more efficient.

* Add test for replaceAtom and stereo groups
2022-02-06 05:06:38 +01:00
Greg Landrum
58e6743df0 Fixes #4468 and #4476 (#4482)
* stop removing substance groups with replaceAtom()
change default for keepSGroups argument to replaceBond()

* enable logging output for the fileparserscatch

* basics of parsing SMARTSQ SubstanceGroups

* Fixes #4476
test coming in the next commit

* handle multi-atom SMARTS as recursive
more testing
Test #4476

* a bit of cleanup

* get the tests working

* additional testing

* Update Code/GraphMol/FileParsers/MolFileParser.cpp

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

Co-authored-by: Ric <ricrogz@users.noreply.github.com>
2021-09-05 05:43:13 +02:00
Greg Landrum
69b143edd0 Swap from RDUNUSED_PARAM to unnamed parameters (#4433)
* cleanup

* more cleanup
2021-08-24 17:19:46 -04:00
Ric
6b1a2eead3 Turn MRV_COORDINATE_BOND_TYPE data Substance Groups into coordinate bonds (#4299)
* add test

* add fix

* document wrapper

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
2021-07-07 06:13:17 +02:00
Greg Landrum
056efc8e55 RWMol cleanup (#4198)
- remove d_partialBonds data member - never used
- remove RWMol::destroy()  - redundant with ROMol::destroy()
2021-06-02 13:09:49 -04:00
Greg Landrum
caaa7406be Fixes #4127 (#4129)
Also adds fixes for some related problems I noticed while fixing this one.
2021-05-18 15:39:15 +02:00
Greg Landrum
92b52f1988 Fixes #4122 (#4123) 2021-05-10 08:45:06 -04:00
Greg Landrum
193f27730c make sure atom and bond bookmarks survive replaceAtom/Bond (#4033)
* make sure atom and bond bookmarks survive replaceAtom/Bond

* fixes oss-fuzz #30572

* fix possible memory-access error in error reporting

* more defensive deserialization

* switch that recursive smarts error handling to not use an exception
2021-04-16 04:54:09 +02:00
Greg Landrum
e69ab627e9 fix a leak in RWMol (#3970) 2021-03-24 20:16:00 +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
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
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
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
5a79190261 rename SGroup -> SubstanceGroup (#2375)
We leave the names of the bit connected with Mol files as SGroups, since that is
appropriate there, but the more generic pieces are renamed
2019-03-30 14:53:24 -04:00
Ric
d26d4b076e Support for parsing/writing SGroups in SD Mol files. (#2138)
* Implementation of SGroups

* remove sample files test

* update gitignore with test outputs

* fix RevisionModifier

* re-enable tests

* backup commit; things seem to work so far

* some refactoring; obvious s group tests pass now

* more refactoring

* everything now out of the public API

* not sure why this was still in there

* rename functions; all tests now pass

* remove getNextFreeSGroupId; readd comment in copy SGroups

* clang-format

* squash-merge current master

* squash merge master

* Address comments on PR

- Update to current master.
- Move SGroup parse time checks to SGroupChecks namespace.
- Store SGroups in ROMOl as vector<SGroups>.
- SGroup methods return referenes instead of pointers.
- Use atom/bond/sgroup indexes for properties instead of pointers.
- Have SGroups inherit from RDProps; move properties to RDProps.
- Remove trivial/unused methods.
- Add a link to the SD specification atop SGroup.h
2019-01-22 15:42:27 +01:00
Dan N
eaa44b40c2 Enhanced stereo read/write support in SDF files. (#2022)
* add a couple test files

* backup

* first pass at some theory documentatin

* it's a draft

* Update enhanced stereochemistry documentation

Adds initial target use case and caveats about the tentative
nature of the current implementation.

* Support read/write of molfile enhanced stereochemistry

This includes reading and writing of enhanced stereochemistry
from v3000 molfiles (sdf). Enhanced stereochemistry encodes
the relative configuration of stereocenters, allowing
representation of racemic mixtures and compounds with
unknown absolute stereochemistry.

It does not include:
* Python wrapping
* invalidation of the enhanced stereochemistry
* use of enhanced stereochemistry in search
* depiction of enhanced stereochemistry.

* Update to reflect changes from #1971

* change names of enum elements to allow compilation in VS2017

I think it's also clearer to do things this way

* Addressed most review comments.

* Run missed test "testEnhancedStereoChemistry"
* In tests, added size checks to group equality checks
* Updated copyright statements
* Deleted mol created for a test
* Use perfect forwarding in RWMol::setStereoGroups()
* use references for stereo groups that are checked in write and pickle
* Updated stereogroup.h in hopes of fixing compilation on Windows.
* clang-format

* try allowing a switch to boost regex and requiring it for g++-4.8

* do a better job of that

* typo

* Code review comments. Updated Copyright notice.

* When an atom is deleted, delete stereo groups containing it.

Also updates StereoGroup toUse accessors instead of
constant member attributes. This allows move of StereoGroups.

* RDKit style guide

* Add header required on Windows.

* get the SWIG wrappers to build
2018-09-26 15:44:23 +02:00
Greg Landrum
8a08c326e0 Fixes #1990 (#1992)
* Fixes #1990
makes sure we don't destroy a double bond's StereoAtoms just because a bond connected to one of its atoms is removed

* change in response to review
2018-08-13 09:03:21 -04:00
Greg Landrum
ba12d98ad0 Removes ATOM/BOND_SPTR in boost::graph in favor of raw pointers (#1713)
* Removes ATOM/BOND_SPTR in boost::graph in favor of raw pointers

* Actually delete atoms and bonds...

* RWMol::clear now calls destroy to handle atom/bond deletion

* Changes broken Atom lookup for windows/gcc

* Adds tests for running with valgrind

* Adds test designed for valgrind and molecule deletions

* Removes RNG, actually tests bond deletions

* update swig wrappers

* deal with most recent changes on the main branch
2018-01-07 14:19:47 -05:00
Greg Landrum
1efa8e696e another clang-format run 2017-10-12 06:42:15 +02:00
Greg Landrum
87786c08b5 Merge branch 'master' into modern_cxx
# Conflicts:
#	.travis.yml
#	Code/GraphMol/FileParsers/MolFileParser.cpp
#	Code/GraphMol/FileParsers/MolFileStereochem.cpp
#	Code/GraphMol/ForceFieldHelpers/UFF/testUFFHelpers.cpp
#	Code/GraphMol/MolAlign/testMolAlign.cpp
#	Code/GraphMol/MolDraw2D/MolDraw2D.cpp
#	Code/GraphMol/MolDraw2D/Wrap/rdMolDraw2D.cpp
#	Code/GraphMol/QueryOps.cpp
#	Code/GraphMol/ROMol.cpp
#	Code/GraphMol/SmilesParse/test.cpp
#	Code/GraphMol/Trajectory/Trajectory.cpp
#	Code/GraphMol/Wrap/Atom.cpp
#	Code/GraphMol/Wrap/Bond.cpp
#	Code/GraphMol/new_canon.cpp
#	Code/RDGeneral/testDict.cpp
#	Code/SimDivPickers/Wrap/MaxMinPicker.cpp
2017-10-05 05:58:38 +02:00
Brian Kelley
7488840ac4 Fix/urange check (#1506)
* Fixes atom documentation

* Fixes #1461

This is a complicated one.  Basically URANGE_CHECK when
used on unsigned integers has a problem when the size of
the range it’s checking is 0.  The standard operations is
to check

URANGE(num, size-1)

Which (for unsigned integers) obviously rolls over.

This fixes all usage cases to be

URANGE(num+1, size)

And fixes the bugs found.  (addBond and the mmff tests)

* Fixes #1461 - Updates URANGE_CHECK to be 0<=x<hi
2017-09-11 21:17:33 +02:00
Brian Kelley
6a76fc9381 Dev/add update props api (#1479)
* Adds RDProps updateProps API point

* AdjustQuery now copies over original atom data to the query ato

* Preserves existing data on the replacing atom

* Exposes preserveProps to Python replaceAtom/Bond
2017-07-10 04:38:59 +02:00
Brian Kelley
b76af93513 Dev/add update props api (#1479)
* Adds RDProps updateProps API point

* AdjustQuery now copies over original atom data to the query ato

* Preserves existing data on the replacing atom

* Exposes preserveProps to Python replaceAtom/Bond
2017-07-10 04:36:12 +02:00
Greg Landrum
915cf08faa run clang-format with c++-11 style over that 2017-04-22 17:19:10 +02:00
Greg Landrum
7c0bb0b743 clang-tidy output 2017-04-22 17:09:24 +02:00
Greg Landrum
59e6508d4f stop using getBondWithIdx() in removeBond() (#1363)
Fixes #1359
2017-03-12 10:07:17 -04:00
Brian Kelley
08be8d097e Removes exponetial numBonds behavior (#1154)
* Removes exponetial numBonds behavior

* Removes accidentally commited Get/SetName
2016-11-12 16:05:06 +01:00
Greg Landrum
1b946794f0 replaceBond and generic atoms and bonds in adjustQueryProperties() (#1141)
* first pass at RWMol::replaceBond()

* get ready for the changes

* rename some options
add bond options (not doing anything with them yet)
update tests to reflect new options

* backup

* re-enable the rest of the tests
2016-11-04 12:41:06 +01:00
Michał Nowotka
f70162a53b Bug when removing stereo info?
It's very possible, that I don't understand something (apologies) but shouldn't the second loop iterate over vertices adjacent to the second end of the bond being removed?
2016-06-20 16:40:33 +01:00
kelley
5dbec2fe85 Adds rdcasts where appropriate 2015-11-29 17:52:27 -05:00
Greg Landrum
e08e0d16d8 first pass, using google style 2015-11-14 14:58:11 +01:00