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 scale charges, add unit tests #33

Merged
merged 7 commits into from
Aug 30, 2023
Merged

Fix scale charges, add unit tests #33

merged 7 commits into from
Aug 30, 2023

Conversation

chrisjonesBSU
Copy link
Member

This PR adds the scale charges functionality to the System class that was previously in a separate utils files, and includes some unit tests.

It works so that each negative charge is slightly increased and each positive charge is slightly decreased (all by the same amount) to achieve as close to a neutral charge as possible.

@@ -150,6 +150,11 @@ def mass(self):
)
return sum(mol.mass for mol in self.all_molecules)

@property
def net_charge(self):
if self.gmso_system:
Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if we still need this if self.gmso_system anymore? It's used in n_particles and mass as well. I think with the recent changes, self.gmso_system will always exist.

Copy link
Member Author

Choose a reason for hiding this comment

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

So, I think we need it for the mass attribute, since that is used by set_target_box before self.gmso_system is created, but we probably don't need it in the n_particles and net_charge attributes. I'll test it out and push more changes if so.

@codecov
Copy link

codecov bot commented Aug 29, 2023

Codecov Report

Merging #33 (daa2b52) into main (bb841e0) will increase coverage by 2.86%.
Report is 16 commits behind head on main.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #33      +/-   ##
==========================================
+ Coverage   89.17%   92.04%   +2.86%     
==========================================
  Files          18       18              
  Lines        1303     1320      +17     
==========================================
+ Hits         1162     1215      +53     
+ Misses        141      105      -36     
Files Changed Coverage Δ
hoomd_organics/utils/utils.py 80.00% <ø> (+30.00%) ⬆️
hoomd_organics/base/system.py 89.78% <100.00%> (+7.85%) ⬆️
hoomd_organics/utils/__init__.py 100.00% <100.00%> (ø)

... and 4 files with indirect coverage changes

Copy link
Collaborator

@marjanalbooyeh marjanalbooyeh left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you.
I added two comments related to cases where charge is None.

hoomd_organics/base/system.py Outdated Show resolved Hide resolved
hoomd_organics/base/system.py Outdated Show resolved Hide resolved
@marjanalbooyeh marjanalbooyeh self-requested a review August 29, 2023 20:19
net_charge = sum(charges)
abs_charge = sum(abs(charges))
for site in self.gmso_system.sites:
site.charge -= abs(site.charge) * (net_charge / abs_charge)
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably need to take care of division by zero error for cases where abs_charge=0

Copy link
Collaborator

Choose a reason for hiding this comment

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

And abs(site.charge) would also cause problem if site.charge=None.

I think one way to fix this would be to have a for loop in _convert_to_gmso() that checks the site.charge and if it's None sets to 0 by default.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, I'll fix this after we merge your PR with addl. unit tests.

@marjanalbooyeh marjanalbooyeh linked an issue Aug 29, 2023 that may be closed by this pull request
@chrisjonesBSU chrisjonesBSU linked an issue Aug 29, 2023 that may be closed by this pull request
@marjanalbooyeh marjanalbooyeh merged commit 4b46d69 into cmelab:main Aug 30, 2023
3 checks passed
@chrisjonesBSU chrisjonesBSU deleted the scale-charges branch August 30, 2023 18:52
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.

Tutorial example doesn't have charge-neutral PPS Finish unit tests
2 participants