Skip to content

Commit 8847116

Browse files
committed
Add real data to line chart
1 parent 1b9b87d commit 8847116

1 file changed

Lines changed: 67 additions & 17 deletions

File tree

  • src/workflows/nwchem/nwchem-neb/components/steps/Visualization/View

src/workflows/nwchem/nwchem-neb/components/steps/Visualization/View/index.js

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,90 @@
1-
import React from 'react';
1+
import React from 'react';
22
import candela from 'candela';
3+
import client from '../../../../../../../network';
4+
5+
const auToEv = 27.2116;
6+
const evToKcal = 23.06;
7+
const auToKcal = auToEv * evToKcal;
8+
const x = 'Reaction Coordinate';
9+
const y = 'Energy (kcal/mol)';
310

411
const VisualizationView = React.createClass({
512

613
displayName: 'nwchem_neb/steps/Visualization',
714

15+
propTypes: {
16+
simulation: React.PropTypes.object,
17+
},
18+
819
getInitialState() {
9-
var data = [];
10-
for (var d = 0; d < 10; d += 1) {
11-
data.push({
12-
a: d,
13-
b: d
20+
return { energies: [] };
21+
},
22+
23+
componentDidMount() {
24+
// Look up and fetch neb.neb_final_epath
25+
client.listItems({
26+
folderId: this.props.simulation.metadata.outputFolder._id,
27+
name: 'neb.neb_final_epath',
28+
})
29+
.then((resp) => client.listFiles(resp.data[0]._id))
30+
// Finally download the file
31+
.then((resp) => client.downloadFile(resp.data[0]._id))
32+
.then((resp) => {
33+
this.setState({
34+
energies: this._extractEnergies(resp.data),
1435
});
36+
this._createLineChart();
37+
}).catch((error) => {
38+
console.error('Unable to neb.neb_final_epath.');
39+
throw error;
40+
});
41+
},
42+
43+
componentWillUpdate(nextProps, nextState) {
44+
if (this.chart) {
45+
this.chart.render();
1546
}
16-
return { data };
1747
},
1848

19-
componentDidMount() {
20-
this.chart = new candela.components.LineChart(this.refs.container, {
21-
data: this.state.data,
22-
x: 'a',
23-
y: ['b'],
24-
width: 700,
25-
height: 400
49+
_extractEnergies(energyData) {
50+
var energies = [];
51+
energyData.split('\n').forEach((line) => {
52+
const trimmedLine = line.trim();
53+
if (!trimmedLine.startsWith('#') && trimmedLine.length > 0) {
54+
const parts = trimmedLine.split(/\s+/);
55+
const point = {};
56+
point[x] = Number.parseFloat(parts[0].trim());
57+
point[y] = Number.parseFloat(parts[1].trim());
58+
energies.push(point);
59+
}
2660
});
2761

28-
this.chart.render();
62+
const minimumEnergy = Math.min(...energies.map((point) => Number.parseFloat(point[y])));
63+
64+
// Convert energies to kcal and make positive
65+
energies = energies.map(point => {
66+
point[y] = (point[y] + Math.abs(minimumEnergy)) * auToKcal;
67+
68+
return point;
69+
});
70+
71+
return energies;
2972
},
73+
_createLineChart() {
74+
this.chart = new candela.components.LineChart(this.refs.container, {
75+
data: this.state.energies,
76+
x,
77+
y: [y],
78+
width: 700,
79+
height: 400,
80+
});
3081

31-
componentWillUpdate(nextProps, nextState) {
3282
this.chart.render();
3383
},
3484

3585
render() {
3686
return (<div ref="container"></div>);
37-
}
87+
},
3888
});
3989

4090

0 commit comments

Comments
 (0)