Skip to content

Commit

Permalink
update base
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Charlop-Powers authored and Zachary Charlop-Powers committed Feb 25, 2025
1 parent 8faa159 commit 9ca4ee1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 15 additions & 1 deletion molecularnodes/entities/molecule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from databpy import Domains, AttributeTypes
import databpy
from ..base import MolecularEntity, EntityType

from .ui import parse

class Molecule(MolecularEntity, metaclass=ABCMeta):
"""
Expand Down Expand Up @@ -100,6 +100,20 @@ def from_array(cls, array: struc.AtomArray, name: str = "FromArray"):
instance.create_object(name=name)
return instance

@classmethod
def load(cls, mol: Union[str, Path, io.BytesIO, struc.AtomArray]):
match mol:
case str() :
return parse(mol)
case Path():
return parse(mol)
case io.BytesIO():
return parse(mol)
case struc.AtomArray():
return Molecule.from_array(mol)
case _:
raise ValueError("Invalid Parsing Type")

@property
def frames(self) -> bpy.types.Collection:
"""
Expand Down
3 changes: 3 additions & 0 deletions tests/test_load_biotite.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ def test_loading():
# use the class method
mol = mn.entities.Molecule.from_array(arr)
assert isinstance(mol, mn.entities.Molecule)

mol = mn.entities.Molecule.load(arr)
assert isinstance(mol, mn.entities.Molecule)

0 comments on commit 9ca4ee1

Please sign in to comment.