-
Notifications
You must be signed in to change notification settings - Fork 81
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
Reorder bond, angle, and dihedral in write_lammpsdata #1071
Conversation
I think I am good with this change! I didn't realize the order was not enforced in the lammps writer. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1071 +/- ##
==========================================
+ Coverage 90.49% 90.54% +0.04%
==========================================
Files 61 61
Lines 6157 6186 +29
==========================================
+ Hits 5572 5601 +29
Misses 585 585 ☔ View full report in Codecov by Sentry. |
The reported failures are due to a merger of the main branch... why doesn't this repository have a develop branch? |
I can look into the issue with the test (seems like it's stemming from something outside the scope of this PR). Regarding missing of the |
A develop branch is definitely a nice feature to have. The way I look at it, essentially the dev version of this package is similar to a dev branch, and in this case then the most recent minor release available on Conda is the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. I still have some concerns with the time it takes for this sorting mechanism, and I'm wondering if there might be something a little more efficient. In the worst case scenario, which looks to be the charmm dihedrals and impropers, we scale by 10N^4. So that can quickly get out of hand, with all of those nested for loops. I think it's a rare case, where you have like 100's of atomtypes but not something entirely impossible.
I think a way we could improve the sorting would be to replace a line like: atom_types = list(set(atom.type for atom in structure.atoms))
atom_types.sort(key=natural_sort)
lx = len(atom_types)
angle_sets = [x[-1] for _, x in unique_angle_types.items()]
ordered_angle_sets = [
(atom_types[x], atom_types[y])
for x in range(lx)
for y in range(x, lx)
if (atom_types[x], atom_types[y]) in angle_sets
] which scales at O(N^3) with a keyed sort which scales on O(NlogN) as far as I'm aware. atom_types = list(set(atom.type for atom in structure.atoms))
atom_types.sort(key=natural_sort)
angle_sets = [
(x[2], x[-1][0], x[-1][1]) for _, x in unique_angle_types.items()
]
angle_sets.sort(key=lambda x: atom_types.index(x[0])) #improved sorting function
ordered_angle_sets = angle_sets |
Sure the sorting function is more efficient if there's a single quantity to sort by, but unless I'm reading it wrong, your proposed solution isn't sorting the second or third atom_types in the angle and so is insufficient. I can use the sorting function with something like this: magnitude = np.ceil(np.log10(len(atom_types)))
angle_sets.sort(
key=lambda x: atom_types.index(x[0]) * 10**(2*mangnitude)
+ atom_types.index(x[1]) * 10**mangnitude
+ atom_types.index(x[2]))
) |
That is correct, I think your solution here completes it! We have discussed this further among the devs, and I tested out some 100 unique atomtypes 100,000 atom systems, and the writing isn't the holdup as compared to just atomtyping the system, so I think once the tests are passing here, we will be good to merge this. I'll also ping the original issue #1070 once this feature is implemented on the GMSO side of things as well. |
What is going on with the docs? |
Oh, I think the docs sometimes just doesn't build properly for PR. I will try to review this PR today. @CalCraven seems like most of your comments have been addressed too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good! Tried out the sorting locally and I think those are quite neat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for noticing this feature.
I'm not seeing the output for LGTM, is that because the docs failed? It seems that there's an unknown attribute "spin"? |
I believe the LGTM checks as of 22-12-16 have been discontinued and are implemented now in CodeQL. So I'm not too worried about that. I'm seeing an issue in read the docs for |
* Reorder bond, angle, and dihedral in write_lammpsdata * Update ordering charm angles/dihedrals * Bug fix tests * Update bond/angle/dihedral sorting algorithm --------- Co-authored-by: Co Quach <43968221+daico007@users.noreply.github.com>
PR Summary:
Resolves #1070
I haven't fixed the tests to accept these changes because I expect there to be comments.
PR Checklist