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

Use list to store compound.children #1121

Merged
merged 1 commit into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions mbuild/coarse_graining.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from mbuild.compound import Compound, clone
from mbuild.exceptions import MBuildError
from mbuild.utils.orderedset import OrderedSet

__all__ = ["coarse_grain"]

Expand Down Expand Up @@ -95,7 +94,7 @@ def _clone(self, clone_of=None, root_container=None):
if self.children is None:
newone.children = None
else:
newone.children = OrderedSet()
newone.children = list()
# Parent should be None initially.
newone.parent = None
newone.labels = OrderedDict()
Expand All @@ -106,7 +105,7 @@ def _clone(self, clone_of=None, root_container=None):
if self.children:
for child in self.children:
newchild = child._clone(clone_of, root_container)
newone.children.add(newchild)
newone.children.append(newchild)
newchild.parent = newone

# Copy labels, except bonds with atoms outside the hierarchy.
Expand Down
13 changes: 6 additions & 7 deletions mbuild/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from mbuild.utils.exceptions import RemovedFuncError
from mbuild.utils.io import import_, run_from_ipython
from mbuild.utils.jsutils import overwrite_nglview_default
from mbuild.utils.orderedset import OrderedSet


def clone(existing_compound, clone_of=None, root_container=None):
Expand Down Expand Up @@ -117,7 +116,7 @@ class Compound(object):
----------
bond_graph : mb.BondGraph
Graph-like object that stores bond information for this Compound
children : OrderedSet
children : list
Contains all children (other Compounds).
labels : OrderedDict
Labels to Compound/Atom mappings. These do not necessarily need not be
Expand Down Expand Up @@ -174,7 +173,7 @@ def __init__(
self._pos = np.zeros(3)

self.parent = None
self.children = OrderedSet()
self.children = list()
self.labels = OrderedDict()
self.referrers = set()

Expand Down Expand Up @@ -920,7 +919,7 @@ def add(

# Create children and labels on the first add operation
if self.children is None:
self.children = OrderedSet()
self.children = list()
if self.labels is None:
self.labels = OrderedDict()

Expand All @@ -931,7 +930,7 @@ def add(
new_child, new_child.parent
)
)
self.children.add(new_child)
self.children.append(new_child)
new_child.parent = self

if new_child.bond_graph is not None and not isinstance(self, Port):
Expand Down Expand Up @@ -3500,7 +3499,7 @@ def _clone(self, clone_of=None, root_container=None):
if self.children is None:
newone.children = None
else:
newone.children = OrderedSet()
newone.children = list()
# Parent should be None initially.
newone.parent = None
newone.labels = OrderedDict()
Expand All @@ -3511,7 +3510,7 @@ def _clone(self, clone_of=None, root_container=None):
if self.children:
for child in self.children:
newchild = child._clone(clone_of, root_container)
newone.children.add(newchild)
newone.children.append(newchild)
newchild.parent = newone

# Copy labels, except bonds with atoms outside the hierarchy.
Expand Down