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

account for charges in convert_mbuild.py #679

Closed
chrisjonesBSU opened this issue Jul 22, 2022 · 11 comments · Fixed by #687
Closed

account for charges in convert_mbuild.py #679

chrisjonesBSU opened this issue Jul 22, 2022 · 11 comments · Fixed by #687
Assignees

Comments

@chrisjonesBSU
Copy link
Contributor

Related to #664 and #678

site.charge defaults to None which might cause issues for some of the writers (e.g. write_gsd)

I think site.charge should default to 0 when not set, and we should look through the convert functions in gmso.external to make sure site.charge is being populated correctly when the information is available.

@chrisjonesBSU
Copy link
Contributor Author

chrisjonesBSU commented Jul 22, 2022

EDIT: After messing around a bit I answered my own question.

I'm kind of confused how default values are handled with pydantic. Is the correct place to define default values for attributes in the Field class?

For example:

 41     charge_: Optional[Union[u.unyt_quantity, float]] = Field(
 42         None,
 43         description="Charge of the atom",
 44     )
 45 
 46     mass_: Optional[Union[u.unyt_quantity, float]] = Field(
 47         None, description="Mass of the atom"
 48     )

Would become:

 41     charge_: Optional[Union[u.unyt_quantity, float]] = Field(
 42        0.0,
 43         description="Charge of the atom",
 44     )
 45 
 46     mass_: Optional[Union[u.unyt_quantity, float]] = Field(
 47         0.0, description="Mass of the atom"
 48     )

@CalCraven
Copy link
Contributor

As far as I'm aware, this is the change you would want. However, I do think it is better to leave at least the default values to None, same as my comment in Issue #678. This gives us the power to understand if the value has been set to 0 somewhere, or is awaiting some way to get the value. When we read from mbuild, we can populate site.charge as 0 for specific instances if that was a good specific default behavior for a system.

For instance, I think in this function we just need to be checking for charges, and assigning them to the atom.

@chrisjonesBSU
Copy link
Contributor Author

Yeah, I agree that leaving the default as None provides some extra information and functionality

@daico007
Copy link
Member

Yeah, having charge default to None was a conscious decision back then, since charge=0 still carry physical meaning, having that as default may cause unexpected behavior (like folks forget to put charge but everything runs).

@chrisjonesBSU
Copy link
Contributor Author

Ok, that makes sense. I guess the question remains if from_mbuild should carry over charge and mass information if it's been set in mBuild, or if they should stay as None until the user takes some further action to define them in gmso.

@CalCraven
Copy link
Contributor

If they're there in mBuild, they should be assigned to the GMSO topology. That is certainly the case, not having that converted is a bug.

@daico007
Copy link
Member

I think we should carry it over given that those parameters are set in the mBuild Compound (but I am not sure what's the default value for those two fields over mbuild, need to double check). My point of view is that if those values have been set by the user and is part of the particle/bead (not atomtype), they should be brought over and take precedent that the values specified in their atomtypes, but also avoid having default to a logically correct value (0 for charge).

@daico007
Copy link
Member

Just checked, and currently, both charge and mass is default to 0 in mbuild, I think we should change those to None

@CalCraven
Copy link
Contributor

That change sounds better to me. It may break some of the current mBuild writers though, so we'll have to keep an eye on that in the PR.

@daico007
Copy link
Member

I will start a PR to do that and see how many things break

@daico007
Copy link
Member

addressed in mosdef-hub/mbuild#1047 and #680

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 a pull request may close this issue.

3 participants