chemosim-lab / ProLIF

Interaction Fingerprints for protein-ligand complexes and more
https://prolif.readthedocs.io
Apache License 2.0
361 stars 68 forks source link

fp.ifp[0].keys() does not return a list of keys #165

Closed forcefield closed 11 months ago

forcefield commented 11 months ago

Here fp is a prolif.fingerprint.Fingerprint.

fp.ifp[0].keys() should give a list of keys. Instead, it returns a KeysView of the original dictionary. I cannot find a way to retrieve the keys at all.

e.g.

fp.ifp[0] returns

{(ResidueId(UNL, 1, None), ResidueId(MET, 929, A)): {'Hydrophobic': ({'indices': {'ligand': (3,), 'protein': (7,)}, 'parent_indices': {'ligand': (3,), 'protein': (6527,)}, 'distance': 3.9180193486386},), 'VdWContact': ({'indices': {'ligand': (1,), 'protein': (6,)}, 'parent_indices': {'ligand': (1,), 'protein': (6526,)}, 'distance': 2.851403921148278},)}, (ResidueId(UNL, 1, None), ResidueId(VAL, 863, A)): {'Hydrophobic': ({'indices': {'ligand': (3,), 'protein': (5,)}, 'parent_indices': {'ligand': (3,), 'protein': (5433,)}, 'distance': 4.420255973772806},)}, (ResidueId(UNL, 1, None), ResidueId(GLU, 930, A)): {'HBDonor': ({'indices': {'ligand': (0, 2), 'protein': (3,)}, 'parent_indices': {'ligand': (0, 2), 'protein': (6540,)}, 'distance': 3.081011454313653, 'DHA_angle': 151.66521850843512},), 'VdWContact': ({'indices': {'ligand': (2,), 'protein': (3,)}, 'parent_indices': {'ligand': (2,), 'protein': (6540,)}, 'distance': 2.132080626872604},)}, (ResidueId(UNL, 1, None), ResidueId(LEU, 983, A)): {'Hydrophobic': ({'indices': {'ligand': (3,), 'protein': (6,)}, 'parent_indices': {'ligand': (3,), 'protein': (7462,)}, 'distance': 3.5994858121918982},), 'VdWContact': ({'indices': {'ligand': (15,), 'protein': (15,)}, 'parent_indices': {'ligand': (15,), 'protein': (7471,)}, 'distance': 2.8897432544251225},)}, (ResidueId(UNL, 1, None), ResidueId(LEU, 855, A)): {'Hydrophobic': ({'indices': {'ligand': (5,), 'protein': (6,)}, 'parent_indices': {'ligand': (5,), 'protein': (5327,)}, 'distance': 4.472858326888363},), 'VdWContact': ({'indices': {'ligand': (7,), 'protein': (14,)}, 'parent_indices': {'ligand': (7,), 'protein': (5335,)}, 'distance': 2.796897946487031},)}, (ResidueId(UNL, 1, None), ResidueId(LEU, 932, A)): {'VdWContact': ({'indices': {'ligand': (7,), 'protein': (3,)}, 'parent_indices': {'ligand': (7,), 'protein': (6576,)}, 'distance': 3.1575852263979045},)}, (ResidueId(UNL, 1, None), ResidueId(ALA, 880, A)): {'Hydrophobic': ({'indices': {'ligand': (3,), 'protein': (4,)}, 'parent_indices': {'ligand': (3,), 'protein': (5692,)}, 'distance': 3.752919974086211},)}}

But fp.ifp[0].keys() returns

KeysView({(ResidueId(UNL, 1, None), ResidueId(MET, 929, A)): {'Hydrophobic': ({'indices': {'ligand': (3,), 'protein': (7,)}, 'parent_indices': {'ligand': (3,), 'protein': (6527,)}, 'distance': 3.9180193486386},), 'VdWContact': ({'indices': {'ligand': (1,), 'protein': (6,)}, 'parent_indices': {'ligand': (1,), 'protein': (6526,)}, 'distance': 2.851403921148278},)}, (ResidueId(UNL, 1, None), ResidueId(VAL, 863, A)): {'Hydrophobic': ({'indices': {'ligand': (3,), 'protein': (5,)}, 'parent_indices': {'ligand': (3,), 'protein': (5433,)}, 'distance': 4.420255973772806},)}, (ResidueId(UNL, 1, None), ResidueId(GLU, 930, A)): {'HBDonor': ({'indices': {'ligand': (0, 2), 'protein': (3,)}, 'parent_indices': {'ligand': (0, 2), 'protein': (6540,)}, 'distance': 3.081011454313653, 'DHA_angle': 151.66521850843512},), 'VdWContact': ({'indices': {'ligand': (2,), 'protein': (3,)}, 'parent_indices': {'ligand': (2,), 'protein': (6540,)}, 'distance': 2.132080626872604},)}, (ResidueId(UNL, 1, None), ResidueId(LEU, 983, A)): {'Hydrophobic': ({'indices': {'ligand': (3,), 'protein': (6,)}, 'parent_indices': {'ligand': (3,), 'protein': (7462,)}, 'distance': 3.5994858121918982},), 'VdWContact': ({'indices': {'ligand': (15,), 'protein': (15,)}, 'parent_indices': {'ligand': (15,), 'protein': (7471,)}, 'distance': 2.8897432544251225},)}, (ResidueId(UNL, 1, None), ResidueId(LEU, 855, A)): {'Hydrophobic': ({'indices': {'ligand': (5,), 'protein': (6,)}, 'parent_indices': {'ligand': (5,), 'protein': (5327,)}, 'distance': 4.472858326888363},), 'VdWContact': ({'indices': {'ligand': (7,), 'protein': (14,)}, 'parent_indices': {'ligand': (7,), 'protein': (5335,)}, 'distance': 2.796897946487031},)}, (ResidueId(UNL, 1, None), ResidueId(LEU, 932, A)): {'VdWContact': ({'indices': {'ligand': (7,), 'protein': (3,)}, 'parent_indices': {'ligand': (7,), 'protein': (6576,)}, 'distance': 3.1575852263979045},)}, (ResidueId(UNL, 1, None), ResidueId(ALA, 880, A)): {'Hydrophobic': ({'indices': {'ligand': (3,), 'protein': (4,)}, 'parent_indices': {'ligand': (3,), 'protein': (5692,)}, 'distance': 3.752919974086211},)}})
cbouy commented 11 months ago

Not sure I understand the issue here, KeysView acts the same way as a standard dict keys, i.e. if you iterate over fp.ifp[0].keys() you simply get the keys, it's just that it prints slightly differently in a shell (in a regular dict you wouldn't see the values like {'Hydrophobic': ({'indices': {'ligand': (3,), 'pr...). You can do fp.ifp[0].data.keys() if you want to but it's more of an implementation detail than anything else. If you really need a list of keys, it's best to do list(fp.ifp[0]), and if you only want the first key next(iter(fp.ifp[0]))