question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove length check in ValenceDict

See original GitHub issue

Is your feature request related to a problem? Please describe.

ValenceDict has a number of restrictions that require the length of the key to be no more than 4 atoms. Is there a real reason for this?

Describe the solution you’d like

Remove length check here:

https://github.com/openforcefield/openff-toolkit/blob/c32527bbdd98e5141c0f7a98c968bf0e514217b0/openff/toolkit/topology/topology.py#L94-L103

Refactor this to just take the forward or backward permutation. Also, it’s much more idiomatic python to make this a classmethod instead of a staticmethod that uses __class__.

permutations = OrderedDict({refkey: 0, refkey[::-1]:1})

https://github.com/openforcefield/openff-toolkit/blob/c32527bbdd98e5141c0f7a98c968bf0e514217b0/openff/toolkit/topology/topology.py#L105-L165

Describe alternatives you’ve considered

Additional context

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
j-wagscommented, Feb 10, 2022

Gotcha, I see some points on both sides but ultimately I agree with @lilyminium on all proposed changes here.

This is sorta related to a legacy of rough edges around vsites, which came to be because, when @trevorgokey and I were working on it, vsites were supposed to take like a month, and then at the 6 month point, when crazy edge cases kept popping up, and we had unilaterally made changes to the SMIRNOFF spec, and @trevorgokey had rewritten everything several times, we finally said “this is good enough”, and this got out with some rough edges. So thanks to both of you for the great discussion, I think @lilyminium’s correct-er on every point (except I’m giving up on trying to understand the serialization thing, so I have no opinion there)

I’ve approved the PR that will close this issue.

1reaction
lilyminiumcommented, Jan 31, 2022

Also, it’s much more idiomatic python to make this a classmethod instead of a staticmethod that uses __class__.

ValenceDict and ImproperDict both have staticmethods that use __class__, so I felt my example was more representative. Again, I have nothing against staticmethods for the reasons you’ve mentioned – they’re a useful construct and exist for a reason. I just think that when you require the class in the method, you should switch to a classmethod to communicate the code more clearly.

https://github.com/openforcefield/openff-toolkit/blob/c32527bbdd98e5141c0f7a98c968bf0e514217b0/openff/toolkit/topology/topology.py#L129

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove characters in string when it reaches specific length
And I am checking the whole "Name" value is greater than 255 and if so, Need to remove that extra characters from DisplayName...
Read more >
String length - JavaScript - MDN Web Docs - Mozilla
The length data property of a string contains the length of the string in UTF-16 code units.
Read more >
String Functions
Returns the rightmost len characters of c1. Trailing blanks are not removed first. If c1 is a fixed-length character string, the result is...
Read more >
LEN function - Amazon Redshift - AWS Documentation
Returns the length of the specified string as the number of characters.
Read more >
JavaScript String length Property - W3Schools
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found