Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace full output info in __str__ by chemical formula #439

Merged
merged 2 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pyiron_atomistics/atomistics/structure/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2031,9 +2031,6 @@ def __dir__(self):
# return len(self.indices)

def __repr__(self):
return self.__str__()

def __str__(self):
if len(self) == 0:
return "[]"
out_str = ""
Expand All @@ -2052,6 +2049,9 @@ def __str__(self):
out_str += str(self.cell) + "\n"
return out_str

def __str__(self):
return self.get_chemical_formula()

def __setitem__(self, key, value):
if isinstance(key, (int, np.integer)):
old_el = self.species[self.indices[key]]
Expand Down
8 changes: 8 additions & 0 deletions tests/atomistics/structure/test_atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,14 @@ def test_set_dihedral():
structure = ase_to_pyiron(molecule('H2COH'))
structure.set_dihedral(4, 0, 1, 2, angle=90)

def test_str_repr(self):
H2 = Atoms(positions=[3*[0], 3*[0.5]], cell=np.eye(3), elements=2*['H'], pbc=True)
self.assertEqual(
repr(H2),
'H: [0. 0. 0.]\nH: [0.5 0.5 0.5]\npbc: [ True True True]\ncell: \nCell([1.0, 1.0, 1.0])\n'
)
self.assertEqual(str(H2), 'H2')

def test_cached_speed(self):
"""
Creating atoms should be faster after the first time, due to caches in periodictable/mendeleev.
Expand Down