xiaoruiDong / RDMC

Reaction Data and Molecular Conformers (RDMC) is a package dealing with reactions, molecules, conformers, majorly in 3D.
https://xiaoruidong.github.io/RDMC/
MIT License
21 stars 0 forks source link

Add a dedicated resonance module #77

Closed xiaoruiDong closed 7 months ago

xiaoruiDong commented 7 months ago

A dedicated resonance generation module is added.

The most important update is that RMG's resonance structure algorithm is added and becomes RDKit native (no RMG module is no longer needed. The details of the algorithm can be found in Dana et al.'s work. Several notes about this addition:

  1. the implementation can be divided into two stages: (1) converting RMG APIs to RDKit APIs and adding missing functions. (commits between Sep 26 - Oct 3). (2) Redesigning functions, algorithms, and workflows to speed up.
  2. The motivation of stage 2. After stage 1, a naive rewrite slows down the resonance structure generation of common molecules by 5 - 10x times than the implementation in RMG. Due to (1) iterating atoms/bonds inefficiently while finding patterns and modifying molecules. (2) slower operations in retrieving atom/ring information. (3) slower molecule copy mechanism. (4) No Clar structure generation is implemented due to missing lpsolve55.
  3. In the stage 2 rewrite, (1) replace all pathfinder algorithms from iterating atoms with fast RDKit substructure match and use an OOP design (2) replace most functions with RDKit builtin functions (3) refactor codes to avoid unnecessary copy/manipulation and minimizing isomorphism check. This also includes aromaticity check and acquisition, resulting in inconsistent behavior compared to RMG (4) Replace lpsolve55 with scipy.linprog (HiGHS as the backend) to achieve Clar structure generation
  4. The rewrite version is purely based on RDKit functions/classes. So, there is also a possibility of separating this module as a standalone package.
  5. Unify the RMG resonance structure generation interface with the original RDMC interface.
  6. Migrate all RMG unit tests. A few tests intentionally checking the difference in behavior between RMG and RDKit are specially marked (xfail). A couple of redundant unit tests are removed.
codecov[bot] commented 7 months ago

Codecov Report

Attention: 109 lines in your changes are missing coverage. Please review.

Comparison is base (1c42c87) 38.24% compared to head (a660267) 48.08%. Report is 2 commits behind head on main.

Files Patch % Lines
rdmc/resonance/utils.py 68.00% 48 Missing and 8 partials :warning:
rdmc/resonance/rmg.py 90.93% 16 Missing and 12 partials :warning:
rdmc/resonance/rdkit.py 87.23% 9 Missing and 3 partials :warning:
rdmc/resonance/filtration.py 95.94% 2 Missing and 4 partials :warning:
rdmc/resonance/pathfinder.py 97.56% 5 Missing :warning:
rdmc/reaction.py 33.33% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #77 +/- ## ========================================== + Coverage 38.24% 48.08% +9.83% ========================================== Files 34 39 +5 Lines 3812 4715 +903 Branches 975 1232 +257 ========================================== + Hits 1458 2267 +809 - Misses 2275 2346 +71 - Partials 79 102 +23 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.