Fix PhonopyAtoms for yaml text output in case of mass undefined.

This commit is contained in:
Atsushi Togo 2017-03-07 14:26:24 +09:00
parent 8f2970bff7
commit 332f3f840e
2 changed files with 25 additions and 11 deletions

View File

@ -260,12 +260,17 @@ class PhonopyAtoms(Atoms):
lines.append("- [ %21.15f, %21.15f, %21.15f ] # %s" %
(v[0], v[1], v[2], a))
lines.append("points:")
if self.masses is None:
masses = [None] * len(self.symbols)
else:
masses = self.masses
for i, (s, v, m) in enumerate(
zip(self.symbols, self.scaled_positions, self.masses)):
zip(self.symbols, self.scaled_positions, masses)):
lines.append("- symbol: %-2s # %d" % (s, i + 1))
lines.append(" coordinates: [ %18.15f, %18.15f, %18.15f ]" %
tuple(v))
lines.append(" mass: %f" % m)
if m is not None:
lines.append(" mass: %f" % m)
return lines
def __str__(self):

View File

@ -15,22 +15,31 @@ class TestCell(unittest.TestCase):
[0.7, 0.7, 0.0],
[0.2, 0.8, 0.5],
[0.8, 0.2, 0.5]]
self._cell = Atoms(cell=lattice,
scaled_positions=points,
symbols=symbols)
self._cells = []
self._cells.append(Atoms(cell=lattice,
scaled_positions=points,
symbols=symbols))
# The element for which mass is not defined.
symbols = ['Ac'] * 2 + ['O'] * 4
self._cells.append(Atoms(cell=lattice,
scaled_positions=points,
symbols=symbols))
def tearDown(self):
pass
def test_atoms(self):
print(self._cell.get_cell())
for s, p in zip(self._cell.get_chemical_symbols(),
self._cell.get_scaled_positions()):
print("%s %s" % (s, p))
for cell in self._cells:
print(cell.get_cell())
for s, p in zip(cell.get_chemical_symbols(),
cell.get_scaled_positions()):
print("%s %s" % (s, p))
def test_phonopy_atoms(self):
print(PhonopyAtoms(atoms=self._cell))
for cell in self._cells:
print(PhonopyAtoms(atoms=cell))
if __name__ == '__main__':
unittest.main()