pymatgen.util.string module¶
This module provides utility classes for string operations.
-
class
StringColorizer(stream)[source]¶ Bases:
object-
colours= {'default': '', 'blue': '\x1b[01;34m', 'cyan': '\x1b[01;36m', 'green': '\x1b[01;32m', 'red': '\x1b[01;31m'}¶
-
-
formula_double_format(afloat, ignore_ones=True, tol=1e-08)[source]¶ This function is used to make pretty formulas by formatting the amounts. Instead of Li1.0 Fe1.0 P1.0 O4.0, you get LiFePO4.
Parameters: - afloat (float) – a float
- ignore_ones (bool) – if true, floats of 1 are ignored.
- tol (float) – Tolerance to round to nearest int. i.e. 2.0000000001 -> 2
Returns: A string representation of the float for formulas.
-
latexify(formula)[source]¶ Generates a latex formatted formula. E.g., Fe2O3 is transformed to Fe$_{2}$O$_{3}$.
Parameters: formula (str) – Input formula. Returns: Formula suitable for display as in LaTeX with proper subscripts.
-
latexify_spacegroup(spacegroup_symbol)[source]¶ Generates a latex formatted spacegroup. E.g., P2_1/c is converted to P2$_{1}$/c and P-1 is converted to P$overline{1}$.
Parameters: spacegroup_symbol (str) – A spacegroup symbol Returns: A latex formatted spacegroup with proper subscripts and overlines.
-
str_delimited(results, header=None, delimiter='\t')[source]¶ Given a tuple of tuples, generate a delimited string form. >>> results = [[“a”,”b”,”c”],[“d”,”e”,”f”],[1,2,3]] >>> print(str_delimited(results,delimiter=”,”)) a,b,c d,e,f 1,2,3
Parameters: - result – 2d sequence of arbitrary types.
- header – optional header
Returns: Aligned string output in a table-like format.
-
transformation_to_string(matrix, translation_vec=(0, 0, 0), components=('x', 'y', 'z'), c='', delim=', ')[source]¶ Convenience method. Given matrix returns string, e.g. x+2y+1/4 :param matrix :param translation_vec :param components: either (‘x’, ‘y’, ‘z’) or (‘a’, ‘b’, ‘c’) :param c: optional additional character to print (used for magmoms) :param delim: delimiter :return: xyz string