calypso.formula module
- class calypso.formula.Formula(formula)
Bases:
UserDict
,MSONable
Formula object
A dict with blocks and its amounts eg. {“Cl”:1, “Na”:1}
Examples
>>> formula = Formula({"Cl":1, "Na":1}) >>> formula.format() NaCl >>> formula = Formula([1, 2, 3, 4, 5]) >>> formula.format() HHeLiBeB >>> formula = Formula("H3O") >>> formula H3O >>> formula.count {'H': 3, 'O': 1}
- __str__()
Return unstacked formula with no brasket.
- count()
Return number of each atoms as dict.
- format(mode='')
- get_anonymous_formula(reduce=False)
- get_reduced_formula()
- property anonymous_formula
- class calypso.formula.FormulaFmt(*values)
Bases:
StrEnum
_summary_
# TODO: finish the docstring
- Parameters:
StrEnum (_type_) – _description_
- ALPHABET = 'alphabet'
- HILL = 'hill'
- METAL = 'metal'
- PERIODIC = 'periodic'
- class calypso.formula.FormulaUnit(formulaunit: str | list[str])
Bases:
object
FormulaUnit for reading from config
Examples
assume file
a.xyz
.. code-block:2 comment C 0 0 0 H 1 1 1
>>> formulaunit = FormulaUnit("B1-2{{file:a.xyz}}2-3") >>> formulaunit.get_structure_template() StructureTemplate( element_numbers=[5, 5, 6, 1], coords_template=[None, None, array([[0., 0., 0.], [1., 1., 1.]])] )
- static sample_range(formulaunit)
find each range and sample from it, return a dict with unit and value and a str.
`python > formula_str = sample_range("Mg2Al") > formula_str Mg2Al > sample_range("(Mg)23(Al)3") (Mg)23(Al)3 > sample_range("Mg3Al2") Mg3Al2 > sample_range("Mg3Al0-3") Mg3Al1 > sample_range("Mg3Al0-3") Mg3Al0 > sample_range("Mg3Al0-3") Mg3Al2 > sample_range("Mg3Al2-1") ValueError > sample_range("Mg0-0Al") ValueError > sample_range("(Mg)1(Al)0-1") (Mg)1(Al)0 > sample_range("A43B(2-5)") 'A43B(4)' > d = ["A43B(2-5)(C4(2-3)D45)1-2", "Ab43B(2-5)"] > sample_range(d) ['A43B(2)(C4(3)D45)1', 'Ab43B(2)'] `
- find_file_map() dict[str, tuple[str, CalyData]]
Find the mapping from file label to pseudo element and structure
See also
_find_file_map()
- get_pseudo_formula() Formula | list[Formula]
Substitute the ambiguous marker into pseudo element
- Returns:
pseudo_formula – Instance or list of instance of
Formula
with pseudo elements.- Return type:
See also
_get_pseudo_formula()
- get_structure_template() StructureTemplate
Sample a structure template
- Returns:
structuretemplate – Instance of
StructureTemplate
.- Return type:
StructureTemplate