Repository navigation
Description
I found this when working on #184. It's not particularly bad behavior but I would like us to decide whether or not we want to keep it.
In the current version (happens to be at bfd1933), calling create_dataset converts SMILES to mapped SMILES in-place
In [1]: from tyff.targets.thermo import DataEntry, create_dataset
In [2]: entry = DataEntry({
...: "id": None,
...: "tag": "density",
...: "smiles_a": "CO",
...: "x_a": 0.5,
...: "smiles_b": "O",
...: "x_b": 0.5,
...: "temperature": 298.15,
...: "pressure": 1.0,
...: "value": 0.785,
...: "std": 0.001,
...: "units": "g/mL",
...: "source": "",
...: })
In [3]: entry["smiles_a"]
Out[3]: 'CO'
In [4]: create_dataset(entry)['smiles_a']
Out[4]: Column(['[C:1]([O:2][H:6])([H:3])([H:4])[H:5]'])
In [5]: entry["smiles_a"]
Out[5]: '[C:1]([O:2][H:6])([H:3])([H:4])[H:5]'I think it is somewhat self-explanatory that it happens because of this code:
Lines 153 to 160 in bfd1933
| for row in rows: | |
| row["smiles_a"] = tyff.utils.molecule.map_smiles(row["smiles_a"]) | |
| if row["smiles_b"] is None: | |
| continue | |
| row["smiles_b"] = tyff.utils.molecule.map_smiles(row["smiles_b"]) | |
In the semi-duplicated code, I avoided this with a simple copy:
tyff/tyff/configs/targets/thermo.py
Lines 49 to 58 in bfd1933
| copied_entries = list() | |
| for entry in entries: | |
| # Copy input data to avoid side effects | |
| copied_entry = copy.deepcopy(entry) | |
| copied_entry["smiles"] = [map_smiles(value) for value in copied_entry["smiles"]] | |
| copied_entries.append(copied_entry) | |
This breaks tests that do any string comparisons between input and mapped SMILES strings, although the behavior is likely the same for most behaviors since they're functionally similar enough.
It could be argued this is a net positive - it's almost like input validation that ensures the input ends up mapped. But if that were the case we'd want it to happen earlier so that the third cell above reports a mapped SMILES.
Activity