Skip to content

Commit

Permalink
Update of naming and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
GardevoirX committed Nov 19, 2024
1 parent b8dce48 commit 5a57100
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion python/chemiscope/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ def show(
"values": (
list(range(len(frames)))
if hasattr(frames, "__len__")
# MDAnalysis `frames` will not be a list, and does not have a `__len__`
# MDAnalysis `frames` will not be a list, and does not have
# a `__len__`
else list(range(len(frames.trajectory)))
),
}
Expand Down
4 changes: 3 additions & 1 deletion python/chemiscope/structures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def frames_to_json(frames):
elif adapter == "stk":
return [_stk_to_json(frame) for frame in frames]
elif adapter == "mda":
return [_mda_to_json(frames.atoms) for frame in frames.trajectory]
# Be careful of the lazy loading of `frames.atoms`, which is updated during the
# iteration of the trajectory
return [_mda_to_json(frames.atoms) for _ in frames.trajectory]
else:
raise Exception("reached unreachable code")

Expand Down
2 changes: 1 addition & 1 deletion python/chemiscope/structures/_mda.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _mda_valid_structures(frames):
def _mda_to_json(ag):
data = {}
data["size"] = len(ag)
data["names"] = [atom.name for atom in ag]
data["names"] = [atom.type for atom in ag]
data["x"] = [float(value) for value in ag.positions[:, 0]]
data["y"] = [float(value) for value in ag.positions[:, 1]]
data["z"] = [float(value) for value in ag.positions[:, 2]]
Expand Down
2 changes: 1 addition & 1 deletion python/chemiscope/structures/_stk.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _stk_valid_structures(
if HAVE_STK and isinstance(frames, Molecule):
# deal with the user passing a single frame
return [frames], True
elif HAVE_STK and hasattr(frames, "__iter__") and isinstance(frames[0], Molecule):
elif HAVE_STK and isinstance(frames, list) and isinstance(frames[0], Molecule):
for frame in frames:
assert isinstance(frame, Molecule)
return frames, True
Expand Down
2 changes: 1 addition & 1 deletion python/tests/mda_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import chemiscope

BASE_FRAME = mda.Universe.empty(n_atoms=3, trajectory=True)
BASE_FRAME.add_TopologyAttr("name", ["C", "O", "O"])
BASE_FRAME.add_TopologyAttr("type", ["C", "O", "O"])
BASE_FRAME.atoms.positions = np.array([[0, 0, 0], [1, 1, 1], [2, 2, 5]])


Expand Down

0 comments on commit 5a57100

Please sign in to comment.