mdanalysis icon indicating copy to clipboard operation
mdanalysis copied to clipboard

Fix wrong element assignment for carbon of the style C*S

Open ricard1997 opened this issue 2 months ago • 1 comments

The current MDAnalysis atom guesser incorrectly assigns the element type for certain atoms. This misassignment leads to incorrect bond guessing, particularly in DSM lipids—which is how the issue was originally identified.

Fixes #5102

Changes made in this Pull Request:

Added two lines in default_guesser.py to the method guess_atom_element():

        if name in tables.atomelements:
            if name == "CS" and  isinstance(eval(atomname[1:-1]), int): #"Adding these two lines correctly assigns this C*S atoms as carbons"
                name = "AC"    # AC maps to C as per the MDAnalysis table
            return tables.atomelements[name]

A detailed explanation of the bug and the proposed solution can be found at https://github.com/ricard1997/MDAnalysis_issue_fix.git

PR Checklist

  • [x] Issue raised/referenced?
  • [x] Tests updated/added?

Developers Certificate of Origin

I certify that I can submit this code contribution as described in the Developer Certificate of Origin, under the MDAnalysis LICENSE.


📚 Documentation preview 📚: https://mdanalysis--5149.org.readthedocs.build/en/5149/

ricard1997 avatar Nov 17 '25 23:11 ricard1997

Codecov Report

:x: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 92.71%. Comparing base (3189d48) to head (e636bac).

Files with missing lines Patch % Lines
package/MDAnalysis/guesser/default_guesser.py 0.00% 1 Missing and 1 partial :warning:
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5149      +/-   ##
===========================================
- Coverage    92.72%   92.71%   -0.01%     
===========================================
  Files          180      180              
  Lines        22458    22460       +2     
  Branches      3186     3187       +1     
===========================================
  Hits         20824    20824              
- Misses        1177     1178       +1     
- Partials       457      458       +1     

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

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Nov 17 '25 23:11 codecov[bot]