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 sidechain hydrogen selection #594

Merged
merged 6 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Binary file modified molecularnodes/assets/MN_data_file_4.2.blend
Binary file not shown.
4,080 changes: 3,126 additions & 954 deletions molecularnodes/data.py

Large diffs are not rendered by default.

27 changes: 21 additions & 6 deletions molecularnodes/entities/molecule/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import biotite.structure as struc
import bpy
import numpy as np
import numpy.typing as npt
from biotite import InvalidFileError

from ... import blender as bl
from ..entity import MolecularEntity
from ... import color, data, utils
from ..entity import MolecularEntity


class Molecule(MolecularEntity, metaclass=ABCMeta):
Expand Down Expand Up @@ -479,6 +480,8 @@ def att_is_backbone():
"N",
"C",
"CA",
"H", # backbone hydrogen off N
"HA", # backbone hydrogen off CA
"O", # peptide backbone atoms
"P",
"O5'",
Expand All @@ -496,25 +499,31 @@ def att_is_backbone():
"O2'", # remaining ribose atoms
]

is_backbone = np.logical_and(
return np.logical_and(
np.isin(array.atom_name, backbone_atom_names),
np.logical_not(struc.filter_solvent(array)),
)
return is_backbone

def att_is_nucleic():
def att_is_nucleic() -> npt.NDArray[np.bool_]:
return struc.filter_nucleotides(array)

def att_is_peptide():
def att_is_peptide() -> npt.NDArray[np.bool_]:
aa = struc.filter_amino_acids(array)
con_aa = struc.filter_canonical_amino_acids(array)

return aa | con_aa

def att_is_side_chain() -> npt.NDArray[np.bool_]:
not_backbone = np.logical_not(att_is_backbone())

return np.logical_and(
not_backbone, np.logical_or(att_is_nucleic(), att_is_peptide())
)

def att_is_hetero():
return array.hetero

def att_is_carb():
def att_is_carb() -> npt.NDArray[np.bool_]:
return struc.filter_carbohydrates(array)

def att_sec_struct():
Expand Down Expand Up @@ -564,6 +573,12 @@ def att_sec_struct():
"type": "BOOLEAN",
"domain": "POINT",
},
{
"name": "is_side_chain",
"value": att_is_side_chain,
"type": "BOOLEAN",
"domain": "POINT",
},
{
"name": "is_alpha_carbon",
"value": att_is_alpha,
Expand Down
468 changes: 300 additions & 168 deletions tests/__snapshots__/test_attributes.ambr

Large diffs are not rendered by default.

1,406 changes: 901 additions & 505 deletions tests/__snapshots__/test_load.ambr

Large diffs are not rendered by default.

86 changes: 68 additions & 18 deletions tests/__snapshots__/test_mol_sdf.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,22 @@
False False False False]
# ---
# name: test_load[ball_and_stick-mol].22
[False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False]
# ---
# name: test_load[ball_and_stick-mol].23
[1 1 2 1 2 1 1 2 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 2 1 1 2 1 1 2 2 2 1 1 1 2 1 1 2 1 1 1 1 1
1 2 1 1 1 1 1 1 1 2 1 1 1 2 1 2 1 1 2 1 1 2 1 1 1 1]
# ---
# name: test_load[ball_and_stick-mol].23
# name: test_load[ball_and_stick-mol].24
[12.0 12.0 12.0 14.0 16.0 1.0 6.5 13.0 13.0 14.0 16.0 6.5 1.0 12.0
12.0 1.0 16.0 12.0 12.0 14.0 12.0 14.0 12.0 14.0 6.5 12.0 1.0 14.0
12.0 14.0 1.0 14.0 6.5 1.0 14.0 14.0 1.0 1.0 13.0 13.0 12.0 12.0
Expand Down Expand Up @@ -668,11 +679,22 @@
False False False False]
# ---
# name: test_load[ball_and_stick-sdf].22
[False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False]
# ---
# name: test_load[ball_and_stick-sdf].23
[2 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 2 2 1 1 1 1 2 1 1 1 2 1 1 1 2 1
1 2 1 2 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 1 1 1 1 2 1 1 2 1 1 1 1 1
1 1 2 1 1 2 2 1 1 2 1 1 1 1 1 1 2 1 2 1 1 1 2 1 1 1]
# ---
# name: test_load[ball_and_stick-sdf].23
# name: test_load[ball_and_stick-sdf].24
[16.0 12.0 12.0 14.0 12.0 1.0 6.5 13.0 13.0 12.0 12.0 6.5 1.0 12.0
12.0 1.0 12.0 12.0 12.0 14.0 12.0 14.0 14.0 12.0 6.5 12.0 1.0 12.0
12.0 14.0 1.0 14.0 6.5 1.0 12.0 14.0 1.0 1.0 14.0 13.0 16.0 12.0
Expand Down Expand Up @@ -1029,11 +1051,22 @@
False False False False]
# ---
# name: test_load[spheres-mol].22
[False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False]
# ---
# name: test_load[spheres-mol].23
[1 1 1 2 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
# ---
# name: test_load[spheres-mol].23
# name: test_load[spheres-mol].24
[ 1. 12. 1. 16. 12. 1. 12. 16. 16. 14. 1. 1. 12. 1. 1. 1. 12. 12.
1. 16. 12. 12. 1. 14. 1. 1. 12. 1. 12. 12. 1. 14. 14. 12. 12. 1.
1. 1. 12. 1. 1. 1. 1. 14. 1. 12. 12. 14. 12. 1. 12. 1. 12. 12.
Expand Down Expand Up @@ -1388,11 +1421,22 @@
False False False False]
# ---
# name: test_load[spheres-sdf].22
[False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False]
# ---
# name: test_load[spheres-sdf].23
[1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 1 1
1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1]
# ---
# name: test_load[spheres-sdf].23
# name: test_load[spheres-sdf].24
[ 1. 12. 1. 12. 16. 1. 14. 12. 12. 14. 1. 1. 16. 1. 1. 1. 12. 16.
1. 12. 14. 16. 1. 14. 1. 1. 12. 1. 12. 12. 1. 12. 14. 12. 12. 1.
1. 1. 14. 1. 1. 1. 1. 12. 1. 12. 12. 12. 12. 1. 12. 1. 14. 12.
Expand Down Expand Up @@ -1662,30 +1706,33 @@
AttributeError("The selected attribute 'is_backbone' does not exist on the mesh.")
# ---
# name: test_load[surface-mol].16
AttributeError("The selected attribute 'is_alpha_carbon' does not exist on the mesh.")
AttributeError("The selected attribute 'is_side_chain' does not exist on the mesh.")
# ---
# name: test_load[surface-mol].17
AttributeError("The selected attribute 'is_solvent' does not exist on the mesh.")
AttributeError("The selected attribute 'is_alpha_carbon' does not exist on the mesh.")
# ---
# name: test_load[surface-mol].18
AttributeError("The selected attribute 'is_nucleic' does not exist on the mesh.")
AttributeError("The selected attribute 'is_solvent' does not exist on the mesh.")
# ---
# name: test_load[surface-mol].19
AttributeError("The selected attribute 'is_peptide' does not exist on the mesh.")
AttributeError("The selected attribute 'is_nucleic' does not exist on the mesh.")
# ---
# name: test_load[surface-mol].2
AttributeError("The selected attribute 'vdw_radii' does not exist on the mesh.")
# ---
# name: test_load[surface-mol].20
AttributeError("The selected attribute 'is_hetero' does not exist on the mesh.")
AttributeError("The selected attribute 'is_peptide' does not exist on the mesh.")
# ---
# name: test_load[surface-mol].21
AttributeError("The selected attribute 'is_carb' does not exist on the mesh.")
AttributeError("The selected attribute 'is_hetero' does not exist on the mesh.")
# ---
# name: test_load[surface-mol].22
AttributeError("The selected attribute 'bond_type' does not exist on the mesh.")
AttributeError("The selected attribute 'is_carb' does not exist on the mesh.")
# ---
# name: test_load[surface-mol].23
AttributeError("The selected attribute 'bond_type' does not exist on the mesh.")
# ---
# name: test_load[surface-mol].24
AttributeError("The selected attribute 'mass' does not exist on the mesh.")
# ---
# name: test_load[surface-mol].3
Expand Down Expand Up @@ -1934,30 +1981,33 @@
AttributeError("The selected attribute 'is_backbone' does not exist on the mesh.")
# ---
# name: test_load[surface-sdf].16
AttributeError("The selected attribute 'is_alpha_carbon' does not exist on the mesh.")
AttributeError("The selected attribute 'is_side_chain' does not exist on the mesh.")
# ---
# name: test_load[surface-sdf].17
AttributeError("The selected attribute 'is_solvent' does not exist on the mesh.")
AttributeError("The selected attribute 'is_alpha_carbon' does not exist on the mesh.")
# ---
# name: test_load[surface-sdf].18
AttributeError("The selected attribute 'is_nucleic' does not exist on the mesh.")
AttributeError("The selected attribute 'is_solvent' does not exist on the mesh.")
# ---
# name: test_load[surface-sdf].19
AttributeError("The selected attribute 'is_peptide' does not exist on the mesh.")
AttributeError("The selected attribute 'is_nucleic' does not exist on the mesh.")
# ---
# name: test_load[surface-sdf].2
AttributeError("The selected attribute 'vdw_radii' does not exist on the mesh.")
# ---
# name: test_load[surface-sdf].20
AttributeError("The selected attribute 'is_hetero' does not exist on the mesh.")
AttributeError("The selected attribute 'is_peptide' does not exist on the mesh.")
# ---
# name: test_load[surface-sdf].21
AttributeError("The selected attribute 'is_carb' does not exist on the mesh.")
AttributeError("The selected attribute 'is_hetero' does not exist on the mesh.")
# ---
# name: test_load[surface-sdf].22
AttributeError("The selected attribute 'bond_type' does not exist on the mesh.")
AttributeError("The selected attribute 'is_carb' does not exist on the mesh.")
# ---
# name: test_load[surface-sdf].23
AttributeError("The selected attribute 'bond_type' does not exist on the mesh.")
# ---
# name: test_load[surface-sdf].24
AttributeError("The selected attribute 'mass' does not exist on the mesh.")
# ---
# name: test_load[surface-sdf].3
Expand Down
Loading
Loading