Commit f18bf933 authored by Iker Hurtado's avatar Iker Hurtado
Browse files

Open source code release (step 7)

parent 4da5a611
Pipeline #31063 passed with stages
in 6 seconds
/**
* Copyright 2016-2018 Iker Hurtado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
This is the base class that models a highly interactive plotter.
It is inherited by several classes implementing specifc plotters.
This plotter implements zoom and y-axis offset
*/
"use strict";
......@@ -6,8 +31,6 @@ let svg = require('./SVG.js');
const xmlns="http://www.w3.org/2000/svg";
const xlink="http://www.w3.org/1999/xlink";
//const OVERLAP_CORRECTOR = 32;
class InteractivePlotterBase{
......@@ -28,7 +51,6 @@ class InteractivePlotterBase{
this.nodataLabel = null;
this.outOfRangeColorActivated = true;
}
......@@ -87,7 +109,6 @@ class InteractivePlotterBase{
this.yLabelGapInit = yLabelGap;
this.xRel= this.plotRangeX/(this.xMax-this.xMin);
this.yRel= this.plotRangeY/(this.yMaxInit-this.yMinInit);
//console.log('setAxisRangeAndLabels MIN MAX ', this.yMin, this.yMax);
this._resetAxisGroup();
......@@ -105,13 +126,6 @@ class InteractivePlotterBase{
if (xLabel !== null)
svg.addText(this.axisGroup, this.plotRangeX/2, this.margins.bottom-12, this.xLabel, 'middle', 'axis-steps-big');
// draw x axis steps
/*
let xStep= this.plotRangeX/ xSteps;
for (let i = 0; i < xSteps; i++) {
svg.addLine(axisGroup, xStep*i, 0, xStep*i, -4, 1);
addText(axisGroup, xStep*i, -8, +((xStep*i/this.xRel)+this.xMin).toFixed(decimals), 'middle', 'steps');
}*/
// initialize y axis steps (dynamic construction) container
this._resetYAxisLabelGroup();
......@@ -159,6 +173,7 @@ class InteractivePlotterBase{
}
}
setYZoomAndOffset(yZoom, yOffset){
this.yZoom = yZoom;
this.yOffset = yOffset;
......@@ -210,21 +225,17 @@ class InteractivePlotterBase{
}
setRepaintListener(listener) {
this.repaintListener = listener;
}
transformY(y){
//let result = this.plotAreaHeight -(y*this.yZoom - this.yMinInit)*this.yRel - this.yOffset ;
// Precalculation usage
// this.plotAreaHeight -y*this.yZoom*this.yRel + this.yMinInit*this.yRel - this.yOffset
// -y*this.yZoom*this.yRel (calculated here) this.plotAreaHeight + this.yMinInit*this.yRel - this.yOffset
let result = -y*this.yZoom*this.yRel + this.precalculation_2;
if (result > 10000) throw 'Y coordinate too large';
if (result > 10000) throw 'Y coordinate too large';
return result;
}
......@@ -237,6 +248,7 @@ class InteractivePlotterBase{
this.plotArea.appendChild(this.plotContent);
}
_resetAxisGroup(){
if (this.axisGroup !== null)
this.svg.removeChild(this.axisGroup);
......@@ -259,6 +271,7 @@ class InteractivePlotterBase{
//this.yAxisLabelsGroup.setAttribute("transform", 'matrix(1 0 0 1 0 -'+OVERLAP_CORRECTOR+')');
}
_reset(){
this.yZoom = 1; // Initial zoom
this.yOffset = 0; // Initial y offset = 0
......@@ -293,16 +306,6 @@ class InteractivePlotterBase{
}
/*
_resetSVGGroup(parentE, groupElement){
if (groupElement !== null)
parentE.removeChild(groupElement);
groupElement = document.createElementNS(xmlns, 'g');
console.log('_resetSVGGroup',groupElement);
parentE.appendChild(groupElement);
}
*/
}
// EXPORTS
......
/**
* Copyright 2016-2018 Iker Hurtado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
This is the base class that models a regular plotter.
It is inherited by several classes implementing specifc plotters
*/
"use strict";
......@@ -48,33 +71,26 @@ class PlotterBase{
this.xRel= this.plotRangeX/(this.xMax-this.xMin);
this.yRel= this.plotRangeY/(this.yMax-this.yMin);
//console.log('setRangeAndLabels', this.xMin, this.xMax, this.yMin, this.yMax, this.xRel, this.yRel);
}
/*
addText(x, y, text, textAnchor = 'start', className){
let e= svg.addText(this.plotArea, x, y, text, textAnchor, className);
let yOffset= 2*(y - (e.getBoundingClientRect().height/2)+3);//console.log(rect);
e.setAttribute("transform", 'matrix(1 0 0 -1 0 '+yOffset+')');
return e;
}
*/
drawAxis(xSteps = 0, ySteps = 0, decimals = 2){
this.plotArea.setAttribute("transform", 'matrix(1 0 0 1 '+
this.margins.left+' '+(this.height - this.margins.bottom)+')');
//this.addText(-3, this.plotRangeY-3, this.yLabel, 'end', 'statisticsviewer');
this.yLabelText = svg.addText(this.svg, 0, 0, this.yLabel, 'middle', 'axis-steps-big');
this.yLabelText.setAttribute('transform','translate(13,'+(this.plotRangeY/2+this.margins.top)+') rotate(-90)');
svg.addText(this.plotArea, this.plotRangeX/2, this.margins.bottom-1, this.xLabel, 'middle', 'axis-steps-big');
this.yLabelText.setAttribute('transform','translate(13,'
+(this.plotRangeY/2+this.margins.top)+') rotate(-90)');
svg.addText(this.plotArea, this.plotRangeX/2, this.margins.bottom-1,
this.xLabel, 'middle', 'axis-steps-big');
if (xSteps !== null){
let xStep= this.plotRangeX/ xSteps;
for (let i = 0; i <= xSteps; i++) {
svg.addLine(this.plotArea, xStep*i, 0, xStep*i, 4, 1);
svg.addText(this.plotArea, xStep*i, 14, +((xStep*i/this.xRel)+this.xMin).toFixed(decimals), 'middle', 'statisticsviewersteps');
svg.addText(this.plotArea, xStep*i, 14,
+((xStep*i/this.xRel)+this.xMin).toFixed(decimals), 'middle', 'statisticsviewersteps');
}
}
......@@ -85,7 +101,7 @@ class PlotterBase{
let numberText = (Math.abs(this.yMax*i) >= 10000 ? (this.yMax*i).toExponential() : this.yMax*i );
svg.addText(this.plotArea,-5, this.transformY(this.yMax*i)+3, numberText,
'end', 'statisticsviewersteps');
i--; //console.log(i, this.yMax*i, this.yMin);
i--;
}
}
......@@ -142,12 +158,11 @@ class PlotterBase{
// Transform from y-axis units to y-axis pixels (svg-coordinates)
transformY(y){
return -this.yRel*(y - this.yMin);
}
}
// EXPORTS
module.exports = PlotterBase;
/**
* Copyright 2016-2018 Iker Hurtado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
Implements a graphical UI component composed of a DOS plotter and a
Band Structure plotter
*/
let BSPlotter = require('./BSPlotter.js');
let DOSPlotter = require('./DOSPlotter.js');
//let InteractivePlotterBase = require('../common/InteractivePlotterBase.js');
let svg = require('../common/SVG.js');
class BSDOSPlotter{
constructor() {
......@@ -81,6 +104,7 @@ class BSDOSPlotter{
this.dosPlotter.setYAxisLabelsVisibility(newDosYAxisLabeled);
}
setNoData(){
this.bsPlotter.setNoData();
this.dosPlotter.setNoData();
......
/**
* Copyright 2016-2018 Iker Hurtado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
Implements the Band Structure plotter.
It's used to show either the regular Band Structure data or
the Phonon Dispersion.
*/
"use strict";
......@@ -17,18 +40,17 @@ class BSPlotter extends InteractivePlotterBase{
this.factor = MULTIPLO1;
}
setPhononMode(){
this.phononMode = true;
this.factor = MULTIPLO2;
this.outOfRangeColorActivated = false;
}
// detach if necessary and attach
attach(element, width, height){
super.attach(element, width, height);
/*this.plotter.attach(element, width, height);
this._init();*/
}
......@@ -62,13 +84,11 @@ class BSPlotter extends InteractivePlotterBase{
}
setBandStructureData(data/*, cbmData, vbmData*/){
setBandStructureData(data){
let bandStructData;
if (data.segments !== undefined) bandStructData = data.segments;
else bandStructData = data;
//console.log('DATA',data);
this.bandGapData = undefined;
if (data.band_gap !== undefined && data.band_gap.position !== undefined){
......@@ -76,7 +96,6 @@ class BSPlotter extends InteractivePlotterBase{
this.bandGapData.cbmDistances = [];
this.bandGapData.vbmDistances = [];
}
//else console.log('BS without BAND GAP data');
// Gather all the points per band (divided by spin) crossing the segments
this.bandsDataSpin1= []; // [segment][band][kpoint]
......@@ -89,9 +108,12 @@ class BSPlotter extends InteractivePlotterBase{
let maxEnergyVal = topAndLowestPoints[1];
if (this.phononMode){
this.setAxisRangeAndLabels('',0,1,'Frequency (cm⁻¹)',-50, 320, minEnergyVal, maxEnergyVal, 100);
this.setAxisRangeAndLabels('',0,1,'Frequency (cm⁻¹)',-50, 320,
minEnergyVal, maxEnergyVal, 100);
}else
this.setAxisRangeAndLabels('',0,1,'Energy (eV)' ,-6 ,11 , minEnergyVal, maxEnergyVal, 5 );
this.setAxisRangeAndLabels('',0,1,'Energy (eV)' ,-6 ,11 , minEnergyVal,
maxEnergyVal, 5 );
// Calculates de distance
let totalDistance= 0;
for (let k = 0; k < bandStructData.length; k++) {
......@@ -114,12 +136,10 @@ class BSPlotter extends InteractivePlotterBase{
this.bandsDataSpin2.push([]);
let segmentDistance= kPointDistance(kPoints,kPoints.length-1);
//console.log("currentDistance: "+currentDistance/totalDistance);
// keeping the segment limits (x coordenate) for after painting
this.segmentLimitsX.push(currentDistance/totalDistance);
if (labels !== null){
// Set k-points labels
if (prevLastLabel !== null && prevLastLabel !== labels[0])
......@@ -137,7 +157,6 @@ class BSPlotter extends InteractivePlotterBase{
for (let i = 0; i < kPoints.length; i++) { // For every k-point
let tempDistance= (currentDistance + kPointDistance(kPoints, i))/totalDistance;
//console.log("kpoint: ", kPoints[i], tempDistance);
if (this.bandGapData !== undefined){
......@@ -145,10 +164,6 @@ class BSPlotter extends InteractivePlotterBase{
let kpt = this.bandGapData.lower.kpt;
if (kPoints[i][0] === kpt[0] && kPoints[i][1] === kpt[1]
&& kPoints[i][2] === kpt[2]){
//console.log("loWER: ", kPoints[i], kpt, tempDistance);
/*
if (this.bandGapData.cbmDistance === undefined)
this.bandGapData.cbmDistance = tempDistance;*/
this.bandGapData.cbmDistances.push(tempDistance);
}
}
......@@ -157,10 +172,6 @@ class BSPlotter extends InteractivePlotterBase{
let kpt = this.bandGapData.upper.kpt;
if (kPoints[i][0] === kpt[0] && kPoints[i][1] === kpt[1]
&& kPoints[i][2] === kpt[2]){
//console.log("upper: ", kPoints[i], kpt, tempDistance);
/*
if (this.bandGapData.vbmDistance === undefined)
this.bandGapData.vbmDistance = tempDistance; */
this.bandGapData.vbmDistances.push(tempDistance);
}
}
......@@ -201,7 +212,6 @@ class BSPlotter extends InteractivePlotterBase{
}
currentDistance+= segmentDistance;
//prevLastLabel = labels[1];
}
if (dataOverflow) throw 'Plotter Data Overflow: Probably the energy data is not in correct units'; //console.log('BSPlotter data overflow');
......@@ -209,7 +219,6 @@ class BSPlotter extends InteractivePlotterBase{
}
repaintData(yMin, yMax){
this.segmentLimitsX.forEach(x => {
......@@ -220,10 +229,8 @@ class BSPlotter extends InteractivePlotterBase{
x*this.xRel, yMaxPx, 'segment');
});
// Drawing lines
// Drawing lines
let polylinePoints;
//console.log("repaint: lines number: ", this.bandsData.length);
for (var i = 0; i < this.bandsDataSpin1.length; i++) // loop the segments
for (var j = 0; j < this.bandsDataSpin1[i].length; j++) { // loop the bands
......@@ -248,30 +255,6 @@ class BSPlotter extends InteractivePlotterBase{
}
}
/*
// Drawing points
for (var i = 0; i < this.bandsDataSpin1.length; i++) // loop the segments
for (var j = 0; j < this.bandsDataSpin1[i].length; j++) { // loop the bands
for (var k = 0; k < this.bandsDataSpin1[i][j].length; k++) { // loop the kpoints
svg.addPoint(this.plotContent,
this.xRel*this.bandsDataSpin1[i][j][k].x,
this.transformY(this.bandsDataSpin1[i][j][k].y),
1, 'plotSpin1');
}
}
if (this.bandsDataSpin2.length > 0){
for (var i = 0; i < this.bandsDataSpin2.length; i++) // loop the segments
for (var j = 0; j < this.bandsDataSpin2[i].length; j++) { // loop the kpoints
for (var k = 0; k < this.bandsDataSpin2[i][j].length; k++) { // loop the bands
svg.addPoint(this.plotContent,
this.xRel*this.bandsDataSpin2[i][j][k].x,
this.transformY(this.bandsDataSpin2[i][j][k].y),
1, 'plotSpin2');
}
}
}
*/
// Paint CBM and VBM
// console.log("Paint CBM and VBM: ", this.vbm); this.vbm.y = -1.01577992001999e-20/this.factor;
......
/**
* Copyright 2016-2018 Iker Hurtado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
This class implements the bar to select calculations on a material
*/
class CalcSelectorBar{
constructor(className, width){
......@@ -39,6 +62,7 @@ class CalcSelectorBar{
this._events();
}
_events() {
this.prevBtn.addEventListener( "click", e => {
e.preventDefault();
......@@ -69,21 +93,26 @@ class CalcSelectorBar{
'calc-selector-icon'+(this.last ? '-disabled' : ''));
}
setPrevListener(listener){
this.prevListener = listener;
}
setNextListener(listener){
this.nextListener = listener;
}
setState(text, first, last){
this.calcSelectorTxt.innerHTML = text;
this.first = first;
this.last = last;
this._styleButtons();
}
}
// EXPORTS
module.exports = CalcSelectorBar;
/**
* Copyright 2016-2018 Iker Hurtado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
Implements the DOS plotter.
*/
"use strict";
let InteractivePlotterBase = require('../common/InteractivePlotterBase.js');
let svg = require('../common/SVG.js');
let util = require('../common/util.js');
const E_MIN = -6;
const E_MAX = 11;
const E_FACTOR = 1.602176565e-19;
//const DOSVALUE_FACTOR = 1.602176565e-49;
class DOSPlotter extends InteractivePlotterBase{
//constructor(margins = {left: 40/*not working*/, right: 0, top: 0, bottom: 30}) {
constructor(margins) {
super(margins);
}
// detach if necessary and attach
......@@ -53,10 +75,8 @@ class DOSPlotter extends InteractivePlotterBase{
}
let maxDosVal = Math.max.apply(null, pointsXInPlotRange);
//console.log('pointsXInPlotRange : ',maxDosVal, pointsXInPlotRange);
let maxEnergyVal = Math.max.apply(null, pointsYInPlotRange);
let minEnergyVal = Math.min.apply(null, pointsYInPlotRange);
//console.log('formattedPoints paintPointsLine : ', this.formattedPoints.length);
// x axis steps generation
let t = util.generateDiagramSteps(maxDosVal);
......@@ -81,14 +101,12 @@ class DOSPlotter extends InteractivePlotterBase{
}
repaintData(){
let polylinePoints = '';
for (var i = 0; i < this.pointsSpin1.length; i++) {
polylinePoints+= ' '+this.xRel*this.pointsSpin1[i].x+
' '+this.transformY(this.pointsSpin1[i].y);
//console.log('POINTS LAT : ',this.formattedPoints[i].x, this.formattedPoints[i].y);
}
svg.addPolyline(this.plotContent, polylinePoints, 'plotSpin1');
......@@ -96,11 +114,11 @@ class DOSPlotter extends InteractivePlotterBase{
for (var i = 0; i < this.pointsSpin2.length; i++) {
polylinePoints+= ' '+this.xRel*this.pointsSpin2[i].x+
' '+this.transformY(this.pointsSpin2[i].y);
//console.log('POINTS LAT : ',this.formattedPoints[i].x, this.formattedPoints[i].y);
}
svg.addPolyline(this.plotContent, polylinePoints, 'plotSpin2');
}
setYAxisLabelsVisibility(value){
if (this.yAxisLabelsGroup !== null)
this.yAxisLabelsGroup.style.visibility = (value ? 'visible' : 'hidden');
......
/**
* Copyright 2016-2018 Iker Hurtado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
This file create and holds the application data models.
It stores the data loaded from the backend (immutable).
In addition it creates app life-time entities for convenience
*/
let materialData;
function setMaterialData(dataFromAPI){
materialData = dataFromAPI;
}
......@@ -30,7 +55,6 @@ function getCalc(calcId){
let groups;
function processCalcGroups(groupsFromAPI){