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

Fix and enhance lammps DATAWriter #4520

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

Conversation

nbzy1995
Copy link

@nbzy1995 nbzy1995 commented Mar 20, 2024

Fixes #

Changes made in this Pull Request:

  • Fix error when convert_units = False in DATAWriter in lammps.py
  • Allow DATAWriter in lammps.py to use differnt atom_style

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

Developers certificate of origin


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

@pep8speaks
Copy link

Hello @nbzy1995! Thanks for opening this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 239:68: W291 trailing whitespace
Line 295:80: E501 line too long (88 > 79 characters)
Line 302:14: W291 trailing whitespace
Line 319:21: E128 continuation line under-indented for visual indent
Line 333:14: W291 trailing whitespace
Line 391:54: E251 unexpected spaces around keyword / parameter equals
Line 391:56: E251 unexpected spaces around keyword / parameter equals
Line 397:78: W291 trailing whitespace
Line 398:73: W291 trailing whitespace
Line 417:53: W291 trailing whitespace

Line 233:52: E251 unexpected spaces around keyword / parameter equals
Line 233:54: E251 unexpected spaces around keyword / parameter equals
Line 233:61: E261 at least two spaces before inline comment
Line 233:80: E501 line too long (93 > 79 characters)
Line 235:60: E251 unexpected spaces around keyword / parameter equals
Line 235:62: E251 unexpected spaces around keyword / parameter equals
Line 238:40: E251 unexpected spaces around keyword / parameter equals
Line 238:42: E251 unexpected spaces around keyword / parameter equals

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

Linter Bot Results:

Hi @nbzy1995! Thanks for making this PR. We linted your code and found the following:

Some issues were found with the formatting of your code.

Code Location Outcome
main package ⚠️ Possible failure
testsuite ⚠️ Possible failure

Please have a look at the darker-main-code and darker-test-code steps here for more details: https://github.com/MDAnalysis/mdanalysis/actions/runs/8352743717/job/22863306560


Please note: The black linter is purely informational, you can safely ignore these outcomes if there are no flake8 failures!

Copy link

codecov bot commented Mar 20, 2024

Codecov Report

Attention: Patch coverage is 70.00000% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 93.62%. Comparing base (0582265) to head (416cffe).
Report is 18 commits behind head on develop.

Files Patch % Lines
package/MDAnalysis/coordinates/LAMMPS.py 70.00% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4520      +/-   ##
===========================================
- Coverage    93.65%   93.62%   -0.04%     
===========================================
  Files          168      180      +12     
  Lines        21215    22306    +1091     
  Branches      3908     3913       +5     
===========================================
+ Hits         19869    20883    +1014     
- Misses         888      965      +77     
  Partials       458      458              

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

Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

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

Great start @nbzy1995.

Would you be able to write up an issue that this PR addresses? There are at least 25 different atom_style variants and we need to ensure this solves an issue that is likely to be useful to the community (yourself included of course) without taking on functionality we cannot maintain.

@@ -274,46 +275,63 @@ def __init__(self, filename, convert_units=True, **kwargs):
self.units['velocity'] = kwargs.pop('velocityunit',
self.units['length']+'/'+self.units['time'])

def _write_atoms(self, atoms, data):
def _write_atoms(self, atoms, data, atom_style):
Copy link
Member

Choose a reason for hiding this comment

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

Forgive my LAMMPs ignorance, but what style are we currently writing? We should use that as the default.


indices = atoms.indices + 1
types = atoms.types.astype(np.int32)

moltags = data.get("molecule_tag", np.zeros(len(atoms), dtype=int))
if atom_style == 'full':
Copy link
Member

Choose a reason for hiding this comment

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

Need to test for valid atom styles, I would add them as a static list object somewhere in this file. e.g

_allowed_atom_styles = ["full, atomic, ..."]

if atom_style not in _allowed_atom_styles:
    raise ValueError("blah")


if has_charges:
if has_charges and print_moltag:
Copy link
Member

Choose a reason for hiding this comment

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

It may be better to separate these by atom_style it is not very clear to which style these branches belong (should use a case statement). Not really your fault but will make things a lot clearer.

@@ -230,14 +230,14 @@ def test_datawriter_universe(filename, tmpdir):
"""
fn = str(tmpdir.join(filename))

u = mda.Universe(LAMMPSdata_mini)
u = mda.Universe(LAMMPSdata_mini, convert_units = False) # By defaul convert_units = True
Copy link
Member

Choose a reason for hiding this comment

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

Parametrize over convert_units = False and convert_units = False with @pytest.mark.parametrize

assert_allclose(u.atoms.positions, u2.atoms.positions)
assert_allclose(u.atoms.velocities, u2.atoms.velocities)
assert_allclose(u.dimensions, u2.dimensions)


Copy link
Member

Choose a reason for hiding this comment

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

Can you roundtrip one of the files we write to ensure it is readable?

@orbeckst
Copy link
Member

@hmacdope could you please be in charge? This may simply mean closing the PR as stale if there's no reply to your questions and requests.

@orbeckst orbeckst added close? Evaluate if issue/PR is stale and can be closed. stale labels May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
close? Evaluate if issue/PR is stale and can be closed. Component-Readers stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants