Skip to content

Commit

Permalink
Merge pull request #14 from Exabyte-io/feat/SOF-6970-1
Browse files Browse the repository at this point in the history
Feat/sof 6970 1
  • Loading branch information
timurbazhirov authored Sep 12, 2023
2 parents d23a7fe + f757bd4 commit 90ffae8
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/classmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BandGapsProperty } from "./include/non-scalar/band_gaps";
import { BandStructureProperty } from "./include/non-scalar/band_structure";
import { ChargeDensityProfileProperty } from "./include/non-scalar/charge_density_profile";
import { DensityOfStatesProperty } from "./include/non-scalar/density_of_states";
import { DielectricTensorProperty } from "./include/non-scalar/dielectric_tensor";
import { PhononDispersionsProperty } from "./include/non-scalar/phonon_dispersions";
import { PhononDOSProperty } from "./include/non-scalar/phonon_dos";
import { PotentialProfileProperty } from "./include/non-scalar/potential_profile";
Expand Down Expand Up @@ -54,6 +55,7 @@ export const PROPERTY_CLASS_MAP = {
[PROPERTIES.valence_band_offset]: null,
[PROPERTIES.pseudopotential]: Pseudopotential,
[PROPERTIES.boundary_conditions]: null,
[PROPERTIES.dielectric_tensor]: DielectricTensorProperty,
};

export const PROPERTY_BRANCH_MAP = {
Expand Down
166 changes: 166 additions & 0 deletions src/include/non-scalar/dielectric_tensor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/* eslint-disable class-methods-use-this */
/* eslint-disable max-classes-per-file */
import zip from "lodash/zip";

import { Property } from "../../property";
import { TwoDimensionalHighChartConfigMixin } from "../mixins/2d_plot";

export class DielectricTensorProperty extends Property {
/**
* @returns {{part: string, spin: number, frequencies: number[], components: number[][]}[]}
*/
get values() {
return this.prop("values");
}

get subtitle() {
return "Dielectric Tensor";
}

get yAxisTitle() {
return "Dielectric Tensor Component";
}

get xAxisTitle() {
return "Frequency (eV)";
}

get legend() {
return this.prop("legend");
}

get chartConfig() {
return this.getAllChartConfigs().map((chartConfig) => {
// eslint-disable-next-line no-use-before-define
const cfg = new DielectricTensorConfig(chartConfig);
return cfg.config;
});
}

/**
*
* @param {[number, number, number][]} matrix
*/
rowMajorToColumnMajor(matrix) {
return matrix.reduce(
(accumulator, item) => {
const [x, y, z] = item;
accumulator[0].push(x);
accumulator[1].push(y);
accumulator[2].push(z);
return accumulator;
},
[[], [], []],
);
}

/**
* @returns {{part: "real" | "imaginary", spin: number, frequencies: number[], components: number[][]}[][]}
*/
getComplementaryPairs(precision = 3) {
const groupedBySpin = {};

this.values.forEach((item) => {
// Round the spin value to mitigate floating-point precision issues
const spinValue = item.spin !== undefined ? item.spin.toFixed(precision) : "undefined";
groupedBySpin[spinValue] = groupedBySpin[spinValue] || [];
groupedBySpin[spinValue].push(item);
});

return Object.values(groupedBySpin).filter(
(group) =>
group.length === 2 &&
group.find((item) => item.part === "real") &&
group.find((item) => item.part === "imaginary"),
);
}

getAllChartConfigs() {
const complementaryPairs = this.getComplementaryPairs();

return complementaryPairs.flatMap((pair) => {
const xDataArray = pair[0].frequencies;
const components_first = this.rowMajorToColumnMajor(pair[0].components);
const components_second = this.rowMajorToColumnMajor(pair[1].components);
return components_first.map((epsilon, index) => {
return {
subtitle: `${this.subtitle} - ${"xyz"[index]}`,
xAxisTitle: this.xAxisTitle,
yAxisTitle: this.yAxisTitle,
yAxisType: "linear",
xDataArray,
yDataSeries: [epsilon, components_second[index]],
legend: pair.map((p) => p.part),
};
});
});
}
}

export class DielectricTensorConfig extends TwoDimensionalHighChartConfigMixin {
constructor(config) {
super(config);
this.legend = config.legend;
}

/**
* @returns {{animation: boolean, name: string, data: number[][]}[]}
*/
get series() {
return this.yDataSeries.map((item, index) => {
return {
animation: false,
name: this.legend[index],
data: zip(this.xDataArray, item),
};
});
}

// eslint-disable-next-line no-unused-vars
tooltipFormatter(xDataArray, yAxisName = "frequency") {
// eslint-disable-next-line func-names
return function () {
return (
"<b>part:</b> " +
this.series.name +
"<br>" +
"<b>frequency:</b> " +
this.key.toFixed(4) +
"<br>" +
"<b>epsilon: </b> " +
this.y.toFixed(4)
);
};
}

get overrideConfig() {
return {
...super.overrideConfig,
// colors: [
// "#7cb5ec",
// "#90ed7d",
// "#f7a35c",
// "#8085e9",
// "#f15c80",
// "#e4d354",
// "#2b908f",
// "#f45b5b",
// "#91e8e1",
// ],
credits: {
enabled: false,
},
chart: {
type: "spline",
zoomType: "xy",
animation: false,
},
legend: {
layout: "horizontal",
align: "center",
verticalAlign: "bottom",
borderWidth: 0,
},
};
}
}
1 change: 1 addition & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ export const PROPERTIES = {
valence_band_offset: "valence_band_offset",
pseudopotential: "pseudopotential",
boundary_conditions: "boundary_conditions",
dielectric_tensor: "dielectric_tensor",
};
3 changes: 3 additions & 0 deletions src/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,7 @@ export default {
[PROPERTIES.boundary_conditions]: {
type: PROPERTY_TYPES.non_scalar,
},
[PROPERTIES.dielectric_tensor]: {
type: PROPERTY_TYPES.non_scalar,
},
};

0 comments on commit 90ffae8

Please sign in to comment.