Open ijpulidos opened 1 year ago
Woah, that's weird and I can reproduce this. Molecule.from_file
returns a List[Molecule]
when given a multi-molecule SDF file. It looks like list.index
is choking on equality checking, which makes sense given that we override it.
There's probably a way to make some sort of class MoleculeList(list)
that overrides
The docs suggest that list.index
is supposed to raise a ValueError
when the item is not found in the list (which would be the case here - "some_item"
is not going to be found in a list of Molecule
objects). Switching that exception would be a marginal API break. Raising a new exception that inherits from both would be either not a behavior change or a marginal one, depending on one's perspective of things. TypeError
does seem like the right one to use here according to the official docs, if using built-in exception types.
Describe the bug
When I tried read a list of molecules form an sdf file and try to apply the
.index
method (list
method) I get an unexpected behavior.It might be a minor issue but it was unexpected.
To Reproduce The code to reproduce the issue is the following:
The
ligands.sdf
file to reproduce the issue is attached.Output
The ipython traceback is as follows:
traceback
```python --------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In [15], line 1 ----> 1 molecules.index("some_name") File ~/miniconda3/envs/openff-0.11/lib/python3.10/site-packages/openff/toolkit/topology/molecule.py:1300, in FrozenMolecule.__eq__(self, other) 1287 """ 1288 Test two molecules for equality to see if they are the chemical species, but do not check other 1289 annotated properties. (...) 1296 1297 """ 1298 # updated to use the new isomorphic checking method, with full matching 1299 # TODO the doc string did not match the previous function what matching should this method do? -> 1300 return Molecule.are_isomorphic(self, other, return_atom_map=False)[0] File ~/miniconda3/envs/openff-0.11/lib/python3.10/site-packages/openff/toolkit/topology/molecule.py:1917, in FrozenMolecule.are_isomorphic(mol1, mol2, return_atom_map, aromatic_matching, formal_charge_matching, bond_order_matching, atom_stereochemistry_matching, bond_stereochemistry_matching, strip_pyrimidal_n_atom_stereo, toolkit_registry) 1911 raise TypeError( 1912 "are_isomorphic accepts a NetworkX Graph or OpenFF " 1913 + f"(Frozen)Molecule, not {type(obj)}" 1914 ) 1916 # Quick number of atoms check. Important for large molecules -> 1917 if _object_to_n_atoms(mol1) != _object_to_n_atoms(mol2): 1918 return False, None 1920 # If the number of atoms match, check the Hill formula File ~/miniconda3/envs/openff-0.11/lib/python3.10/site-packages/openff/toolkit/topology/molecule.py:1911, in FrozenMolecule.are_isomorphic.I was expecting a
ValueError: 'some_name' is not in list
as the error output.Computing environment (please complete the following information):
Output of running `conda list`
ligands.sdf.zip