Commit Graph

99 Commits

Author SHA1 Message Date
Ricardo Rodriguez
680520e0ad Follow up to PR #8968 (#9168)
* implement consistency check

* add more consistency checks

* check direction consistency accross double bond

* clean up directions for non-stereo bonds

* fix counts for second from atom dirs; add check

* handle inconconsistent bond dirs

* add more tests, pubchem cases, and update existing

* drop statics

* fix typo

* make sourceBond arg const

* fix consistency check
2026-03-20 04:28:17 +01:00
Ricardo Rodriguez
f6348578b9 More refactoring in Canon.cpp (#9155)
* dir counts -> vector of char

* cycles: unused

* move ringStereoChemAdjusted

* move and change cyclesAvailable type

* fix tcolor duplication

* move nSwaps

* nix directTravList, cycleEndList

* make cyclesAvailable a bitset

* minor stuff

* make bondDirCounts, atomDirCounts int8_t
2026-03-12 05:54:20 +01:00
Greg Landrum
1e1e734708 Fixes #9144 (#9159)
* Fixes #9144
needs more review;

* remove debugging
a bit more fixing

---------

Co-authored-by: = <=>
2026-03-09 09:07:54 +01:00
Ricardo Rodriguez
46a4f59048 Small refactor before PR #8968 follow up (#9135)
* done

* remove unused arg

* restore parenthesis

* more refactoring

* make checks even stricter

* don't use a string_view
2026-03-01 07:24:59 +01:00
Ricardo Rodriguez
5f1bfa1f78 don't increment counts before checking them (#9136) 2026-03-01 07:19:21 +01:00
Ricardo Rodriguez
d5aa90e18f Fix for issue #8965 (#8968)
* add a test

* change stereo bond canonicalization

* update canonicalization watch test with fixed cases

* make canonicalization test stricter (compare CIP codes)

* add reverse symmetry condition

* rewrite double bond canonicalization code

* update tests

* fix multiline comment

* update java tests

* update python test

* nix switchBondDir (unused)

* fix and rename flipBondDir

* refactor comment

* fix shadowed var name, casting

* fix neighbor sorting

* make seen_bonds a vector

* abstract setDirectionFromNeighboringBond

* handle both sides of the bond have directions

* move getNeighboringStereoBond

* check seen_bonds after popping connectedBondsQ

* use references for arguments

* add release note

* add example required by Dan

* add example requested by Dan
2026-02-26 08:58:36 +01:00
Ricardo Rodriguez
dfb34ec23c Another canonicalization fix (#9082)
* update canonicalization test

* fix
2026-02-05 17:24:20 +01:00
Ricardo Rodriguez
d4641c1f58 Fix removing (non)redundant bond dir specs when exporting SMILES (#9066)
* increase counts to avoid removing non-redundant bond dirs

* update tests
2026-01-24 07:15:00 +01:00
Ricardo Rodriguez
1c16a91730 Some more cleaning up in SMILES Writing (#8991)
* refactor getting initial bond directions

* fix atom dir counts

* move lambdas to separate functions

* restore increments

These are ok: they mean how many double bonds care about this direction,
not just whether it has been set or not.
2025-12-29 07:00:45 +01:00
Ricardo Rodriguez
b6655a136d Refactor atomVisitOrders and bondVisitOrders in SMILES Writer canonicalization (#8972)
* refactor calculation of atomVisitOrders/bondVisitOrders

* refactor checkBondsInSameBranch

* fix
2025-12-12 14:07:26 +01:00
Ricardo Rodriguez
39c4083bbf Minor clean up in SMILES Writing double bond canonicalization (#8971)
* move firstVisitOrder into lambda

* remove extra bond switch

* modernize loop
2025-12-03 17:38:56 +01:00
Greg Landrum
fa048eacc5 Replace GetImplicitValence() and GetExplicitValence() with GetValence() (#7926) 2025-01-28 21:09:03 +01:00
Hussein Faara
f35e7e6414 remove no-op macros and dead code (pt 1) (#8012) 2024-11-19 04:31:56 +01:00
John Mayfield
2553cfce73 Improved handling of SP/TB/OH reording in SMILES/SMARTS. (#6777)
* Improved handling of SP/TB/OH reording in SMILES/SMARTS.

- add a getMaxNbors(tag) utility function to avoid repeated logic in multiple places
- tweak getChiralPermutation() for handling implicit/missing ligands (uses -1), allow inverse lookup
- use the tweaked chiral ordering in the reading/writing from SMILES

* clang-format run

* Reviewer requested changes.
- curly braces on all if conditions
- null check raw pointers with precondition.

* Correct additional test case introduced in the last year
2024-10-21 04:55:08 +02:00
Yakov Pechersky
ad4ee83aec Fixes #7044 (#7137)
* oxime tests

* Support allenes in canonicalizing double bonds

* alternate solution to the problem

* expand comment

* reactivate conjugated nitro test

* Fix conjugated nitro tests, have a bondstereo test

* Empty commit to re-proc tests

---------

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
2024-10-18 05:32:20 +02:00
tadhurst-cdd
0de215a1f8 Fix canonicalization of stereogroups (#7041)
* 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

* test changes

* 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

* Merge branch 'master' into pr/specialQueries

* changes from previous PR

* Iclude false chiral

* rigorous enhnced stereo canoncalization

* Added more tests and clenup

* removed commented out code

* corrected init of SmilesWriteParams

* added MolFileStereoChem.h to the header files

* Renamed Rxn parser to MrvBlockToChemicalReaction

* To make catch2 work, and match the checksum

* Fixed Structchecker errors

* fix CI for DetermineBonds catch test

* error in catch_test for CI

* Allow custom  smileWriteParams  in GetMolLayers

* misnamed entry point

* ReactionFromMrvString change name

* remove adding writeParams to GetMolLayers

* make rigorous enhanced stereo the default, and fix tests

* only one abs group no longer needs Rigorous Enhanced treatment

* changed string_view to string in catch test

* Canonicalize Enhnaced Stereo only resturne unique smiles

* Now allows or and and groups together

* internal routines inside detail scope

* fix test error

* changed string back to string_view and fixed a CHECK

* Fixes for PR review tests

* Fix RDKit_Book.rst failure on build test

* fix xqm sql test

* updated expected files for cxsmiles_test

* Fixed removal of atom attrs

* Fixed tests after merge of master

* More efficient version of Stereo Groups Canonicalization

* Fixes for ctests

* removed debug code

* readded cipLabel test

* fix generalizedSubstruct/catch_tests.cpp error

* hueristics to improve speed

* Rationaized control of abs groups

* removed unused routine

* added rigorous stereo group treatment to test

* some suggested changes

* Changes per PR review and removed some changes to smiles

* Fixed CI errors

* changes per PR review

* more PR review vhanges and cleanup

* Fixed PSql PKL change

* changes as per PR review

* Restored error type for bad mols for canonicalizeStereoGroups and added a test

* Merge master and fix test in MolDraw2D

* Fix for randomize test error and other PR review comments

* Removed unsued variable to fix mac CI

* do not force aromatization in canonicalizeStereoGroups

* changes as per PR review

---------

Co-authored-by: greg landrum <greg.landrum@gmail.com>
2024-10-11 17:09:18 +02:00
Ric
3058ec4db8 Fixes #7023 (#7136)
* reset to master, delete check

* add the test
2024-02-06 15:57:21 +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
Greg Landrum
c9a46b34bc Fixes #6975 (#6972) 2023-12-11 17:40:30 +01:00
Ric
aa02c9afb0 Fixes #6633 (#6643)
* add a test

* add fix

* ignore incorrect stereo bonds from inchi
2023-08-23 06:18:14 +02:00
Ric
6b7c2e0488 Add a "rootedAtAtom" to MolToSmarts (#6581) 2023-08-19 19:17:45 +02:00
Ric
d033aee043 Optionally forward Enhanced Stereo Group ids (#6560)
* add id members to StereoGroup class

* add optional read id argument to StereoGroup constructors

* add functions forward Stereo Group Ids and assign the missing ones

* update ops updating stereogroups to forward read id

* update CX Smiles to parse/write stereogroup ids

* Add test cases for stereo group id forwarding/canonicalization

* update mol block (V3K only) to parse/write stereogroup ids

* update pickling to parse/write stereogroup ids

* update cdxml parser to store stereogroup ids

* update mol interchange to parse/write stereogroup ids

* update draw code with new stere group ids

* update test

* add some tests

* Update Code/GraphMol/Wrap/rdmolfiles.cpp

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

* Update Code/GraphMol/Wrap/rdmolfiles.cpp

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

* Update Code/GraphMol/Canon.cpp

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

* Update Code/GraphMol/SmilesParse/CXSmilesOps.cpp

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

* review

---------

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
2023-07-27 18:53:40 +02:00
Greg Landrum
a57060225f Fixes #6479 (#6482)
* make sure we don't try to access an SG which no longer exists

* Fixes #6479
updates a bunch of tests to support this

* test ring stereo too

* update expected results from the tests
2023-07-13 19:29:06 +02:00
Greg Landrum
a8c8e9a8e1 Add canonicalization of stereo groups (enhanced stereo) (#6051)
* add function to canonicalize enhanced stereo representations

* use enhanced stereo in canonicalization

* Fixes #6045
enables the doc tests for EnumerateStereoisomers.py
Re-enables the BRICS tests

* some things work... tests need to be updated

* c++ and python tests pass

* update expected psql results

* run the canonicalization on SMILES generation;
c++ and python tests pass

* cartridge and java tests pass

* update doctests
2023-02-08 04:21:51 +01:00
Greg Landrum
e322928028 swap boost::tuple to std::tuple (#5851) 2022-12-16 16:01:19 +01: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
Greg Landrum
939d8c3c02 Move to C++17 (#5155)
* bump to c++17

* remove binary_function

* update our boost::hash implementation too
2022-04-12 13:53:07 +02:00
Eisuke Kawashima
ba6d8e0d3b clang-tidy: readability-simplify-boolean-expr (#4639) 2022-03-17 13:50:50 +01:00
Greg Landrum
e8252f3662 Fixes #4582 (#4587)
* Fixes #4582

The extra new tests are failing, that's not great, but maybe acceptable.
This processes all of ChEMBL27 with only one difference relative to
2021.03.1: CHEMBL3623347
Looking into that now, but want to backup the current status first

* a bit of tweaking of the test

* this version now passes with all ChEMBL molecules

* a bit of cleanup

* trying to get the ubuntu cartridge CI builds working again

* is it psql 14?

* trying to force a build
2021-10-08 05:19:43 +02:00
Greg Landrum
df72c241c5 Improve test coverage and some bug fixes (#4536)
* test getIdOfEntryWithBitId()

* remove unused functions

* improve bv tests in python wrapper

* more UniformGrid tests

* improve deprotect coverage

* improve abbreviations coverage

* add operator!= to DeprotectData

* more testing for adjustQueryProperties

* fix a copy-paste bug

* copy-paste bug

* more testing

* more testing

* more testing

* fix an edge case bug in getValenceContrib

* more bond tests

* add operator!= to StereoInfo
tests StereoInfo::operator==

* make some internal functions testable

* more testing

* minor code cleanup

* fix some bad caching behavior in getDistanceMat() and get3DDistanceMat()

testing

* test FixeMolSizeMolBundle() copy ctor

* deprecate BalabanJ

* more testing

* testing

* mods to get things working for windows DLL builds
(don't bother running some of the tests there)

* fix a typo
2021-09-26 07:45:06 +02:00
Greg Landrum
69b143edd0 Swap from RDUNUSED_PARAM to unnamed parameters (#4433)
* cleanup

* more cleanup
2021-08-24 17:19:46 -04:00
jfkonecn
145c3891ff added a flip bond dir function to remove repeated code inside the canonicalizeDoubleBond function (#4204) 2021-06-04 17:37:32 +02:00
jfkonecn
4f0521e116 fixes #3967 (#4190)
* fixes #3967

* modernize test

Co-authored-by: greg landrum <greg.landrum@gmail.com>
2021-06-03 05:13:13 +02:00
Greg Landrum
edd922c99c Cleanup warnings from clang-10 (#3238)
* stop returning local memory in exceptions

* remove a couple unnecessary copies in loops

* fix a bug in the way the default MMFF aromatic parameters are constructed

* remove a bunch of loop-variable warnings

* remove a bunch of clang warnings

* disable clang warnings in python wrappers

* remove some warnings when building the python wrappers
2020-06-19 17:16:22 -04: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
1dc9ac3fbf adds a one-liner for getting a vector of random smiles for a molecule (#3002)
* first pass at random smiles vector; c++ version

* add python wrappers for that

* Remove accidental change

* switch to using a cross-platform reproducible RNG
2020-03-12 13:10:29 -04:00
Greg Landrum
9991c5247a cleanup of the SMILES/SMARTS parsing and writing code (#2912)
* first cleanup

* next round of changes. all tests pass

* Fixes #2909

* Fixes #2910

* further cleanup

* some cleanup/refactoring of the Dict class

* remove now extraneous calls to hasProp() before clearProp()

* minor refactoring of RDProps.h

* Switch from using our own version of round() to std::round()

* replace some boost::math stuff with the equivalents from std::

* cleanups in SmartsWrite

* refactor out a bunch of duplicated code

* fix an instance of undefined behavior

* changes in response to review
2020-01-29 15:13:39 +01: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
Ric
bb3bdb01ea Fix some chirality issues in SMARTS writing/parsing (Issues #2565 & #2568) (#2570)
* forward doIsomericSmiles

* added test for #2565

* fix for my snippet

* update test with Greg's comments

* add braces for readability to MolMatchFinalCheckFunctor

* small refactors: abstract label checking, while/size, final check

* merge loops reading order of bonds -- all tests pass

* fix chiral-lead fragments, allow frags w. degree < 3

* add new test, update old

* add test, update old

* fix (inocuous) bug with ranks assignment in MolToSmarts

* start SMARTS with first non-chiral atom

* use smart pointers in test

* reenable doIsomericSmiles

* update patch for #2594

* remove faulty fragments matching

* review tests, remove wrong flip
2019-10-03 15:33:46 +02:00
Ric
06f79666c1 Use the same criteria to flip chiral atoms in SMILES parsing/writing (Fixes #1028) (#2600)
* symmetrize SMILES read/write chirality flipping

* fix bad escape

* fix test ???

* add a test

* add mol in #1028

* fix sequence test: consider imp. valence in chiral flip decision

* restore Code/GraphMol/Wrap/rough_test.py
2019-08-15 07:47:27 +02:00
Ric
5b23830425 Fix to Issue #2023 (Canonizalizer assumed directed bond must be reversed) (#2598)
* fix

* update test, add mol from #2023
2019-08-12 11:52:59 +02: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
Brian Kelley
373a89021e Change boost int types to std types (#2233) 2019-01-22 17:45:03 +01:00
guillaume godin
d58197f4a2 Fix #2042 allowing python/c++ randomizer smiles generator (#2059)
* Fix #2042 allowing python/c++ randomizer smiles generator

* adding rootAtAtoms randomness

* add the minor change to bypass rules if doRandom

* Add another point of randomness (the initial choice had been missed)
Make the tests cross-platform. Hopefully
2018-10-08 11:09:42 +02: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
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
e625c58bab Add cis/trans tags to double bonds (#1316)
* add cis and trans to bond stereo

* compiles, does not work

* tests all pass

* Whitespace cleanup to recent changes.

* C++ test case for Bond::setStereo using Bond::STEREOCIS and Bond::STEREOTRANS

* Adding a PRECONDITION to Bond::setStereo to make sure the stereo atoms
are already specified if CIS or TRANS is being specified.

E/Z is technically defined by the topology of the molecule so the
stereo atoms are redundant (easier to understand and use!), but
ultimately redundant with the graph. However, CIS and TRANS is _only_
defined in this usage as the orientation of the atoms in the
getStereoAtoms vector.

* Exposing Bond::setStereo to Python and adding test cases to make sure
it can be used to set CIS/TRANS stereochemistry.

* verify substructure matching works

* Adding Bond::setStereoAtoms to C++ Bond class.

This allows setting the atoms to be considered for CIS or TRANS
directly without a much more costly determination of ranking that E/Z
requires.

* Wrap Bond::SetStereoAtoms into python with a new type of test case.

* docs
2017-02-26 08:15:44 -05:00
Brian Kelley
2debdfde0d Adds RDAny (smaller generic holder) Updates all used dictionaries (#896)
* Adds RDAny (smaller generic holder) Updates all used dictionaries

This is an API compliant version of the current rdany system,
but uses a lot less memory in practice.

* Removes code duplication

* Converts CHECK_INVARIANT to TEST_ASSERT

* Fixes DoubleTag issue

* Adds Bool to DoubleMagic implementation

* Removes reference to property pickler
2016-05-29 17:04:21 +01:00
kelley
5dbec2fe85 Adds rdcasts where appropriate 2015-11-29 17:52:27 -05:00