Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix confusing default torch transform #21

Merged
merged 5 commits into from
Sep 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: atom_types was referring to element names before; expose both an…
…d use simpler default encoding containing the integer index of the string defined in pinder constants
  • Loading branch information
danielkovtun committed Sep 25, 2024
commit feb882385f0dab72bcf5f94d96a890cba4733150
23 changes: 14 additions & 9 deletions src/pinder-core/pinder/core/loader/geodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
def structure2tensor(
atom_coordinates: NDArray[np.double] | None = None,
atom_types: NDArray[np.str_] | None = None,
element_types: NDArray[np.str_] | None = None,
residue_coordinates: NDArray[np.double] | None = None,
residue_ids: NDArray[np.int_] | None = None,
residue_types: NDArray[np.str_] | None = None,
Expand All @@ -38,14 +39,16 @@ def structure2tensor(
) -> dict[str, torch.Tensor]:
property_dict = {}
if atom_types is not None:
types_array_ele = np.zeros(
(len(atom_types), len(set(list(pc.ELE2NUM.values()))))
)
unknown_name_idx = max(pc.ALL_ATOM_POSNS.values()) + 1
types_array_at = np.zeros((len(atom_types), 1))
for i, name in enumerate(atom_types):
types_array_ele[i, pc.ELE2NUM.get(name, "C")] = 1.0

property_dict["atom_types"] = torch.tensor(types_array_ele).type(dtype)

types_array_at[i] = pc.ALL_ATOM_POSNS.get(name, unknown_name_idx)
property_dict["atom_types"] = torch.tensor(types_array_at).type(dtype)
if element_types is not None:
types_array_ele = np.zeros((len(element_types), 1))
for i, name in enumerate(element_types):
types_array_ele[i] = pc.ELE2NUM.get(name, pc.ELE2NUM["other"])
property_dict["element_types"] = torch.tensor(types_array_ele).type(dtype)
if residue_types is not None:
unknown_name_idx = max(pc.AA_TO_INDEX.values()) + 1
types_array_res = np.zeros((len(residue_types), 1))
Expand Down Expand Up @@ -119,14 +122,16 @@ def from_structure_pair(
lig_calpha = ligand.filter("atom_name", mask=["CA"])
rec_props = structure2tensor(
atom_coordinates=receptor.coords,
atom_types=receptor.atom_array.element,
atom_types=receptor.atom_array.atom_name,
element_types=receptor.atom_array.element,
residue_coordinates=rec_calpha.coords,
residue_types=rec_calpha.atom_array.res_name,
residue_ids=rec_calpha.atom_array.res_id,
)
lig_props = structure2tensor(
atom_coordinates=ligand.coords,
atom_types=ligand.atom_array.element,
atom_types=ligand.atom_array.atom_name,
element_types=ligand.atom_array.element,
residue_coordinates=lig_calpha.coords,
residue_types=lig_calpha.atom_array.res_name,
residue_ids=lig_calpha.atom_array.res_id,
Expand Down