73 Commits

Author SHA1 Message Date
Emily Rhodes
3836049ab2 Add optional default_val parameter to GetProp() (#9242)
* SHARED-12256: Add test and change function.

* SHARED-12256: Update to only wrapping changes.

* SHARED-12256: Parameterize tests.

* SHARED-12256: GetPropIfPresent changes.

* Revert "SHARED-12256: GetPropIfPresent changes."

This reverts commit f598f8c161.

* SHARED-12256: Make default the keyword in the boost wrappings.

* SHARED-12256: Overload function instead of using a sentinel.

* SHARED-12256: Extend GetProp changes.

* SHARED-12256: Add entry point for tests and fix tests.
2026-05-06 06:09:11 +02:00
Greg Landrum
8e76c27784 Fixes #9117 (#9131) 2026-02-27 04:39:41 +01:00
Ricardo Rodriguez
86902488e9 Store CIP-ranked anchors after CIP labeling. (#9056)
* add the _CIPNeighborRanks property

* store CIP-ranked chiral neighbors

* store CIP-ranked SP2 bond and atropisomer anchors

* add a test

* boost headers in test

* add Atom::NOATOM

* add NOATOM test

* amend and clarify implicit H in Tetrahedral

* rename property

* rename property to _CIPNeighborOrder

* deprecate Chirality::StereoInfo::NOATOM
2026-01-29 18:23:44 +01:00
Philip Ullmann
c8f274f0d3 Update deprecation messages for valence methods (#9050) 2026-01-19 08:12:53 +01:00
Greg Landrum
20907d3ba9 Fixes #8877 (#8886) 2025-10-22 07:59:35 -04:00
Brian Kelley
d304f9f416 Trim spaces from RDProp strings to simulate reading from SDFiles (#8760)
* Trim spaces from RDProp strings to simulate reading from SDFiles

* Update documentation

* Use the correct doc strings

---------

Co-authored-by: Brian Kelley <bkelley@glysade.com>
2025-09-26 06:14:23 +02:00
Greg Landrum
9d4afd0e08 add clearPropertyCache() (#8533) 2025-05-18 08:14:05 +02:00
Dan Nealschneider
3facd882d6 Speed up GetProp Python keyerrors (#8372)
* Speed up GetProp Python keyerrors

A common pattern _in Python_ for checking for the presence or
absence of a key is:

    try:
       return mol.GetProp('mykey')
    except KeyError:
       return None

Shockingly, this is really slow with boost python objects! I was
recently profiling a workflow and 90% of the time or more was
spent in failed GetProp calls (mostly on bonds, some on atoms
or mols).

I sped up the workflow by protecting the calls using HasProp. But
I think this is a silly trap we've set for our users.

The problem comes because boost::python uses a C++ exception to
indicate that there is already a Python exception set. In C++,
exceptions are slow - they require unrolling a stack. In Python,
exceptions are about the same speed as any other control flow!

This commit speeds up GetProp failures by circumventing the
boost throw_exception_already_set() mechanism.

In my testing, this speeds up failed GetProp substantially:

* Factor of 1000x on Mac
* Factor of 40x on Linux

* Update typed GetXXXProp to bypass boost exceptions

Based on PR #8372

Updates the typed GetIntProp, GetDoubleProp, etc to bypass C++
exceptions in access. This speeds up missing key errors
significantly - for instance, calling mol. GetIntProp with a
missing prop 100,000 times:

Before: 28s
After:  0.05s
2025-04-07 13:55:22 +02:00
Greg Landrum
fa048eacc5 Replace GetImplicitValence() and GetExplicitValence() with GetValence() (#7926) 2025-01-28 21:09:03 +01:00
Brian Kelley
bd85b29d43 Fix #4570 Segfault on Property Getters/Setters (#8042)
* Fix #4570 Segfault on Property Getters/Setters

* Revert regression, response to review

* Remove print statement
2024-12-09 14:34:40 +01:00
Brian Kelley
0909d753b8 Fixes #7873 (#7885)
* Fixes #7873

* Resolve MonomerInfo class for deletion

* Add regression test for setMonomerInfo

---------

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
2024-10-11 06:42:52 +02:00
Ricardo Rodriguez
73e91a6344 Fixes #7318 (#7319)
* fix hybridization for atoms with outgoing dative bonds

* expose and wrap C++ numPiElectrons

* deprecate AtomPairs.Utils.NumPiElectrons

* add & update tests

* fix draw2d test

* update expected hash

* add hybridization test

* move numPiElectrons to Atom.h

* take reference instead of ptr
2024-04-03 15:34:37 +02:00
cdvonbargen
45c88e4e1e Add Atom::hasValenceViolation (Take 2) (#7030)
* Refactor Atom.cpp to create a hasValenceViolation method that uses existing valence checking code

* work without exceptions

* get rid of the snake_case

* put free functions in an unnamed namespace

---------

Co-authored-by: greg landrum <greg.landrum@gmail.com>
2024-01-18 05:06:57 +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
Paolo Tosco
c43f6d363a - enable building stubs in both in-tree and out-of-tree builds (#6980)
with cmake --build . --target stubs (also make stubs on *NIX)
- improved the patching script to do a better assignment of
  overloaded constructor parameters, whcih results in a number
  of docstring fixes

Co-authored-by: ptosco <paolo.tosco@novartis.com>
2023-12-13 04:49:34 +01:00
Paolo Tosco
2b4202867e Add Python modules to generate stubs and automatically patch docstrings (#6919)
* - added gen_rdkit_stubs Python module to generate rdkit-stubs
- added patch_rdkit_docstrings Python module to patch existing C++ sources to fix docstrings missing self parameter and add named parameters taken from C++ signatures where possible
- added rdkit-stubs/CMakeLists.txt to build rdkit-stubs as part of the RDKit build
- added an option to CMakeLists.txt to enable building rdkit-stubs as part of the RDKit build (defaults to OFF)

* fixed CMakeLists.txt, rdkit-stubs/CMakeLists.txt and a doctest

* - added missing cmp_func parameter
- fixed case with overloads with optional parameters
- do not trim params if expected_param_count == -1
- add dummy parameter names if we could not find any
- keep into account member functions when making up parameter names
- address __init__ and make_constructor __init__ functions
- fix incorrectly assigned staticmethods

* patched sources

* address residual few remarks

---------

Co-authored-by: ptosco <paolo.tosco@novartis.com>
2023-11-30 04:54:18 +01:00
Brian Kelley
ef234130f8 Optimize GetPropsFromDict: use tags for conversion (#6355)
* Optimize GetPropsFromDict, use tags for conversion, not the try and fail technique

* Autoconvert strings to ints and bools if possible

* Add autoConvert option to GetPropsAsDict default=true

* Update Code/GraphMol/Wrap/props.hpp

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

* change autoConvert to autoConvertStrings, add failed datatype conversion notices

* Fix Invariant usage

* Fix namespace for string

* Add GetProp(key, autoConvert) to allow for converting only what you want

* Make TestSetProps private

* Get _TestSetProps from rdmolops

---------

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
Co-authored-by: Brian Kelley <bkelley@relaytx.com>
2023-05-25 09:50:08 -04:00
Greg Landrum
1f4584b2ca run clang_format (#5676) 2022-11-01 04:14:26 +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
Rachel Walker
ef67ab6bb8 Added GetQueryType() to python query atom API (#4882)
* Added GetQueryType() to python query atom API

* Update Code/GraphMol/Atom.h

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

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
2022-01-20 04:09:37 +01:00
Greg Landrum
85608555fe add ROMol::atomNeighbors() and ROMol::atomBonds() (#4573)
* add ROMol::atomBonds() and ROMol::atomNeighbors() methods

* remove some warnings

* start using the new code

* add default for those template params

* some more applications

* get the SWIG builds working

* get rid of extraneous ref

* remove extraneous comments
2021-10-02 07:28:24 +02:00
Maximilian Greil
213f537edd Fixes Github issue 1631 (#3782)
* Fix Github issue 1631

* Typo
2021-02-09 13:44:08 +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
Greg Landrum
728a9e9ca0 Fixes #2639 (#2698)
Required some changes to the StereoGroups wrapper code too
2019-10-10 10:24:20 -04:00
Greg Landrum
bc0b177ceb Fixes #2450 (#2457)
* Fixes #2450
adds `hasOwningMol()` to the public API for Bond and Atom

* add to other classes;
add to python wrappers

* get the smiles generation partially working

* changes in response to review
2019-05-22 09:23:44 -04:00
Brian Kelley
46d68bbe67 Add ExplicitBitVect prop and query (#2384)
* Add ExplicitBitVect prop and query

* Fix for review comments
2019-04-03 04:46:14 +02:00
Dan N
3095d08cd1 Allow copying atoms in Python (#2322)
* Allow Atoms to be copyied in Python.

The dunder copy method is the idiomatic way to support
making copies in Python. Includes a test to make sure that
copied atoms are usable.

* Use RWMol in Code/GraphMol/Wrap/rough_test.py

Co-Authored-By: d-b-w <dan.nealschneider@schrodinger.com>

* Allow access to an atom's copy constructor in Python
2019-03-08 10:05:16 -05:00
Greg Landrum
fb5e325705 update docstrings in the wrappers too 2019-03-05 11:40:28 +01:00
Dan N
04c1234f11 Enhanced stereo python issue 2108 (#2121)
* Issue #2108: Read Enhanced Stereochemistry from Python

This wraps enhanced stereochemistry data for an ROMol for use
in Python and includes a test that demonstrates access.

* Adds test for potential memory management problems

(also fixes incorrect class name and bad docstring)

* Corrected file reading idiom and object lifetime test logic
2018-10-25 04:58:02 +02:00
Brian Kelley
bae005bd75 Dev/expose setquery to python (#2088)
* Expose SetQuery to python

* Add a default for maximum products generated by a reaction (maxProducts=1000)

* Add better documentation for test that used to raise exception

* properly import rdqueries
2018-10-08 22:26:52 +02:00
Greg Landrum
9277c1f578 Allow Atom.GetAtomSmarts() to return isomeric SMILES (#1902)
* Add more options to GetAtomSmiles() to control output.

The most important one here is that you can now directly control whether or not isomeric SMILES is generated.

Expand the python interface so that we have more control over Atom.GetSmarts()

* make the use of isomeric atomic smiles explicit (since we can)

* start release notes for 2018.09.1

* python formatting
2018-06-19 17:23:02 -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
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
Greg Landrum
769e6648e4 Fixes #1489 (#1556)
* move the describeQuery functions to the RDKit namespace.
They are generally useful

* Fixes #1489
2017-09-11 08:34:25 -04: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
fbeb88e341 Fixes #1352 (#1353) 2017-03-06 11:22:54 -05:00
Greg Landrum
278efc427c Fixes #1088 (#1096)
merging this myself because it's trivial
2016-10-12 08:20:43 +02:00
Greg Landrum
99efdd2bd3 Fixes #1041 (#1070) 2016-09-22 14:38:13 +02:00
Brian Kelley
ddf7c73b50 Adds Atom atom map and rlabel apis (#1004)
* Adds Atom atom map and rlabel apis

* Moves RLabels to their own namespace, adds other properties.

* Removes namespaces, liberally adds Atom to function names.

* move detail::computedPropName to RDKit::detail::computedPropName
2016-08-11 04:46:41 +02:00
Greg Landrum
d2d0071373 Fixes #955 (#956) 2016-06-24 07:42:46 -04: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
Brian Kelley
1b69b940a8 Converts RuntimeError to better described ValueError 2016-01-17 16:33:34 -05:00
Brian Kelley
5c398036da Adds GetPropsAsDict to Mol/Atom/Bond 2015-12-21 08:44:59 -05:00
Brian Kelley
ae49289a62 Changes GetUInt to GetUnsigned 2015-12-21 08:44:33 -05:00
Greg Landrum
e08e0d16d8 first pass, using google style 2015-11-14 14:58:11 +01:00
Brian Kelley
403a3d6b7c Suppresses Boost warnings 2015-10-18 13:41:03 -04:00
Greg Landrum
a743cff4d7 Fixes #573 2015-09-20 04:44:39 +02:00
Greg Landrum
797db2fa82 remove Atom::setMass() 2015-03-22 17:57:04 +01:00
Brian Kelley
93f31d07cd RDKit python API learns Atom/Bond Queries on properties
BondQuery was exposed to python
Atoms and Bonds can now set and Query String/Int/Bool
 and Double properties through python.
2015-03-11 23:22:35 -04:00