Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from ase import Atoms
2from ase.io.jsonio import encode, decode
5class AtomsClipboard:
6 def __init__(self, tk):
7 self.tk = tk
9 def get_text(self) -> str:
10 return self.tk.clipboard_get()
12 def set_text(self, text: str) -> None:
13 self.tk.clipboard_clear()
14 self.tk.clipboard_append(text)
16 def get_atoms(self) -> Atoms:
17 text = self.get_text()
18 atoms = decode(text)
19 if not isinstance(atoms, Atoms):
20 typename = type(atoms).__name__
21 raise ValueError(f'Cannot convert {typename} to Atoms')
22 return atoms
24 def set_atoms(self, atoms: Atoms) -> None:
25 json_text = encode(atoms)
26 self.set_text(json_text)