Skip to content

Commit e803001

Browse files
committed
pymol: refactor for view remote rpyc Molecule object
1 parent 15dc942 commit e803001

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# [[file:spdkit-python.note::e345323a][e345323a]]
22
[package]
33
name = "spdkit-python"
4-
version = "0.1.8"
4+
version = "0.1.9"
55
edition = "2021"
66
authors = ["Wenping Guo <[email protected]>"]
77
description = "structure prediction kit for python"

spdkit/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ def view_in_pymol(mol: Molecule, rebond=False, format="pdb"):
6565
molfile = f.name
6666
title = mol.title
6767
lat = mol.get_lattice()
68-
mol.to_file(molfile)
68+
# for work with rpyc remote Molecule object, we do not call
69+
# to_file directly
70+
fmt = io.guess_format_from_path(molfile)
71+
s = mol.format_as(fmt)
72+
open(molfile, "w").write(s)
73+
6974
with tempfile.NamedTemporaryFile(mode="w", suffix=".py") as f:
7075
print(f"pymol.cmd.load('{molfile}', '{title}')\n", file=f)
7176
# pymol doesnot recognize lattice data in mol2 format
@@ -107,7 +112,11 @@ def view_traj_in_pymol(mols: list[Molecule], animated=True, format="mol2", sleep
107112
i += 1
108113
molfile = os.path.join(td, f"{i}.{format}")
109114
title = m.title
110-
m.to_file(molfile)
115+
# for work with rpyc remote Molecule object, we do not call to_file directly
116+
fmt = io.guess_format_from_path(molfile)
117+
s = m.format_as(fmt)
118+
open(molfile, "w").write(s)
119+
111120
if animated:
112121
print(
113122
f"pymol.cmd.load('{molfile}', object='traj', state=0)\n", file=fpy

0 commit comments

Comments
 (0)