Skip to content

Commit

Permalink
update set mass
Browse files Browse the repository at this point in the history
  • Loading branch information
marjanalbooyeh committed Aug 29, 2023
1 parent 217fa97 commit 9483944
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions hoomd_organics/base/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,19 @@ def reference_energy(self, energy):
)

@reference_mass.setter
def reference_mass(self, mass, unit=None):
def reference_mass(self, mass):
if isinstance(mass, u.array.unyt_quantity):
self._reference_values["mass"] = mass
elif isinstance(unit, str) and (
isinstance(mass, float) or isinstance(mass, int)
):
self._reference_values["mass"] = mass * getattr(u, unit)
elif isinstance(mass, str) and len(mass.split()) == 2:
value, unit = mass.split()
if value.isnumeric() and hasattr(u, unit):
self._reference_values["mass"] = float(value) * getattr(u, unit)
else:
raise ReferenceUnitError(
f"Invalid reference mass input.Please provide reference "
f"mass (number) and unit (string) or pass mass value as "
f"an {str(u.array.unyt_quantity)}."
)
else:
raise ReferenceUnitError(
f"Invalid reference mass input.Please provide reference "
Expand Down

0 comments on commit 9483944

Please sign in to comment.