Skip to content

Rascal atom and bond equivalences - #7612

Merged
greglandrum merged 8 commits into
rdkit:masterfrom
DavidACosgrove:RascalAtomEquivalences
Jul 23, 2024
Merged

Rascal atom and bond equivalences#7612
greglandrum merged 8 commits into
rdkit:masterfrom
DavidACosgrove:RascalAtomEquivalences

Conversation

@DavidACosgrove

@DavidACosgrove DavidACosgrove commented Jul 14, 2024

Copy link
Copy Markdown
Collaborator

Reference Issue

No issue, but referred to in #7565

What does this implement/fix? Explain your changes.

This PR allows the user to use SMARTS strings to create classes of equivalent atoms. For example, if you want all halogens to match each other, or allow aromatic carbon and nitrogen atoms to match each other. In that case the option string would be
[F,Cl,Br,I] [c,n]
and c1ccccc1Br and c1ncccc1F would have an MCES of 7 atoms. The SMARTS string of the match includes the SMARTS for the classes as well.

The classes are implemented by giving all matching atoms for a SMARTS the same atomic number, starting at 110. There is thus an effective limit of 9 classes allowed (the atomic number can only go up to 118). A ValueErrorException is thrown if this occurs. Also, it will clearly get confused if there are Darmstadtium atoms in the molecule, but I think we can live with that.

Any other comments?

@DavidACosgrove

Copy link
Copy Markdown
Collaborator Author

I don't think the failure is down to these changes.

@bp-kelley

Copy link
Copy Markdown
Contributor

We're working on the osx builds, the clang toolchain was updated and it found some issues.

Fixes are here
#7607

@DavidACosgrove

Copy link
Copy Markdown
Collaborator Author

@bp-kelley anything I can do to help? I probably have a bit of time tomorrow.

@bp-kelley

Copy link
Copy Markdown
Contributor

If should be all fixed if you pull from master

Comment thread Code/GraphMol/RascalMCES/RascalMCES.cpp Outdated
// Set the atomic number of the atoms that match the SMARTS in
// RascalOptions.EquivalentAtoms to 110, 111 etc. These will
// be mapped back at the end.
void assignEquivalentAtoms(ROMol &mol, const std::string equivalentAtoms) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const std::string &equivalences will prevent a potential copy

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Facepalm! Thanks.

@DavidACosgrove
DavidACosgrove marked this pull request as draft July 16, 2024 07:05
@DavidACosgrove DavidACosgrove changed the title Rascal atom equivalences Rascal atom and bond equivalences Jul 16, 2024
@DavidACosgrove
DavidACosgrove marked this pull request as ready for review July 16, 2024 11:52
std::vector<std::string> classSmarts;
boost::split(classSmarts, equivalentAtoms, boost::is_any_of(" "),
boost::token_compress_on);
if (classSmarts.size() > 9) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like an arbitrary restriction, won't the code work with more than 9?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

As it says in the opening comment, that depends on what RDKit thinks of atomic numbers above 118. I assumed it would object though I didn’t check. Atoms that match a SMARTS class are all given the same atomic number starting at 110- it was a quick and dirty implementation. It could start lower than 110 but I was being exceptionally paranoid about what might be fed into it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it probably would still work with larger values, but (famous last words) "it's unlikely to ever really be a problem"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I can’t think of a case where you’d want to have more than 9 types of equivalent atom. But, as you imply, you can never trust a chemist!

@greglandrum greglandrum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@greglandrum
greglandrum merged commit 80381c6 into rdkit:master Jul 23, 2024
@greglandrum greglandrum added this to the 2024_03_6 milestone Jul 23, 2024
yishutu pushed a commit to yishutu/rdkit that referenced this pull request Aug 15, 2024
* C++ implementation of equivalent atoms via SMARTS.

* Python wrapper.

* Tidy.

* Check for too many classes.

* Better handling of spaces in split.

* Pass string by reference.  Doh.

* Add ignoreBondOrders option.
greglandrum pushed a commit that referenced this pull request Aug 29, 2024
* C++ implementation of equivalent atoms via SMARTS.

* Python wrapper.

* Tidy.

* Check for too many classes.

* Better handling of spaces in split.

* Pass string by reference.  Doh.

* Add ignoreBondOrders option.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants