Skip to content

Commit

Permalink
more test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
BradyAJohnston committed Jan 14, 2025
1 parent 545d6dc commit e8294d0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
23 changes: 16 additions & 7 deletions molecularnodes/entities/molecule/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,25 @@ class MN_OT_Import_wwPDB(bpy.types.Operator):
description="Add a node to build the biological assembly on import",
default=False,
)
style: EnumProperty( # type: ignore
name="Style",
description="Default style for importing",
items=STYLE_ITEMS,
default="spheres",
)
cache_dir: StringProperty( # type: ignore
name="Cache Directory",
description="Where to store the structures downloaded from the Protein Data Bank",
default=CACHE_DIR,
subtype="DIR_PATH",
)

def execute(self, context):
addon_pref = addon_preferences()
scene = context.scene
cache_dir = addon_pref.cache_dir
file_format = self.file_format

if not addon_pref.cache_download:
cache_dir = None

if self.node_setup:
style = scene.mn.import_style
style = self.style
else:
style = None

Expand All @@ -294,7 +301,7 @@ def execute(self, context):
del_solvent=scene.mn.import_del_solvent,
del_hydrogen=scene.mn.import_del_hydrogen,
style=style,
cache_dir=cache_dir,
cache_dir=self.cache_dir,
build_assembly=self.build_assembly,
format=file_format,
)
Expand Down Expand Up @@ -446,6 +453,8 @@ def panel_wwpdb(layout, scene):
op.file_format = scene.mn.import_format_wwpdb
op.node_setup = scene.mn.import_node_setup
op.build_assembly = scene.mn.import_build_assembly
op.style = scene.mn.import_style
op.cache_dir = str(addon_preferences().cache_dir)
layout.separator(factor=0.4)

layout.separator()
Expand Down
24 changes: 8 additions & 16 deletions tests/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,14 @@ def test_style_1(snapshot_custom: NumpySnapshotExtension, assembly, code, style)
"code, format", itertools.product(codes, ["bcif", "cif", "pdb"])
)
def test_download_format(code, format):
mol = mn.entities.fetch(code, format=format, style=None, cache_dir=data_dir).object
scene = bpy.context.scene
scene.mn.import_pdb_code = code
scene.mn.import_node_setup = False
scene.mn.import_format_wwpdb = format
names = [o.name for o in bpy.data.objects]
bpy.ops.mn.import_wwpdb()

for o in bpy.data.objects:
if o.name not in names:
mol2 = o

def verts(object):
return db.named_attribute(object, "position")

assert np.isclose(verts(mol), verts(mol2)).all()
mol = mn.entities.fetch(code, format=format, style=None, cache_dir=data_dir)
with db.ObjectTracker() as o:
bpy.ops.mn.import_wwpdb(
pdb_code=code, file_format=format, cache_dir=str(data_dir)
)
mol2 = bpy.context.scene.MNSession.match(o.latest())

assert np.allclose(mol.position, mol2.position)


@pytest.mark.parametrize("code", codes)
Expand Down
6 changes: 1 addition & 5 deletions tests/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ def test_op_api_cartoon(
snapshot_custom: NumpySnapshotExtension, code, style="ribbon", format="bcif"
):
scene = bpy.context.scene
scene.mn.import_node_setup = True
scene.mn.import_style = style
scene.mn.import_centre = False
scene.mn.import_del_solvent = False

bpy.ops.mn.import_wwpdb(pdb_code=code, file_format=format, node_setup=True)
bpy.ops.mn.import_wwpdb(pdb_code=code, file_format=format, style=style)
mol1 = scene.MNSession.match(bpy.context.active_object)

mol2 = mn.entities.fetch(code, style=style, format=format, cache_dir=data_dir)
Expand Down

0 comments on commit e8294d0

Please sign in to comment.