pymatgen.util.string module¶
This module provides utility classes for string operations.
-
class
Stringify
[source]¶ Bases:
object
Mix-in class for string formatting, e.g. superscripting numbers and symbols or superscripting.
-
to_html_string
() → str[source]¶ Generates a HTML formatted string. This uses the output from to_latex_string to generate a HTML output. :return: HTML formatted string.
-
to_latex_string
() → str[source]¶ Generates a LaTeX formatted string. The mode is set by the class variable STRING_MODE, which defaults to “SUBSCRIPT”. E.g., Fe2O3 is transformed to Fe$_{2}$O$_{3}$. Setting STRING_MODE to “SUPERSCRIPT” creates superscript, e.g., Fe2+ becomes Fe^{2+}. The initial string is obtained from the class’s __str__ method.
- Returns
String for display as in LaTeX with proper superscripts and subscripts.
-
-
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
subscripts ('x', 'y', 'z') –
default this is (by) –
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.
-
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