8 Commits

Author SHA1 Message Date
David Cosgrove
b04a861ae7 Replace combineMols with RWMol::insertMol. (#9319)
Co-authored-by: David Cosgrove <david@cozchemix.co.uk>
2026-06-02 14:38:14 +02:00
David Cosgrove
8ef091f306 Github9007 (#9022) 2025-12-29 21:08:10 +01:00
David Cosgrove
620a16108d Synthon Search Phase 2 (#8338)
* Function for converting text to db file.

* Do search looping first on reactions, then on fragments.

* Add lowMem mode so reactions are only read from database as required.

* Move fragment fingerprint generation out of the inner loop.

* Put positions of SynthonSets directly in DB file so no need to read the file on initialisation.

* Update test binary file.

* Fix SynthonSpace.summarise() for new loMem mode.

* Extra bits in Python wrapper.

* Correct docstring.

* Compute pattern fingerprints ahead of search.

* Put Synthons into hitsets.

* First stage of re-factoring SynthonSpace.  Synthons are highly duplicated in the SynthonSets, so are held centrally in a pool in SynthonSpace and just the pointers kept in the SynthonSets.  The same Synthon, identified by SMILES string, can have multiple IDs in the SynthonSets so the ID is now held by the SynthonSet not the Synthon.

* Second stage - moved the synthon FPs into the Synthon as well.

* New binary file format.

* Tidying and fix because Synthons are shared across SynthonSets.

* Use shorter fingerprints for synthons.

* Don't exit with a bad file.

* Back out the fingeprint folding which made things worse.
Don't copy the synthon molecules into the hit sets, just take a pointer.
Put the fragments into the corresponding hit set, useful for debugging.

* Change way hit names are made to the manner preferred by Enamine.

* Only generate query connector regions once.

* Do some of the connector region checking by SMILES.

* Move where it gets the connector combinations so it's not done unnecessarily often.

* Fix tests.

* Don't make molecules for the connector combinations, a bitset is plenty.

* Make a pool of fragment fingerprints to reduce the number in total.
Use an upper bound on the Tanimoto Coeff to reduce need for full calculation.

* Fix splitMolecule, which wasn't producing all possible fragments.

* Take out old code.

* Back to using unique_ptr for fragments.
Abolish maxBondSplits option. Use the maximum number of synthons in the space to control the splitting.

* Don't fold the reaction connector region fps into 1.

* Streamline connector combinations in substructure search.

* Re-factor fragment fingerprint generation prior to multi-threading.

* Make checkConnectorRegions return false when it should.
Tweak AllProbeBitsMatch.cpp.

* Fix Python wrapper of text file reader.

* More complex query shenanigans - amino acid this time.

* More complex query shenanigans - amino acid this time.

* Tidy.

* Fix binary DB read bug.
New Idorsia space file.

* Correct/improve function documentation.

* Tidying up.

* Remove stray include.

* Fix CI Tests.

* Plug memory leak.
Revise python timeout test.

* Simplify way synthon searchMols are created.  Previous method gave incorrect results sometimes hence new test.

* Update idorsia space file.

* Update idorsia test result.

* Update idorsia test result.

* Changes after first review.

* Move getFormattedNumProducts to general function.

* Stash working version with maps and mutex.

* Working with sorted vectors rather than maps.
Reading Text DB presumably slow.

* Split out MemoryMappedFileReader.cpp.

* Fix ReadDBFile in Python wrapper.

* Streamline tests.

* Include filesystem.

* Replace many uses of std::map with sorted std::vector.

* Use more auto.

* Threaded build hits.

* Threaded search.

* Don't chunk threaded buildAllHits.

* Allow for different results in random sampling.

* Threaded splitMolecule.
Fix bug - apply removeQueryAtoms to all frags, not just one per unique SMILES.
Do largest fragment heuristic up front so as not to repeat on each thread.

* Streamline Python tests.

* Separate out time-consuming tests.

* Add Rascal similarity searching.

* Add extended queries.

* Make extended queries honour maxHits correctly.

* Extra extended query test.

* Hide really long tests on local files.

* Remove local test.

* Make random tests less strict.
Attempt to fix build issues.

* Attempt to fix build issues.

* Response to review.

* Fix no-threads version.

* Re-move re-formatting.

* Add move semantics to MemoryMappedFileReader.

* Move c'tor needs size as well.

---------

Co-authored-by: David Cosgrove <david@cozchemix.co.uk>
2025-03-21 13:09:34 +01:00
David Cosgrove
c2944e7050 Optimisations to fingerprint search of Synthon Space (#8152)
* First pass at approximate FP check.

* Tidy and Python wrapper.

* More tidying.

* Add addFP and subtractFP to binary file.

* Minor tidy.

* In splits code, check for duplicate fragmentations.

* Update test results.

* Tidy.

* Set configurable limit on number of fragments generated from query.

* Stash prior to trying counts fps.

* Stash count fps.

* Back to bit fingerprints again.

* Extra comment.

---------

Co-authored-by: David Cosgrove <david@cozchemix.co.uk>
2025-01-22 05:44:56 +01:00
David Cosgrove
ce35b3c25b SynthonSearch synth check (#8109)
* Catch errors when creating products.

* Extra python test.

* Fix formatting.

---------

Co-authored-by: David Cosgrove <david@cozchemix.co.uk>
2024-12-18 05:12:07 +01:00
David Cosgrove
403cd55e6a Synthon search fp bug (#8086)
* Fix bug - connector patterns weren't being matched to the synthon connector patterns.

* Tiny tweak.

* Typo in comment.

---------

Co-authored-by: David Cosgrove <david@cozchemix.co.uk>
2024-12-12 18:24:01 +01:00
David Cosgrove
bbac292b4c Synthon fingerprint search (#8025)
* First pass at splitting molecule.

* Interim commit.  Reading libraries from file in original format.

* Basic search seems to be working.

* Pattern fingerprint screening.

* Connector region heuristic.

* Fixed triazole (aromatic/non-aromatic connectors).

* Fix search with non-split parent query, where query is substructure of a single reagent.

* Remove duplicate hits by reaction/reagents used.

* Implement largest fragment heuristic.

* Extra test files.

* Read/write binary file.
Program for conversion from text format to binary format.

* Remove empty reagent sets on reading, probably due to synthon number counting from 1 rather than 0.

* Tidy SSSearch functions.

* Stash pending major surgery for triazole bug.

* Revert to using unique_ptr.
Correct use of reagent order.

* Function to summarise Hyperspace.

* Delay building hits till end and put cutoff on number.

* Earlier bale-out in getHitReagents.

* Streamline checkConnectorRegions.

* Remove free functions for search.

* Correct name of Python test.

* First stage of Python wrappers.

* Rename namespace.

* Parameters object.

* Mysterious windows export thing.

* Fix bug - not matching number of connectors in fragment and synthon.

* Back like it was.  The connector count wasn't the problem.

* Put the substructure results into their own class.

* gcc 14 didn't like my use of std::reduce.
Update expected test results.

* Remove write statement.

* Tidy.

* Tidy.

* Enable random sample of hits.

* Test that complex SMARTS works.
Update Python wrappers.

* Rename Hyperspace to SynthonSpace.

* More renaming.
Python test.

* Enable Python test.
Remove write.

* Plug memory leak.

* Response to Greg's initial look.

* More response to Greg's initial look.

* get the windows DLL builds working

* Do away with mutable.
Purge a few more uses of reagent in favour of synthon.
Remove the c++ exe for converting text to binary databases.

* Better Synthon c'tor.

* More feedback from Greg.

* Tidy the Python wrapper.

* Remove tags from catch tests.

* Don't allow copying of SubstructureResults.

* Revert to allow copying of SubstructureResults.  The Python wrapper needs it.

* Refinements based on CLion/clangd suggestions.

* Allow for map numbers in connectors in space file.

* Refactor to make the searcher a separate class from the space.

* Transfer Greg's review suggestions from Hyperspace merge.

* First cut of fingerprint searcher.

* Python wrapper.
Some tidying.

* Better random selection.

* Fix bug in preparing frags for fingerprints.
Re-factor.

* Minor-refactor.

* Sort hits by similarity if available.

* Option for a few different fingerprint types.  Pending a better solution.

* Write fingerprints to binary file.

* Use any fingerprint generator for similarity searching.  No Python wrapper yet.

* Python wrapper.

* Change random selection to use distribution weighted by number of hits in each reaction.

* Lots of suggestions from CLion/clang.

* Use boost discrete_distribution for cross-platform consistency.

* Tidy test up.

* Try boost rng as well.

* uniform_int_distribution to boost also.

* Small tidy.

* Method to write enumerated library.

* Windows export thing.

* Windows export thing.

* Allow for commas in tab-separated fields.

* win64 dll builds now work

* More aliphatic synthon, aromatic product joy.

* Force ring finding if it hasn't been done.

* Fingerprint hits not being sorted if maxHits reached.

* Remove debugging write.  Doh!

* Response to review of SynthonSpace2.

* Missed one.

* Add test file.

* Hand merge Greg's #8050.

* Discard nodiscard.

* Move include of export.h inside include guards.

* Response to review.

* Fix memory leaks.

---------

Co-authored-by: David Cosgrove <david@cozchemix.co.uk>
Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
2024-11-29 13:07:32 +01:00
David Cosgrove
eaf544ab6f SynthonSpace Search (#7978)
* First pass at splitting molecule.

* Interim commit.  Reading libraries from file in original format.

* Basic search seems to be working.

* Pattern fingerprint screening.

* Connector region heuristic.

* Fixed triazole (aromatic/non-aromatic connectors).

* Fix search with non-split parent query, where query is substructure of a single reagent.

* Remove duplicate hits by reaction/reagents used.

* Implement largest fragment heuristic.

* Extra test files.

* Read/write binary file.
Program for conversion from text format to binary format.

* Remove empty reagent sets on reading, probably due to synthon number counting from 1 rather than 0.

* Tidy SSSearch functions.

* Stash pending major surgery for triazole bug.

* Revert to using unique_ptr.
Correct use of reagent order.

* Function to summarise Hyperspace.

* Delay building hits till end and put cutoff on number.

* Earlier bale-out in getHitReagents.

* Streamline checkConnectorRegions.

* Remove free functions for search.

* Correct name of Python test.

* First stage of Python wrappers.

* Rename namespace.

* Parameters object.

* Mysterious windows export thing.

* Fix bug - not matching number of connectors in fragment and synthon.

* Back like it was.  The connector count wasn't the problem.

* Put the substructure results into their own class.

* gcc 14 didn't like my use of std::reduce.
Update expected test results.

* Remove write statement.

* Tidy.

* Tidy.

* Enable random sample of hits.

* Test that complex SMARTS works.
Update Python wrappers.

* Rename Hyperspace to SynthonSpace.

* More renaming.
Python test.

* Enable Python test.
Remove write.

* Plug memory leak.

* Response to Greg's initial look.

* More response to Greg's initial look.

* get the windows DLL builds working

* Do away with mutable.
Purge a few more uses of reagent in favour of synthon.
Remove the c++ exe for converting text to binary databases.

* Better Synthon c'tor.

* More feedback from Greg.

* Tidy the Python wrapper.

* Remove tags from catch tests.

* Don't allow copying of SubstructureResults.

* Revert to allow copying of SubstructureResults.  The Python wrapper needs it.

* Refinements based on CLion/clangd suggestions.

* Allow for map numbers in connectors in space file.

* Response to review.

* update binary file spec

* Changes after review.

---------

Co-authored-by: David Cosgrove <david@cozchemix.co.uk>
Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
2024-11-17 08:13:54 +01:00