pymatgen.util.string module¶
This module provides utility classes for string operations.
-
class
StringColorizer
(stream)[source]¶ Bases:
object
Provides coloring for strings in terminals.
- Parameters
stream – Input stream
-
disordered_formula
(disordered_struct, symbols='x', 'y', 'z', fmt='plain')[source]¶ Returns a formula of a form like AxB1-x (x=0.5) for disordered structures. Will only return a formula for disordered structures with one kind of disordered site at present.
- Parameters
disordered_struct – a disordered structure
symbols – a tuple of characters to use for
by default this is (subscripts,) –
if you have more than three disordered (but) –
more symbols will need to be added (species) –
fmt (str) – ‘plain’, ‘HTML’ or ‘LaTeX’
Returns (str): a disordered formula string
-
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.
-
htmlify
(formula)[source]¶ Generates a HTML formatted formula, e.g. Fe2O3 is transformed to Fe<sub>2</sub>O</sub>3</sub>
- Parameters
formula –
- Returns
-
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
-
unicodeify
(formula)[source]¶ Generates a formula with unicode subscripts, e.g. Fe2O3 is transformed to Fe₂O₃. Does not support formulae with decimal points.
- Parameters
formula –
- Returns
-
unicodeify_spacegroup
(spacegroup_symbol)[source]¶ Generates a unicode formatted spacegroup. E.g., P2$_{1}$/c is converted to P2₁/c and P$\overline{1}$ is converted to P̅1.
- Parameters
spacegroup_symbol (str) – A spacegroup symbol as LaTeX
- Returns
A unicode spacegroup with proper subscripts and overlines.