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

Collapse classes for Molecule #766

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft

Collapse classes for Molecule #766

wants to merge 26 commits into from

Conversation

BradyAJohnston
Copy link
Owner

@BradyAJohnston BradyAJohnston commented Feb 28, 2025

Collapses classes for different data formats that are all now handled by the Molecule class.

Simplifies much of the attribute creation logic and code. All potential attributes are initially computed when reading in the file, and set as annotations on the AtomArray.

Then there is just a generic step where all numeric annotations are stored on the mesh as named attributes. This additionally then supports any generic numerical attributes into the future.

New import methods currently don't support:

  • building assembly on import or with code
  • centering on import
  • adding additional styles
  • using selections when adding styles

@BradyAJohnston BradyAJohnston changed the title initial working import from PDB Collapse classes for Molecule Feb 28, 2025
@@ -23,6 +23,7 @@ def __init__(self) -> None:
super().__init__(obj=None)
self._entity_type: EntityType
self._register_with_session()
self._world_scale = 0.01
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other non-decanted attribute I had encountered is _assemblies. Not sure if it's needed. But if it is it mid the nice to declare up top

from ... import color


class ReaderBase(metaclass=ABCMeta):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this.

if isinstance(file_path, str):
file_path = Path(file_path)

match file_path.suffix:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

"""
return self._code

def _read(self, file_path: str | Path | io.BytesIO) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: why not just load in the data? E.g. instead of returning a handle, why not just create the AtomArray with the fields of interest. You could optionally set the handle as well. Seems like an extra bit of indirection

super().__init__()
self._read(file_path)
self.atom_array: AtomArray | AtomArrayStack
self._create_object()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are using self.tree in other locations? Maybe it would be helpful to declare it here as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops. no you are using self.object

mol._code = code

if centre:
mol.position + -mol.centroid(centre)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to declare mol.position as an attribute at top.

Otherwise it might be mol.object.postion?

@@ -338,7 +333,7 @@ def assemblies(self, as_array=False):
transformation matrices, or None if no assemblies are available.
"""
try:
assemblies_info = self._assemblies()
assemblies_info = self._assemblies
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add _assemblies as a top level attribute in Init.

@@ -64,7 +65,8 @@ def test_selection_working(snapshot_custom: NumpySnapshotExtension, attribute, c
@pytest.mark.parametrize("code", codes)
@pytest.mark.parametrize("attribute", ["chain_id", "entity_id"])
def test_color_custom(snapshot_custom: NumpySnapshotExtension, code, attribute):
mol = mn.entities.fetch(code, style="ribbon", cache_dir=data_dir)
mol = mn.Molecule.fetch(code, cache=data_dir)
mol.add_style("ribbon")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer Set style to Add_style . Add_style implies more than one style.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going with add_style() so that we can add multiple styles on the same Molecule, which will just be additional branches in the node tree. Currently calling add_style() once will be equivalent to the previous style setyp.

Copy link

codecov bot commented Mar 9, 2025

Codecov Report

Attention: Patch coverage is 92.70833% with 28 lines in your changes missing coverage. Please review.

Project coverage is 75.75%. Comparing base (92eed49) to head (21a9126).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
molecularnodes/entities/molecule/base.py 91.05% 11 Missing ⚠️
molecularnodes/entities/molecule/reader.py 92.98% 8 Missing ⚠️
molecularnodes/ui/ops.py 50.00% 4 Missing ⚠️
molecularnodes/entities/molecule/pdbx.py 91.30% 2 Missing ⚠️
molecularnodes/entities/molecule/pdb.py 91.66% 1 Missing ⚠️
tests/test_load.py 92.30% 1 Missing ⚠️
tests/test_nodes.py 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #766      +/-   ##
==========================================
- Coverage   76.21%   75.75%   -0.46%     
==========================================
  Files          78       77       -1     
  Lines        5297     5235      -62     
==========================================
- Hits         4037     3966      -71     
- Misses       1260     1269       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants