Skip to content

Commit

Permalink
space group formatting: add overline for negative numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
eimrek committed Aug 16, 2024
1 parent ed35645 commit da3e796
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/utils/formatting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,48 @@ export function formatChemicalFormula(formula) {
return v;
});
}
const overlineStyle = {
display: "inline-block",
position: "relative",
};

const overlineAdjustmentStyle = {
position: "absolute",
top: "0.15em",
left: 0,
right: 0,
borderTop: "0.1em solid black",
height: 0,
zIndex: 1,
};

export function formatSpaceGroupSymbol(params) {
/*
* Note: there is no case where both subscript and overline need
* to be applied to the same number.
*/
let nextIsSub = false;
let nextIsNegative = false;
return (
<span>
{params.split("").map((v, index) => {
if (v == "-") {
nextIsNegative = true;
return null;
}
if (v == "_") {
nextIsSub = true;
return null;
}
if (nextIsNegative) {
nextIsNegative = false;
return (
<span style={overlineStyle} key={index}>
<span style={overlineAdjustmentStyle} />
{v}
</span>
);
}
if (nextIsSub) {
nextIsSub = false;
return <sub key={index}>{v}</sub>;
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/symmetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* - https://github.com/spglib/spglib/blob/v2.5.0/database/make_spgtype_db.py
* - https://github.com/materialsproject/pymatgen/blob/v2024.8.9/src/pymatgen/symmetry/analyzer.py
* - https://raw.githubusercontent.com/materialsproject/pymatgen/v2024.8.9/src/pymatgen/symmetry/symm_ops.json
* - https://aflow.org/prototype-encyclopedia/spacegroup_info.html
*/

// Import the international (Hermann-Mauguin) space and point group symbols
Expand All @@ -23,6 +24,8 @@ const PEARSON_CRYSTAL_FAMILIES = {
h: "hexagonal",
c: "cubic",
};
// Note that for "base-centered" other sources might use a different letter
// (e.g. 'C' instead of 'S')
const PEARSON_BRAVAIS_LATTICES = {
aP: "triclinic",
mP: "simple monoclinic",
Expand Down
1 change: 1 addition & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function App() {
<span>utils/formatting.jsx</span>
<div>{formatChemicalFormula("CO2")}</div>
<div>{formatSpaceGroupSymbol("P6_3/mcm")}</div>
<div>{formatSpaceGroupSymbol("P-42_1m")}</div>
<span>utils/symmetry.js</span>
<div>
<Table bordered striped>
Expand Down

0 comments on commit da3e796

Please sign in to comment.