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

Initial Attempt at PR for issue #3603 #5013

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

EchoFia
Copy link

@EchoFia EchoFia commented Apr 5, 2025

Would greatly appreciate some feedback, as this is just meant to be a rough version (+ my first time doing a PR, so, hopefully it's in the right place). So that I know, what's the best way to discuss changes and get feedback?

It's very rough at the moment, cause I have a lot of questions that I think it would be good to clear up (I think I'll try and put another message in the chat of issue #3603 summarising). I'm not expecting this to be merged immediately, and so will properly fill this out later I imagine (i.e. the checkboxes and the certification), my eyes just need a break from reading through things.

Fixes #3603

Changes made in this Pull Request:

  • Changed test_lineardensity.py from using a system of 5 water molecules to 3 systems (neutral particles, charged particles and charged dimers) that better demonstrate each aspect of Linear Density analysis. The systems consist of 100 atoms/dimers of mass 1 in a cubic box of side length 1 Angstrom.
  • More detail will be in the comments of issue LinearDensity should have more reliable tests #3603 in an hour or 2, hopefully

PR Checklist

  • Issue raised/referenced?
  • Tests updated/added?
  • Documentation updated/added?
  • package/CHANGELOG file updated?
  • Is your name in package/AUTHORS? (If it is not, add it!)

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--5013.org.readthedocs.build/en/5013/

…e feedback as this is just a rough attempt
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hello there first time contributor! Welcome to the MDAnalysis community! We ask that all contributors abide by our Code of Conduct and that first time contributors introduce themselves on GitHub Discussions so we can get to know you. You can learn more about participating here. Please also add yourself to package/AUTHORS as part of this PR.

Copy link

codecov bot commented Apr 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.41%. Comparing base (7fb3534) to head (09a9f60).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5013      +/-   ##
===========================================
- Coverage    93.42%   93.41%   -0.01%     
===========================================
  Files          177      189      +12     
  Lines        21865    22931    +1066     
  Branches      3079     3079              
===========================================
+ Hits         20427    21421     +994     
- Misses         986     1059      +73     
+ Partials       452      451       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@EchoFia EchoFia marked this pull request as ready for review April 7, 2025 23:27
Copy link

@jeremyleung521 jeremyleung521 left a comment

Choose a reason for hiding this comment

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

Just some comments on what to change, based on a quick read through. Haven't actually tried running anything yet.

### Calculating the Expected Values ###

def calc_Prop(u, prop = 'masses'): # Property can be 'masses' or 'charges'
expected_atoms = eval(f'u.atoms.{prop}')

Choose a reason for hiding this comment

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

The linter (and most programmers) would heavily discourage using eval(). It could be used to run arbitrary code. Maybe you can use getattr() instead? (https://docs.python.org/3/library/functions.html#getattr)

getattr(u.atoms, prop)

There are quite a few eval() below you could replace similarly.

expected_xcharge_residues = np.array(
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
)
test_Systems = ['neutral_Particles', 'charged_Particles', 'charged_Dimers']

Choose a reason for hiding this comment

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

Instead of strings, can't you just add in the functions? You might have to move this below those functions.

expected_xmass = []
expected_xcharge = []

for system in test_Systems:
Copy link

@jeremyleung521 jeremyleung521 Apr 8, 2025

Choose a reason for hiding this comment

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

With functions in test_Systems on L51, you can remove the eval() and run system(...) on L207. I would also discourage using such a generic name system for a variable, esp. since it's callable. Could mistaken with something more common like os.system.

assert_allclose(ld.masses, expected_masses)
assert_allclose(ld.charges, expected_charges)
# rtol changed here due to floating point imprecision
assert_allclose(ld.results.x.mass_density, expected_xmass, rtol=1e-06)
assert_allclose(ld.results.x.charge_density, expected_xcharge)


for i in range(len(params)):
print(i)
Copy link

@jeremyleung521 jeremyleung521 Apr 8, 2025

Choose a reason for hiding this comment

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

Is this print a leftover from testing?

def calc_Densities(u, prop = 'masses', spliceLen = 0.25): # Property can be 'masses' or 'charges'

propShort = 'mass'
if prop == 'charges': propShort = 'charge'
Copy link

@jeremyleung521 jeremyleung521 Apr 8, 2025

Choose a reason for hiding this comment

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

I would combine these two lines to:

propShort = 'charge' if prop == 'charges' else 'mass'

I don't think linters like an if statement without the actual new line/spaces

universe = eval(f'{system}(100, 1, 5, 4)')
universes.append(universe)

## expected_masses_atoms, expected_masses_residues, expected_masses_segments = calc_Prop(universe, 'masses')

Choose a reason for hiding this comment

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

leftover from testing?

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.

LinearDensity should have more reliable tests
3 participants