Skip to content

load_sdf imports first reference id only #249

Description

@laurenreid1

Tested using develop branch but bug appears to also be present in main.

The following snippet calls animal.load_sdf and includes the reference_col keyword argument to signal that the reference_id SDF column should be used to register the HIPPO references:

animal = hippo.HIPPO(f"<TARGET>.sqlite", update_legacy=True)

animal.load_sdf(
                target=target_name, 
                path="<PATH_TO_SDF>", 
                inspiration_col="inspiration_ids", 
                reference_col="reference_id",
                compound_tags = ["<TAG>"],
                pose_tags = ["<TAG>"],
                name_col = "ID",
            )

However animal.py lines 837-845 (in develop branch):

Image

takes the first rows reference_id and assigns it to the reference variable. The following rows then skip these lines of code because the reference variable is not None. The result is that every pose is assigned to the first row's reference in the DB.

Suggestion:

Change animal.py lines 837-845 (develop branch) to something like this:

            if not reference:
                ref_str = row.get(reference_col)
                if ref_str:
                    try:
                        row_reference = int(ref_str)
                    except ValueError:
                        row_reference = inspiration_map[ref_str]
                else:
                    row_reference = None

            elif isinstance(reference, Pose):
                row_reference = reference.id

and lines 891-906 to:

            data.append(
                dict(
                    alias=alias,
                    compound_id=compound_id,
                    target_id=target.id,
                    path=pose_path,
                    metadata=metadata,
                    inspiration_ids=inspiration_list,
                    reference_id=row_reference,
                    mol=mol,
                    inchikey=inchikey,
                    smiles=smiles,
                    energy_score=energy_score,
                    distance_score=distance_score,
                )
            )

Note - introduction of row_reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions