def row2str(row) -> str: t = row2dct(row) S = [t['formula'] + ':', 'Unit cell in Ang:', 'axis|periodic| x| y| z|' + ' length| angle'] c = 1 fmt = (' {0}| {1}|{2[0]:>11}|{2[1]:>11}|{2[2]:>11}|' + '{3:>10}|{4:>10}') for p, axis, L, A in zip(row.pbc, t['cell'], t['lengths'], t['angles']): S.append(fmt.format(c, [' no', 'yes'][p], axis, L, A)) c += 1 S.append('') if 'stress' in t: S += ['Stress tensor (xx, yy, zz, zy, zx, yx) in eV/Ang^3:', ' {}\n'.format(t['stress'])] if 'dipole' in t: S.append('Dipole moment in e*Ang: ({})\n'.format(t['dipole'])) if 'constraints' in t: S.append('Constraints: {}\n'.format(t['constraints'])) if 'data' in t: S.append('Data: {}\n'.format(t['data'])) width0 = max(max(len(row[0]) for row in t['table']), 3) width1 = max(max(len(row[1]) for row in t['table']), 11) S.append('{:{}} | {:{}} | Value' .format('Key', width0, 'Description', width1)) for key, desc, value in t['table']: S.append('{:{}} | {:{}} | {}' .format(key, width0, desc, width1, value)) return '\n'.join(S)
def row_to_dict(row: AtomsRow, project: Dict[str, Any]) -> Dict[str, Any]: """Convert row to dict for use in html template.""" dct = row2dct(row, project['key_descriptions']) dct['formula'] = Formula(Formula(row.formula).format('abc')).format('html') return dct