diff --git a/package/MDAnalysis/topology/base.py b/package/MDAnalysis/topology/base.py index b075ca64a38..f27288a1534 100644 --- a/package/MDAnalysis/topology/base.py +++ b/package/MDAnalysis/topology/base.py @@ -144,11 +144,11 @@ def squash_by(child_parent_ids, *attributes): def squash_by_attributes(squash_attributes, *other_attributes): """Squash a child-parent relationship using combinations of attributes - parents will retain their order of appearance + parents will retain their order of appearance Arguments --------- - squash_attributes - list of attribute arrays (attributes used to + squash_attributes - list of attribute arrays (attributes used to identify the parent) *other_attributes - other arrays that need to follow the sorting of ids @@ -164,18 +164,17 @@ def squash_by_attributes(squash_attributes, *other_attributes): unique_combos, sort_mask, atom_idx = np.unique( squash_array, return_index=True, return_inverse=True, axis=0) - appearance_order = np.argsort(sort_mask) - new_index = np.arange(0,len(appearance_order)) + new_index = np.arange(0, len(appearance_order)) resort_pairs = np.column_stack((appearance_order, new_index)) atom_idx_mapping = dict(resort_pairs) sorted_atom_idx = np.vectorize(atom_idx_mapping.get)(atom_idx).astype(int) sorted_mask = np.sort(sort_mask) - + squashed_attrs = [attr[sorted_mask] for attr in squash_attributes] other_attrs = [attr[sorted_mask] for attr in other_attributes] - + return sorted_atom_idx, squashed_attrs, other_attrs diff --git a/testsuite/MDAnalysisTests/topology/test_mol2.py b/testsuite/MDAnalysisTests/topology/test_mol2.py index ad4a0ba2411..a71c4699888 100644 --- a/testsuite/MDAnalysisTests/topology/test_mol2.py +++ b/testsuite/MDAnalysisTests/topology/test_mol2.py @@ -317,6 +317,7 @@ def test_unformat(): match='Some atoms in the mol2 file'): u = mda.Universe(StringIO(mol2_resname_unformat), format='MOL2') + def test_repeat_resid(): u = mda.Universe(StringIO(mol2_repeat_resid), format='MOL2') diff --git a/testsuite/MDAnalysisTests/topology/test_pdb.py b/testsuite/MDAnalysisTests/topology/test_pdb.py index f19f3c18a2e..ee0c2e4d910 100644 --- a/testsuite/MDAnalysisTests/topology/test_pdb.py +++ b/testsuite/MDAnalysisTests/topology/test_pdb.py @@ -330,11 +330,12 @@ def test_nobonds_error(): pdb_repeat_resid = """\ ATOM 1 CA LYS A 1 65.978 40.866 -0.183 1.00 0.00 C -ATOM 2 CA SER A 2 64.324 40.006 3.164 1.00 0.00 C -ATOM 3 CA LEU A 1 64.000 39.236 8.648 1.00 0.00 C -ATOM 4 N LYS A 1 66.135 42.099 -1.007 1.00 0.00 N1+ +ATOM 2 CA SER A 2 64.324 40.006 3.164 1.00 0.00 C +ATOM 3 CA LEU A 1 64.000 39.236 8.648 1.00 0.00 C +ATOM 4 N LYS A 1 66.135 42.099 -1.007 1.00 0.00 N """ + def test_repeat_resid(): u = mda.Universe(StringIO(pdb_repeat_resid), format='PDB')