Skip to content
Snippets Groups Projects
Commit dc3ecc75 authored by Georg Huhs's avatar Georg Huhs
Browse files

added encyclopedia tutorial - BKR MISSINGgit statusgit status!

parent 16d70ec2
Branches
Tags
No related merge requests found
function apiReq(materialId, dataType, authToken, callback){
let oReq = new XMLHttpRequest();
oReq.addEventListener("load", callback);
oReq.open("GET", "https://encyclopedia-api.nomad-coe.eu/v1.0/materials/"+materialId+"/"+dataType);
oReq.setRequestHeader('Authorization', 'Basic '+btoa(authToken));
oReq.send();
return oReq;
}
function getMaterialStructureDataFromAPI(materialId, authToken, callback){
apiReq(materialId, 'elements', authToken, e => {
let elements = JSON.parse(e.target.response).results;
apiReq(materialId, 'cells', authToken, e1 => {
let cells = JSON.parse(e1.target.response).results;
let cell;
if (!cells[0].is_primitive) cell= cells[0];
else cell= cells[1];
callback(getCellDataForViewer(elements, cell));
});
});
}
function getNumberArray(string){
let sArray= string.substring(1,string.length-1).split(',');
let fArray= [];
for (let i = 0; i < sArray.length; i++) {
fArray.push(parseFloat(sArray[i]));
}
return fArray;
}
function getCellDataForViewer(elements, cell){
let cellData= {};
cellData.normalizedCell= [
getNumberArray(cell.a),
getNumberArray(cell.b),
getNumberArray(cell.c)
];
cellData.labels= [];
cellData.positions= [];
for (let i = 0; i < elements.length; i++) {
cellData.labels.push(elements[i].label);
cellData.positions.push(getNumberArray(elements[i].position));
}
//cellData.periodicity = JSON.parse(matData.periodicity);
return cellData;
}
File added
{
"id": "5a1bf3b780996e0031366357",
"type": "demos",
"attributes": {
"title": "Encyclopedia API and code usage",
"logicalPath": "/data/shared/ghuhs/encyclopedia.bkr",
"authors": ["Himanen, Lauri", "Huhs, Georg", "Hurtado, Iker", "Kuban, Martin", "Vancea, Ioan", "Draxl, Claudia"],
"editLink": "/notebook-edit/data/shared/tutorialsNew/encyclopedia/encyclopedia.bkr",
"isPublic": true,
"username": "tutorialsNew",
"description": "This tutorial deals mainly with accessing the NOMAD Encyclopedia API (searching for materials, extracting data for specific materials and calculations). It also shows how code developed for the Encyclopedia GUI can be embedded into client applications. ",
"created_at": "2018-09-22T11:15:03.028Z",
"updated_at": "2018-09-22T11:15:03.028Z",
"user_update": "2018-09-22",
"top_of_list": true,
"featured": true,
"labels" : {
"category" : ["Demo"],
"platform" : ["beaker"],
"language" : ["python", "javascript"],
"application_section" : ["Encyclopedia"]
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment