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

Merge top #249

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
15 changes: 7 additions & 8 deletions polyply/src/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def __init__(self, force_field, name=None):
self.defines = {}
self.atom_types = {}
self.nonbond_params = {}
self.volumes = {}
# list attributes
self.description = []
self.persistences = []
Expand All @@ -243,12 +244,12 @@ def __init__(self, force_field, name=None):
def merge(self, other_top, check_duplicates=True):
"""
Merge two topologies updating their attribute dictionaries.
If check_dublicates is True attribute value combinations
already existent in self will be overwritten by those in
If `check_duplicates` is True attribute value combinations
that already exist will be overwritten by those in
the to be merged topology. An error will raise otherwise if
there are any conflicting dublicate entries.
there are any conflicting duplicate entries.

Note distance restraints are not checked for possibly
Note distance restraints are not checked for possible
Copy link
Member

Choose a reason for hiding this comment

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

Something went wrong here

conflicting definitions.

Parameters
Expand All @@ -260,16 +261,14 @@ def merge(self, other_top, check_duplicates=True):
check for conflicting attribute value pairs

"""
for attribute in ["defaults", "defines", "atom_types", "nonbond_params"]:
for attribute in ["defaults", "defines", "atom_types", "nonbond_params", "volumes"]:
self_dict = getattr(self, attribute)
if check_duplicates:
for key, value in getattr(other_top, attribute).items():
if key in self_dict and self_dict[key] != value:
msg = f"Conflicting entry in {attribute} with key {key}"
raise MergeError(msg)
self_dict[key] = value
else:
getattr(self, attribute).update(getattr(other_top, attribute))
getattr(self, attribute).update(getattr(other_top, attribute))

self.description += other_top.description
self.persistences += other_top.persistences
Expand Down