Skip to content

Commit 63ad88c

Browse files
committed
add lattice as a scene property and make structure automatically assign it
1 parent 84fabc8 commit 63ad88c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

crystal_toolkit/core/scene.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Scene:
4545
contents: list = field(default_factory=list)
4646
origin: List[float] = field(default=(0, 0, 0))
4747
visible: bool = True
48+
lattice: Optional[List[List[float]]] = None
4849
_meta: Dict = None
4950

5051
def __add__(self, other):
@@ -61,6 +62,7 @@ def __add__(self, other):
6162
contents=self.contents + other.contents,
6263
origin=self.origin,
6364
visible=self.visible,
65+
lattice=self.lattice,
6466
_meta={self.name: self._meta, other.name: other._meta},
6567
)
6668

@@ -91,6 +93,7 @@ def to_json(self):
9193
name=self.name,
9294
contents=self.merge_primitives(self.contents),
9395
origin=self.origin,
96+
lattice=self.lattice,
9497
)
9598

9699
def remove_defaults(scene_dict):

crystal_toolkit/renderables/structure.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def get_structure_scene(
6969
Args:
7070
self: Structure object
7171
origin: fractional coordinate of the origin
72-
legend: Legend for the sites
72+
legend: Legend for the sites\
7373
draw_image_atoms: If true draw image atoms that are just outside the
7474
periodic boundary
7575
@@ -95,16 +95,18 @@ def get_structure_scene(
9595
site.lattice,
9696
properties=site.properties,
9797
)
98-
9998
site_scene = site.get_scene(legend=legend,)
10099
for scene in site_scene.contents:
101100
primitives[scene.name] += scene.contents
102101

103102
primitives["unit_cell"].append(self.lattice.get_scene())
104103

104+
lattice_vectors = [list(array) for array in self.lattice.matrix]
105+
105106
return Scene(
106107
name="Structure",
107108
origin=origin,
109+
lattice=lattice_vectors,
108110
contents=[
109111
Scene(name=k, contents=v, origin=origin) for k, v in primitives.items()
110112
],

0 commit comments

Comments
 (0)