Skip to content

Commit

Permalink
remove "adding" fixes -- keep only "deletion" fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyminium committed Oct 26, 2024
1 parent 560ad70 commit fa68282
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions package/MDAnalysis/core/topologyattrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3042,12 +3042,19 @@ class _Connection(AtomAttr, metaclass=_ConnectionTopologyAttrMeta):

@_check_connection_values
def __init__(self, values, types=None, guessed=False, order=None):
self.values = []
self.types = []
self._guessed = []
self.order = []
self.values = values
if types is None:
types = [None] * len(values)
self.types = types
if guessed in (True, False):
# if single value passed, multiply this across
# all bonds
guessed = [guessed] * len(values)
self._guessed = guessed
if order is None:
order = [None] * len(values)
self.order = order
self._cache = dict()
self._add_bonds(values, types, guessed, order)

def copy(self):
"""Return a deepcopy of this attribute"""
Expand Down Expand Up @@ -3111,8 +3118,9 @@ def _add_bonds(self, values, types=None, guessed=True, order=None):
if order is None:
order = itertools.cycle((None,))

existing = set(self.values)
for v, t, g, o in zip(values, types, guessed, order):
if v not in self.values:
if v not in existing:
self.values.append(v)
self.types.append(t)
self._guessed.append(g)
Expand Down
4 changes: 2 additions & 2 deletions testsuite/MDAnalysisTests/topology/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def parse():
struc = parse()

assert hasattr(struc, 'bonds')
assert len(struc.bonds.values) == 2
assert len(struc.bonds.values) == 4


def test_single_conect():
Expand All @@ -158,7 +158,7 @@ def parse():
with pytest.warns(UserWarning):
struc = parse()
assert hasattr(struc, 'bonds')
assert len(struc.bonds.values) == 1
assert len(struc.bonds.values) == 2


def test_new_chainid_new_res():
Expand Down

0 comments on commit fa68282

Please sign in to comment.