cbouy / mols2grid

Interactive molecule viewer for 2D structures

Home Page:https://mols2grid.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Save CSV not working as expected

ale94mleon opened this issue · comments

Hello,
I used the following code from the documentation:

import mols2grid
from pathlib import Path
from rdkit import RDConfig
SDF_FILE = (f"{RDConfig.RDDocsDir}/Book/data/solubility.test.sdf"
            if Path(RDConfig.RDDocsDir).is_dir() else "solubility.test.sdf")

mols2grid.display(
    SDF_FILE,
    # rename fields for the output document
    rename={"SOL": "Solubility",
            "SOL_classification": "Class",
            "NAME": "Name"},
    # set what's displayed on the grid
    subset=["ID", "img", "Solubility"],
    # set what's displayed on the hover tooltip
    tooltip=["Name", "SMILES", "Class", "Solubility"],
    # style for the grid labels and tooltips
    style={
      "Solubility": lambda x: "color: red; font-weight: bold;" if x < -3 else "",
      "__all__": lambda x: "background-color: azure;" if x["Solubility"] > -1 else ""
    },
    # change the precision and format (or other transformations)
    transform={"Solubility": lambda x: round(x, 2)},
    # sort the grid in a different order by default
    sort_by="Name",
    # molecule drawing parameters
    fixedBondLength=25, clearBackground=False
)

Then I checked the molecule with ID = 150, Solubility = -2.37, SMILES = CCCCBr. However, when I open the CSV files, the saved structure was:

index ID Solubility Name SMILES Class      
29 246 -6.8 2 2ᄡ 5 6ᄡ-PCB c1c(Cl)ccc(Cl)c1c2c(Cl)cccc2Cl (A) low

Hi @ale94mleon,

Thanks for reporting this!
I could indeed reproduce the issue, the problem seems to come from sorting the grid, I'll look into it soon.

Cheers,
Cédric