Skip to content

Commit

Permalink
Parameterized Parmed Conversions (#721)
Browse files Browse the repository at this point in the history
* Conversion of parmed structure to GMSO should now properly identify unique potential types

* Clean up legacy functions necessary for mapping types to connections

* Update gmso/external/convert_parmed.py

Co-authored-by: Co Quach <43968221+daico007@users.noreply.github.com>

* Update gmso/external/convert_parmed.py

Co-authored-by: Co Quach <43968221+daico007@users.noreply.github.com>

* Update gmso/external/convert_parmed.py

Co-authored-by: Co Quach <43968221+daico007@users.noreply.github.com>

* Modified ParmEd loading to sort new GMSO topology connections by site appearance in the topology. Copies of connection types are made, which must be filtered using potential filters to get whatever subset is considered unique.

* minor changes/cleanup

* minor change for consistency

---------

Co-authored-by: Co Quach <43968221+daico007@users.noreply.github.com>
Co-authored-by: Co Quach <daico007@gmail.com>
  • Loading branch information
3 people authored May 17, 2023
1 parent 78b0d85 commit d068b93
Show file tree
Hide file tree
Showing 10 changed files with 583 additions and 405 deletions.
30 changes: 28 additions & 2 deletions gmso/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,37 @@ def get_name_or_class(potential):
"""Get identifier for a topology potential based on name or membertype/class."""
if isinstance(potential, AtomType):
return potential.name
if isinstance(potential, (BondType, AngleType, DihedralType, ImproperType)):
elif isinstance(
potential, (BondType, AngleType, DihedralType, ImproperType)
):
return potential.member_types or potential.member_classes


def get_sorted_names(potential):
"""Get identifier for a topology potential based on name or membertype/class."""
if isinstance(potential, AtomType):
return potential.name
elif isinstance(potential, BondType):
return tuple(sorted(potential.member_types))
elif isinstance(potential, AngleType):
if potential.member_types[0] > potential.member_types[2]:
return tuple(reversed(potential.member_types))
else:
return potential.member_types
elif isinstance(potential, DihedralType):
if potential.member_types[1] > potential.member_types[2] or (
potential.member_types[1] == potential.member_types[2]
and potential.member_types[0] > potential.member_types[3]
):
return tuple(reversed(potential.member_types))
else:
return potential.member_types
elif isinstance(potential, ImproperType):
return (potential.member_types[0], *sorted(potential.member_types[1:]))


def get_parameters(potential):
"""Return hashable version of parameters for a potential."""

return (
tuple(potential.get_parameters().keys()),
tuple(map(lambda x: x.to_value(), potential.get_parameters().values())),
Expand All @@ -58,6 +82,7 @@ def filtered_potentials(potential_types, identifier):

class PotentialFilters:
UNIQUE_NAME_CLASS = "unique_name_class"
UNIQUE_SORTED_NAMES = "unique_sorted_names"
UNIQUE_EXPRESSION = "unique_expression"
UNIQUE_PARAMETERS = "unique_parameters"
UNIQUE_ID = "unique_id"
Expand All @@ -74,6 +99,7 @@ def all():

potential_identifiers = {
PotentialFilters.UNIQUE_NAME_CLASS: get_name_or_class,
PotentialFilters.UNIQUE_SORTED_NAMES: get_sorted_names,
PotentialFilters.UNIQUE_EXPRESSION: lambda p: str(p.expression),
PotentialFilters.UNIQUE_PARAMETERS: get_parameters,
PotentialFilters.UNIQUE_ID: lambda p: id(p),
Expand Down
Loading

0 comments on commit d068b93

Please sign in to comment.