Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test that we can make a sample molecule for every atom type. #1661

Merged
merged 9 commits into from
May 17, 2023
Merged

Conversation

rwest
Copy link
Member

@rwest rwest commented Jul 22, 2019

Motivation or Problem

This unit test at the start of this PR was inspired by efforts to debug something in some changes to the database (ReactionMechanismGenerator/RMG-database#317) , which caused a segfault when running the database Tests, but was in fact caused by an undetected bug in RMG (#1656) not a problem in the database. I felt there ought to have been a unit test to prevent the bug.

Description of Changes

The goal is to make a group definition out of each atom type, and then make a sample molecule for each group definition. This should test the group definition and the make_sample_molecule method.

At first, the test failed, and that was either because of

  1. bug(s) in the way the test is currently written, or
  2. bug(s) in our atom type definitions
  3. bug(s) in our make_sample_molecule method.

I then fixed several of the bugs - mostly in the algorithm to make aromatic rings for sample molecules.
The remaining bugs I split into a "work in progress" unit test - they involve aromatic O and S atoms (['O4b', 'S4b'] ) which seem to be poorly supported currently.

I then made a more stringent test - that not only do we generate sample molecules without crashing, but that they're correct. This test is also currently marked a "work in progress". The list of problems is Xo, Cq, Sib, Sibf, Siq. Fixing those can be a separate issue.

@rwest
Copy link
Member Author

rwest commented Nov 14, 2019

Just updated to RMG 3.

@JacksonBurns
Copy link
Contributor

This PR is abandoned but up-to-date and simple enough that it could be merged. I am going to change the base branch to main, update it, and see what happens.

@JacksonBurns JacksonBurns changed the base branch from master to main May 12, 2023 20:41
@JacksonBurns
Copy link
Contributor

Rebased and CI is now running.

@rwest
Copy link
Member Author

rwest commented May 13, 2023

Couldn't make sample molecules for types ['Ctc', 'N5bd', 'O4b', 'P3b', 'P5b', 'P5bd', 'S4b']

@rwest
Copy link
Member Author

rwest commented May 13, 2023

Now down to ['N5bd', 'O4b', 'P3b', 'P5b', 'P5bd', 'S4b'].
Noting that these are all benzene atom types, I am hoping they all have the same problem.

@rwest
Copy link
Member Author

rwest commented May 13, 2023

Got several more working.
There is still some (other) problem with O4b and S4b, but this gets them closer.
Note that Sib and Sibf atom types do not crash, but do not create a correct sample molecule at this time.
(The unit test just checks for exceptions, not that the sample molecules are right, so these errors are undetected)

@rwest rwest added the Status: Ready for Review PR is complete and ready to be reviewed label May 14, 2023
@codecov
Copy link

codecov bot commented May 14, 2023

Codecov Report

Merging #1661 (dac9888) into main (758065c) will decrease coverage by 0.01%.
The diff coverage is n/a.

❗ Current head dac9888 differs from pull request most recent head 15ca27e. Consider uploading reports for the commit 15ca27e to get more accurate results

@@            Coverage Diff             @@
##             main    #1661      +/-   ##
==========================================
- Coverage   48.11%   48.11%   -0.01%     
==========================================
  Files         110      110              
  Lines       30626    30625       -1     
  Branches     7988     7988              
==========================================
- Hits        14735    14734       -1     
+ Misses      14363    14362       -1     
- Partials     1528     1529       +1     

see 3 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@JacksonBurns JacksonBurns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for bringing this one back from the dead. Approving now (tests should pass w/o problems) and then feel free to merge.

rwest added 9 commits May 16, 2023 19:49
This unit test was inspired by efforts to debug something in some
changes to the database, which caused a segfault when running
the database Tests, but was in fact caused by an undetected bug in RMG. This should detect similar bugs.
The idea is that for every atomType, such as 'Cds', the
method Group().make_sample_molecule() can create a molecule
from the group definition, eg.
  1  Cd  ux
should make the molecule
  1 C u0 p0 c0 {2,D} {3,S} {4,S}
  2 C u0 p0 c0 {1,D} {5,S} {6,S}
  3 H u0 p0 c0 {1,S}
  4 H u0 p0 c0 {1,S}
  5 H u0 p0 c0 {2,S}
  6 H u0 p0 c0 {2,S}

Many work, but quite a few fail.
Updated to RMG3/Python3.
We have a hard-coded list of charged atom types here. It was missing one.
The atomtypes each have a charge list - let's just see if it matches.
When you create a molecule from a functional group definition that 
declares implicit benzene rings by using a "benzene" atom type,
it creates benzene rings.

This algorithm contains a list of "benzene" atom types.
It's hard-coded. And missing some. This adds one, to check that 
adding one fixes things.

With this fix, the following line works:

rmgpy.molecule.Group().from_adjacency_list('1 N5bd ux').make_sample_molecule()
Before it had a hard-coded list (that was missing some).
Now any atomtype that is declared as having at least one benzene bond
is counted.
This helps generating sample molecules for certain atomtypes.
Now lines like this work:
rmgpy.molecule.Group().from_adjacency_list('1 P3b ux').make_sample_molecule()
Fixing O4b and S4b will be nontrivial, so rather than fix them
I'm marking them as "work in progress" (expected to fail)
Ideally we could make a molecule from every atom type definition
that matches that atom type. 

This is a work in progress test, because we can't.
Two (marked in previous tests) crash. Some others create molecules,
but they don't seem to match the functional group they were designed
to match.
@rwest rwest merged commit 9bd4580 into main May 17, 2023
@rwest rwest deleted the atomtypetest branch May 17, 2023 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Ready for Review PR is complete and ready to be reviewed Type: Testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants