Skip to content

Commit

Permalink
re-add __hash__ method for atom type and parametric potential
Browse files Browse the repository at this point in the history
  • Loading branch information
daico007 committed Nov 20, 2023
1 parent cabb47b commit b3e2c7f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
4 changes: 4 additions & 0 deletions gmso/core/atom_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def clone(self, fast_copy=False):
definition=self.definition,
)

def __hash__(self):
"""Return the unique hash of the object."""
return id(self)

def __eq__(self, other):
if other is self:
return True
Expand Down
30 changes: 21 additions & 9 deletions gmso/core/parametric_potential.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class ParametricPotential(AbstractPotential):
by classes that represent these potentials.
"""

model_config = ConfigDict(
alias_to_fields=dict(
**AbstractPotential.model_config["alias_to_fields"],
**{"topology": "topology_", "set_ref": "set_ref_"},
),
validate_assignment=True,
)

def __init__(
self,
name="ParametricPotential",
Expand Down Expand Up @@ -96,7 +104,7 @@ def parameters(self):
def __setattr__(self, key: Any, value: Any) -> None:
"""Set the attributes of the potential."""
if key == "parameters":
self.potential_expression.parameters = value
self.potential_expression_.parameters = value
else:
super().__setattr__(key, value)

Expand All @@ -121,7 +129,7 @@ def set_expression(
If only a subset of the parameters are supplied, they are updated
while the non-passed parameters default to the existing values
"""
self.potential_expression.set(
self.potential_expression_.set(
expression=expression,
independent_variables=independent_variables,
parameters=parameters,
Expand All @@ -143,7 +151,7 @@ def dict(
if isinstance(exclude, dict):
exclude = set(exclude)

exclude = exclude.union({"topology", "set_ref"})
exclude = exclude.union({"topology_", "set_ref_"})

return super().dict(
include=include,
Expand All @@ -155,6 +163,10 @@ def dict(
exclude_none=exclude_none,
)

def __hash__(self):
"""Return the unique hash of the object."""
return id(self)

def __eq__(self, other):
if other is self:
return True
Expand Down Expand Up @@ -210,12 +222,12 @@ def _etree_attrib(self):
by_alias=True,
exclude_none=True,
exclude={
"topology",
"set_ref",
"member_types",
"member_classes",
"potential_expression",
"tags",
"topology_",
"set_ref_",
"member_types_",
"member_classes_",
"potential_expression_",
"tags_",
},
).items()
if value != ""
Expand Down

0 comments on commit b3e2c7f

Please sign in to comment.