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

Add 2d checkered pattern #1118

Merged
merged 15 commits into from
Jun 6, 2023
Merged

Conversation

daico007
Copy link
Member

PR Summary:

Add new 2D checkered patter to mBuild pattern.py.
Grid2DPattern:
Screenshot 2023-05-27 at 16 16 56

Checkered2DPattern:
Screenshot 2023-05-27 at 16 17 18

PR Checklist


  • Includes appropriate unit test(s)
  • Appropriate docstring(s) are added/updated
  • Code is (approximately) PEP8 compliant
  • Issue(s) raised/addressed?

@daico007 daico007 marked this pull request as ready for review May 27, 2023 21:17
@codecov
Copy link

codecov bot commented May 27, 2023

Codecov Report

Patch coverage: 96.00% and project coverage change: +0.03 🎉

Comparison is base (5e505ab) 87.13% compared to head (7767544) 87.16%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1118      +/-   ##
==========================================
+ Coverage   87.13%   87.16%   +0.03%     
==========================================
  Files          62       62              
  Lines        6420     6445      +25     
==========================================
+ Hits         5594     5618      +24     
- Misses        826      827       +1     
Impacted Files Coverage Δ
mbuild/pattern.py 95.56% <96.00%> (+0.08%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@chrisiacovella
Copy link
Contributor

A few comments:

let us ditch the "row" and "column" terminology in the Checkered2DPattern and Grid2DPattern. It would be more consistent (with the 3d packing) and clearer to say:

    n : int
         Number of points along x-axis

    m : int
         Number of points along y-axis

Similarly, I think change the accepted values for shift to be either 'n' or 'm' (or 'x' or 'y') where shift='n' would mean shifting occurs in the x-direction (shifting every other row in 'm').

To make it clear what is being done, I think the description in the docstring should probably state what is done:

Generates a square grid of dimensions n by m, then shifts points accordingly to generate a triangular arrangement. shift='n' would mean shifting occurs in the x-direction, where the code shifts every other row in the range specified by 'm'. Similarly shift='m' performs shifting along the y-direction, where the code shifts every other column in range specified by 'n'. By default, shifting will be half the distance between neighboring points in the direction of shifting. This code will allow patterns to be generated that are only periodic in one direction; to generate a periodic pattern, m should be even when shift='n' and 'n' should be even when shift='m'.

To generalize, could also allow the value of the delta_shift to be set; this allows of course a wider range of grids to be defined, but also if delta_shift is set to zero, it would recover grid2dpattern. As such, we should probably just have Grid2DPattern inherit from this class, setting delta_shift=0.

I think Triangle2DPattern might be a more appropriate name than checkered, since a square lattice can be checkered by alternately labeling the points (which might actually be a useful addition to the code in a future PR, being able to label the point and thus being able to pass a point label name to the apply function so that only select points would get compounds moved to them) .

@chrisiacovella chrisiacovella self-requested a review June 1, 2023 20:27
mbuild/pattern.py Fixed Show fixed Hide fixed
assert len(pattern) == 25

with pytest.raises(ValueError):
pattern = mb.Triangle2DPattern(5, 5, "bogus")

Check notice

Code scanning / CodeQL

Unused local variable

Variable pattern is not used.
Copy link
Contributor

@chrisiacovella chrisiacovella left a comment

Choose a reason for hiding this comment

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

LGTM

mbuild/pattern.py Outdated Show resolved Hide resolved
mbuild/pattern.py Outdated Show resolved Hide resolved
mbuild/pattern.py Show resolved Hide resolved
mbuild/pattern.py Show resolved Hide resolved
mbuild/pattern.py Outdated Show resolved Hide resolved
Copy link
Contributor

@chrisiacovella chrisiacovella left a comment

Choose a reason for hiding this comment

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

Looks good.

@daico007 daico007 merged commit 7eb74c6 into mosdef-hub:main Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants