mc-react-structure-visualizer 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # React Materials Cloud Structure Visualizer
2
+
3
+ A React component to visualize structures on the Materials Cloud platform.
4
+
5
+ # Getting Started with Create React App
6
+
7
+ This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
8
+
9
+ ## Available Scripts
10
+
11
+ In the project directory, you can run:
12
+
13
+ ### `npm start`
14
+
15
+ Runs the app in the development mode.\
16
+ Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
17
+
18
+ The page will reload when you make changes.\
19
+ You may also see any lint errors in the console.
20
+
21
+ ### `npm test`
22
+
23
+ Launches the test runner in the interactive watch mode.\
24
+ See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
25
+
26
+ ### `npm run build`
27
+
28
+ Builds the app for production to the `build` folder.\
29
+ It correctly bundles React in production mode and optimizes the build for the best performance.
30
+
31
+ The build is minified and the filenames include the hashes.\
32
+ Your app is ready to be deployed!
33
+
34
+ See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
35
+
36
+ ### `npm run eject`
37
+
38
+ **Note: this is a one-way operation. Once you `eject`, you can't go back!**
39
+
40
+ If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
41
+
42
+ Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
43
+
44
+ You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
45
+
46
+ ## Learn More
47
+
48
+ You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
49
+
50
+ To learn React, check out the [React documentation](https://reactjs.org/).
51
+
52
+ ### Code Splitting
53
+
54
+ This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
55
+
56
+ ### Analyzing the Bundle Size
57
+
58
+ This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
59
+
60
+ ### Making a Progressive Web App
61
+
62
+ This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
63
+
64
+ ### Advanced Configuration
65
+
66
+ This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
67
+
68
+ ### Deployment
69
+
70
+ This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
71
+
72
+ ### `npm run build` fails to minify
73
+
74
+ This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
@@ -0,0 +1,5 @@
1
+ .gldiv {
2
+ width: 98%;
3
+ height: 98%;
4
+ position: relative;
5
+ }
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var $3Dmol = _interopRequireWildcard(require("3dmol"));
10
+ require("./Visualizer3dmol.css");
11
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
16
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
18
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
19
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
20
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
21
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
22
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
23
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
24
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
25
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
26
+ var Visualizer3dmol = /*#__PURE__*/function (_React$Component) {
27
+ _inherits(Visualizer3dmol, _React$Component);
28
+ var _super = _createSuper(Visualizer3dmol);
29
+ function Visualizer3dmol(props) {
30
+ var _this;
31
+ _classCallCheck(this, Visualizer3dmol);
32
+ _this = _super.call(this, props);
33
+ _this.viewer = null;
34
+ _this.model = null;
35
+
36
+ // Assign random id to prevent multiple 'gldiv' from clashing
37
+ _this.divId = "gldiv-" + (Math.random() + 1).toString(36).substring(7);
38
+ return _this;
39
+ }
40
+ _createClass(Visualizer3dmol, [{
41
+ key: "componentDidMount",
42
+ value: function componentDidMount() {
43
+ // set up the viewer instance
44
+ var config = {
45
+ backgroundColor: "mintcream",
46
+ orthographic: true
47
+ };
48
+ this.viewer = $3Dmol.createViewer(this.divId, config);
49
+ this.updateView();
50
+ }
51
+ }, {
52
+ key: "updateView",
53
+ value: function updateView() {
54
+ this.viewer.removeAllModels();
55
+ this.model = this.viewer.addModel(this.props.cifText, "cif");
56
+ var style = {
57
+ sphere: {
58
+ scale: 0.3,
59
+ colorscheme: "Jmol"
60
+ }
61
+ };
62
+ if (this.props.viewerParams.vdwRadius) {
63
+ style.sphere.scale = 1.0;
64
+ }
65
+ if (this.props.viewerParams.bonds) {
66
+ style.stick = {
67
+ radius: 0.2,
68
+ colorscheme: "Jmol"
69
+ };
70
+ }
71
+ this.viewer.setStyle(style);
72
+ this.viewer.addUnitCell(this.model);
73
+ var sc = this.props.viewerParams.supercell;
74
+ this.viewer.replicateUnitCell(sc[0], sc[1], sc[2], this.model);
75
+ this.model.assignBonds();
76
+
77
+ // console.log(this.viewer.getView());
78
+ // this.viewer.setView([0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.5, 0.5]);
79
+
80
+ this.viewer.zoomTo();
81
+ this.viewer.render();
82
+ }
83
+ }, {
84
+ key: "handleEvent",
85
+ value: function handleEvent(type, value) {
86
+ if (type == "camera") {
87
+ // console.log(this.viewer.getView());
88
+ if (value == "x") {
89
+ this.viewer.setView([0.0, 0.0, 0.0, 0.0, -0.5, -0.5, -0.5, 0.5]);
90
+ }
91
+ if (value == "y") {
92
+ this.viewer.setView([0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.5, 0.5]);
93
+ }
94
+ if (value == "z") {
95
+ this.viewer.setView([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]);
96
+ }
97
+ this.viewer.zoomTo();
98
+ }
99
+ }
100
+ }, {
101
+ key: "render",
102
+ value: function render() {
103
+ if (this.viewer && this.model) {
104
+ this.updateView();
105
+ }
106
+ return /*#__PURE__*/_react.default.createElement("div", {
107
+ id: this.divId,
108
+ className: "gldiv"
109
+ }, "No data!");
110
+ }
111
+ }]);
112
+ return Visualizer3dmol;
113
+ }(_react.default.Component);
114
+ var _default = Visualizer3dmol;
115
+ exports.default = _default;
@@ -0,0 +1,25 @@
1
+ .control-box {
2
+ position: relative;
3
+ z-index: 1;
4
+ height: 95px;
5
+ width: 448px;
6
+ background: rgb(223, 226, 255);
7
+ text-align: center;
8
+ border: 1px solid #999;
9
+ display: flex;
10
+ flex-direction: column;
11
+ justify-content: center;
12
+ align-items: start;
13
+ margin: 3px;
14
+ margin-top: -15px;
15
+ padding-top: 10px;
16
+ border-radius: 10px;
17
+ }
18
+
19
+ .control-box-row {
20
+ margin: 2px 5px;
21
+ }
22
+
23
+ .supercell-input {
24
+ width: 40px;
25
+ }
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ require("./index.css");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
11
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
13
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
14
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
15
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
16
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
17
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
18
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
19
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
20
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
21
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
22
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
23
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
24
+ var ControlBox = /*#__PURE__*/function (_React$Component) {
25
+ _inherits(ControlBox, _React$Component);
26
+ var _super = _createSuper(ControlBox);
27
+ function ControlBox(props) {
28
+ var _this;
29
+ _classCallCheck(this, ControlBox);
30
+ _this = _super.call(this, props);
31
+ _defineProperty(_assertThisInitialized(_this), "handleSupercellChange", function (index, value) {
32
+ var newSupercell = _this.props.viewerParams.supercell;
33
+ newSupercell[index] = parseInt(value);
34
+ _this.props.onViewerParamChange("supercell", newSupercell);
35
+ });
36
+ _defineProperty(_assertThisInitialized(_this), "handleOptionChange", function (option) {
37
+ _this.props.onViewerParamChange(option, !_this.props.viewerParams[option]);
38
+ });
39
+ _defineProperty(_assertThisInitialized(_this), "handleCameraEvent", function (orientation) {
40
+ _this.props.onViewerEvent("camera", orientation);
41
+ });
42
+ return _this;
43
+ }
44
+ _createClass(ControlBox, [{
45
+ key: "render",
46
+ value: function render() {
47
+ var _this2 = this;
48
+ return /*#__PURE__*/_react.default.createElement("div", {
49
+ className: "control-box"
50
+ }, /*#__PURE__*/_react.default.createElement("div", {
51
+ className: "control-box-row"
52
+ }, /*#__PURE__*/_react.default.createElement("label", null, "Supercell: "), [0, 1, 2].map(function (index) {
53
+ return /*#__PURE__*/_react.default.createElement("input", {
54
+ key: index,
55
+ className: "supercell-input",
56
+ type: "number",
57
+ value: _this2.props.viewerParams.supercell[index],
58
+ onChange: function onChange(e) {
59
+ return _this2.handleSupercellChange(index, e.target.value);
60
+ }
61
+ });
62
+ })), /*#__PURE__*/_react.default.createElement("div", {
63
+ className: "control-box-row"
64
+ }, /*#__PURE__*/_react.default.createElement("label", null, "Camera: "), /*#__PURE__*/_react.default.createElement("button", {
65
+ onClick: function onClick() {
66
+ return _this2.handleCameraEvent("x");
67
+ }
68
+ }, "x"), /*#__PURE__*/_react.default.createElement("button", {
69
+ onClick: function onClick() {
70
+ return _this2.handleCameraEvent("y");
71
+ }
72
+ }, "y"), /*#__PURE__*/_react.default.createElement("button", {
73
+ onClick: function onClick() {
74
+ return _this2.handleCameraEvent("z");
75
+ }
76
+ }, "z")), /*#__PURE__*/_react.default.createElement("div", {
77
+ className: "control-box-row"
78
+ }, /*#__PURE__*/_react.default.createElement("label", null, /*#__PURE__*/_react.default.createElement("input", {
79
+ type: "checkbox",
80
+ checked: this.props.viewerParams.bonds,
81
+ onChange: function onChange() {
82
+ return _this2.handleOptionChange("bonds");
83
+ }
84
+ }), "Bonds"), /*#__PURE__*/_react.default.createElement("label", null, /*#__PURE__*/_react.default.createElement("input", {
85
+ type: "checkbox",
86
+ checked: this.props.viewerParams.atomLabels,
87
+ onChange: function onChange() {
88
+ return _this2.handleOptionChange("atomLabels");
89
+ },
90
+ disabled: true
91
+ }), "Atom Labels"), /*#__PURE__*/_react.default.createElement("label", null, /*#__PURE__*/_react.default.createElement("input", {
92
+ type: "checkbox",
93
+ checked: this.props.viewerParams.packedCell,
94
+ onChange: function onChange() {
95
+ return _this2.handleOptionChange("packedCell");
96
+ },
97
+ disabled: true
98
+ }), "Packed Cell"), /*#__PURE__*/_react.default.createElement("label", null, /*#__PURE__*/_react.default.createElement("input", {
99
+ type: "checkbox",
100
+ checked: this.props.viewerParams.spaceFilling,
101
+ onChange: function onChange() {
102
+ return _this2.handleOptionChange("vdwRadius");
103
+ }
104
+ }), "vdW radius")));
105
+ }
106
+ }]);
107
+ return ControlBox;
108
+ }(_react.default.Component);
109
+ var _default = ControlBox;
110
+ exports.default = _default;
package/dist/index.css ADDED
@@ -0,0 +1,14 @@
1
+ .structure-window {
2
+ position: relative;
3
+ z-index: 2;
4
+ height: 350px;
5
+ width: 448px;
6
+ background: #f5fffa;
7
+ text-align: center;
8
+ border: 1px solid #999;
9
+ display: flex;
10
+ justify-content: center;
11
+ align-items: center;
12
+ margin: 3px;
13
+ border-radius: 10px;
14
+ }
package/dist/index.js ADDED
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _ControlBox = _interopRequireDefault(require("./ControlBox"));
10
+ var _Visualizer3dmol = _interopRequireDefault(require("./3dmol/Visualizer3dmol"));
11
+ require("./index.css");
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
14
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
18
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
19
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
20
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
21
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
22
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
23
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
24
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
25
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
26
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
27
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
28
+ var StructureVisualizer = /*#__PURE__*/function (_React$Component) {
29
+ _inherits(StructureVisualizer, _React$Component);
30
+ var _super = _createSuper(StructureVisualizer);
31
+ function StructureVisualizer(props) {
32
+ var _this;
33
+ _classCallCheck(this, StructureVisualizer);
34
+ _this = _super.call(this, props);
35
+ _this.state = {
36
+ viewerParams: {
37
+ supercell: [2, 2, 2],
38
+ orientation: "x",
39
+ bonds: true,
40
+ atomLabels: false,
41
+ packedCell: false,
42
+ vdwRadius: false
43
+ }
44
+ };
45
+
46
+ // use Ref to send events to the visualizer backend
47
+ _this.visualizerRef = /*#__PURE__*/_react.default.createRef();
48
+ _this.handleViewerParamChange = _this.handleViewerParamChange.bind(_assertThisInitialized(_this));
49
+ _this.handleViewerEvent = _this.handleViewerEvent.bind(_assertThisInitialized(_this));
50
+ return _this;
51
+ }
52
+ _createClass(StructureVisualizer, [{
53
+ key: "handleViewerParamChange",
54
+ value: function handleViewerParamChange(param, value) {
55
+ this.setState({
56
+ viewerParams: _objectSpread(_objectSpread({}, this.state.viewerParams), {}, _defineProperty({}, param, value))
57
+ });
58
+ }
59
+ }, {
60
+ key: "handleViewerEvent",
61
+ value: function handleViewerEvent(param, value) {
62
+ this.visualizerRef.current.handleEvent(param, value);
63
+ }
64
+ }, {
65
+ key: "render",
66
+ value: function render() {
67
+ // console.log("CIF", this.props.cifText);
68
+ return /*#__PURE__*/_react.default.createElement("div", {
69
+ className: "structure-visualizer"
70
+ }, /*#__PURE__*/_react.default.createElement("div", {
71
+ className: "structure-window"
72
+ }, /*#__PURE__*/_react.default.createElement(_Visualizer3dmol.default, {
73
+ ref: this.visualizerRef,
74
+ viewerParams: this.state.viewerParams,
75
+ cifText: this.props.cifText
76
+ })), /*#__PURE__*/_react.default.createElement(_ControlBox.default, {
77
+ viewerParams: this.state.viewerParams,
78
+ onViewerParamChange: this.handleViewerParamChange,
79
+ onViewerEvent: this.handleViewerEvent
80
+ }));
81
+ }
82
+ }]);
83
+ return StructureVisualizer;
84
+ }(_react.default.Component);
85
+ var _default = StructureVisualizer;
86
+ exports.default = _default;
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "mc-react-structure-visualizer",
3
+ "version": "0.2.0",
4
+ "author": "Kristjan Eimre <kristjan.eimre@epfl.ch>",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "babel": {
8
+ "presets": [
9
+ "@babel/preset-react",
10
+ "@babel/preset-env"
11
+ ]
12
+ },
13
+ "dependencies": {
14
+ "@testing-library/jest-dom": "^5.16.5",
15
+ "@testing-library/react": "^13.4.0",
16
+ "@testing-library/user-event": "^13.5.0",
17
+ "3dmol": "^2.0.1",
18
+ "react": "^18.2.0",
19
+ "react-dom": "^18.2.0",
20
+ "react-scripts": "5.0.1",
21
+ "web-vitals": "^2.1.4"
22
+ },
23
+ "scripts": {
24
+ "start": "react-scripts start",
25
+ "build": "SET NODE_ENV=production && rm -rf dist && npx babel src/StructureVisualizer --out-dir dist --copy-files",
26
+ "test": "react-scripts test",
27
+ "eject": "react-scripts eject"
28
+ },
29
+ "eslintConfig": {
30
+ "extends": [
31
+ "react-app",
32
+ "react-app/jest"
33
+ ]
34
+ },
35
+ "browserslist": {
36
+ "production": [
37
+ ">0.2%",
38
+ "not dead",
39
+ "not op_mini all"
40
+ ],
41
+ "development": [
42
+ "last 1 chrome version",
43
+ "last 1 firefox version",
44
+ "last 1 safari version"
45
+ ]
46
+ },
47
+ "devDependencies": {
48
+ "@babel/cli": "^7.20.7",
49
+ "@babel/core": "^7.20.12",
50
+ "@babel/preset-env": "^7.20.2",
51
+ "@babel/preset-react": "^7.18.6",
52
+ "babel-loader": "^9.1.2"
53
+ }
54
+ }
Binary file
@@ -0,0 +1,43 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <meta name="theme-color" content="#000000" />
8
+ <meta
9
+ name="description"
10
+ content="Web site created using create-react-app"
11
+ />
12
+ <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
13
+ <!--
14
+ manifest.json provides metadata used when your web app is installed on a
15
+ user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
16
+ -->
17
+ <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18
+ <!--
19
+ Notice the use of %PUBLIC_URL% in the tags above.
20
+ It will be replaced with the URL of the `public` folder during the build.
21
+ Only files inside the `public` folder can be referenced from the HTML.
22
+
23
+ Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
24
+ work correctly both with client-side routing and a non-root public URL.
25
+ Learn how to configure a non-root public URL by running `npm run build`.
26
+ -->
27
+ <title>React App</title>
28
+ </head>
29
+ <body>
30
+ <noscript>You need to enable JavaScript to run this app.</noscript>
31
+ <div id="root"></div>
32
+ <!--
33
+ This HTML file is a template.
34
+ If you open it directly in the browser, you will see an empty page.
35
+
36
+ You can add webfonts, meta tags, or analytics to this file.
37
+ The build step will place the bundled scripts into the <body> tag.
38
+
39
+ To begin the development, run `npm start` or `yarn start`.
40
+ To create a production bundle, use `npm run build` or `yarn build`.
41
+ -->
42
+ </body>
43
+ </html>
Binary file
Binary file
@@ -0,0 +1,25 @@
1
+ {
2
+ "short_name": "React App",
3
+ "name": "Create React App Sample",
4
+ "icons": [
5
+ {
6
+ "src": "favicon.ico",
7
+ "sizes": "64x64 32x32 24x24 16x16",
8
+ "type": "image/x-icon"
9
+ },
10
+ {
11
+ "src": "logo192.png",
12
+ "type": "image/png",
13
+ "sizes": "192x192"
14
+ },
15
+ {
16
+ "src": "logo512.png",
17
+ "type": "image/png",
18
+ "sizes": "512x512"
19
+ }
20
+ ],
21
+ "start_url": ".",
22
+ "display": "standalone",
23
+ "theme_color": "#000000",
24
+ "background_color": "#ffffff"
25
+ }
@@ -0,0 +1,3 @@
1
+ # https://www.robotstxt.org/robotstxt.html
2
+ User-agent: *
3
+ Disallow:
package/src/App.css ADDED
@@ -0,0 +1,38 @@
1
+ /* .App {
2
+ text-align: center;
3
+ }
4
+
5
+ .App-logo {
6
+ height: 40vmin;
7
+ pointer-events: none;
8
+ }
9
+
10
+ @media (prefers-reduced-motion: no-preference) {
11
+ .App-logo {
12
+ animation: App-logo-spin infinite 20s linear;
13
+ }
14
+ }
15
+
16
+ .App-header {
17
+ background-color: #282c34;
18
+ min-height: 100vh;
19
+ display: flex;
20
+ flex-direction: column;
21
+ align-items: center;
22
+ justify-content: center;
23
+ font-size: calc(10px + 2vmin);
24
+ color: white;
25
+ }
26
+
27
+ .App-link {
28
+ color: #61dafb;
29
+ }
30
+
31
+ @keyframes App-logo-spin {
32
+ from {
33
+ transform: rotate(0deg);
34
+ }
35
+ to {
36
+ transform: rotate(360deg);
37
+ }
38
+ } */
package/src/App.js ADDED
@@ -0,0 +1,38 @@
1
+ import React, { useState, useEffect } from "react";
2
+
3
+ import "./App.css";
4
+ import StructureVisualizer from "./StructureVisualizer";
5
+
6
+ async function fetchCif() {
7
+ // Fetch a cif file from the Materials Cloud AiiDA rest api
8
+ const aiidaRestEndpoint = "https://aiida.materialscloud.org/mc3d/api/v4";
9
+ const uuid = "85260507-9cb4-4849-a10d-703f32697dd7";
10
+
11
+ const responseAiiDACif = await fetch(
12
+ `${aiidaRestEndpoint}/nodes/${uuid}/download?download_format=cif&download=false`
13
+ );
14
+ const jsonAiiDACif = await responseAiiDACif.json();
15
+
16
+ console.log(jsonAiiDACif);
17
+
18
+ return jsonAiiDACif.data.download.data;
19
+ }
20
+
21
+ function App() {
22
+ const [cifText, setCifText] = useState(null);
23
+
24
+ // componentDidMount equivalent
25
+ useEffect(() => {
26
+ fetchCif().then((cifText) => {
27
+ setCifText(cifText);
28
+ });
29
+ });
30
+
31
+ return (
32
+ <div className="App">
33
+ <StructureVisualizer cifText={cifText} />
34
+ </div>
35
+ );
36
+ }
37
+
38
+ export default App;
@@ -0,0 +1,5 @@
1
+ .gldiv {
2
+ width: 98%;
3
+ height: 98%;
4
+ position: relative;
5
+ }
@@ -0,0 +1,82 @@
1
+ import React from "react";
2
+
3
+ import * as $3Dmol from "3dmol";
4
+
5
+ import "./Visualizer3dmol.css";
6
+
7
+ class Visualizer3dmol extends React.Component {
8
+ constructor(props) {
9
+ super(props);
10
+
11
+ this.viewer = null;
12
+ this.model = null;
13
+
14
+ // Assign random id to prevent multiple 'gldiv' from clashing
15
+ this.divId = "gldiv-" + (Math.random() + 1).toString(36).substring(7);
16
+ }
17
+
18
+ componentDidMount() {
19
+ // set up the viewer instance
20
+ let config = { backgroundColor: "mintcream", orthographic: true };
21
+ this.viewer = $3Dmol.createViewer(this.divId, config);
22
+
23
+ this.updateView();
24
+ }
25
+
26
+ updateView() {
27
+ this.viewer.removeAllModels();
28
+ this.model = this.viewer.addModel(this.props.cifText, "cif");
29
+
30
+ let style = {
31
+ sphere: { scale: 0.3, colorscheme: "Jmol" },
32
+ };
33
+ if (this.props.viewerParams.vdwRadius) {
34
+ style.sphere.scale = 1.0;
35
+ }
36
+ if (this.props.viewerParams.bonds) {
37
+ style.stick = { radius: 0.2, colorscheme: "Jmol" };
38
+ }
39
+
40
+ this.viewer.setStyle(style);
41
+
42
+ this.viewer.addUnitCell(this.model);
43
+ let sc = this.props.viewerParams.supercell;
44
+ this.viewer.replicateUnitCell(sc[0], sc[1], sc[2], this.model);
45
+ this.model.assignBonds();
46
+
47
+ // console.log(this.viewer.getView());
48
+ // this.viewer.setView([0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.5, 0.5]);
49
+
50
+ this.viewer.zoomTo();
51
+ this.viewer.render();
52
+ }
53
+
54
+ handleEvent(type, value) {
55
+ if (type == "camera") {
56
+ // console.log(this.viewer.getView());
57
+ if (value == "x") {
58
+ this.viewer.setView([0.0, 0.0, 0.0, 0.0, -0.5, -0.5, -0.5, 0.5]);
59
+ }
60
+ if (value == "y") {
61
+ this.viewer.setView([0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.5, 0.5]);
62
+ }
63
+ if (value == "z") {
64
+ this.viewer.setView([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]);
65
+ }
66
+ this.viewer.zoomTo();
67
+ }
68
+ }
69
+
70
+ render() {
71
+ if (this.viewer && this.model) {
72
+ this.updateView();
73
+ }
74
+ return (
75
+ <div id={this.divId} className="gldiv">
76
+ No data!
77
+ </div>
78
+ );
79
+ }
80
+ }
81
+
82
+ export default Visualizer3dmol;
@@ -0,0 +1,25 @@
1
+ .control-box {
2
+ position: relative;
3
+ z-index: 1;
4
+ height: 95px;
5
+ width: 448px;
6
+ background: rgb(223, 226, 255);
7
+ text-align: center;
8
+ border: 1px solid #999;
9
+ display: flex;
10
+ flex-direction: column;
11
+ justify-content: center;
12
+ align-items: start;
13
+ margin: 3px;
14
+ margin-top: -15px;
15
+ padding-top: 10px;
16
+ border-radius: 10px;
17
+ }
18
+
19
+ .control-box-row {
20
+ margin: 2px 5px;
21
+ }
22
+
23
+ .supercell-input {
24
+ width: 40px;
25
+ }
@@ -0,0 +1,88 @@
1
+ import React from "react";
2
+
3
+ import "./index.css";
4
+
5
+ class ControlBox extends React.Component {
6
+ constructor(props) {
7
+ super(props);
8
+ }
9
+
10
+ handleSupercellChange = (index, value) => {
11
+ let newSupercell = this.props.viewerParams.supercell;
12
+ newSupercell[index] = parseInt(value);
13
+ this.props.onViewerParamChange("supercell", newSupercell);
14
+ };
15
+
16
+ handleOptionChange = (option) => {
17
+ this.props.onViewerParamChange(option, !this.props.viewerParams[option]);
18
+ };
19
+
20
+ handleCameraEvent = (orientation) => {
21
+ this.props.onViewerEvent("camera", orientation);
22
+ };
23
+
24
+ render() {
25
+ return (
26
+ <div className="control-box">
27
+ <div className="control-box-row">
28
+ <label>Supercell: </label>
29
+ {[0, 1, 2].map((index) => (
30
+ <input
31
+ key={index}
32
+ className="supercell-input"
33
+ type="number"
34
+ value={this.props.viewerParams.supercell[index]}
35
+ onChange={(e) =>
36
+ this.handleSupercellChange(index, e.target.value)
37
+ }
38
+ />
39
+ ))}
40
+ </div>
41
+ <div className="control-box-row">
42
+ <label>Camera: </label>
43
+ <button onClick={() => this.handleCameraEvent("x")}>x</button>
44
+ <button onClick={() => this.handleCameraEvent("y")}>y</button>
45
+ <button onClick={() => this.handleCameraEvent("z")}>z</button>
46
+ </div>
47
+ <div className="control-box-row">
48
+ <label>
49
+ <input
50
+ type="checkbox"
51
+ checked={this.props.viewerParams.bonds}
52
+ onChange={() => this.handleOptionChange("bonds")}
53
+ />
54
+ Bonds
55
+ </label>
56
+ <label>
57
+ <input
58
+ type="checkbox"
59
+ checked={this.props.viewerParams.atomLabels}
60
+ onChange={() => this.handleOptionChange("atomLabels")}
61
+ disabled={true}
62
+ />
63
+ Atom Labels
64
+ </label>
65
+ <label>
66
+ <input
67
+ type="checkbox"
68
+ checked={this.props.viewerParams.packedCell}
69
+ onChange={() => this.handleOptionChange("packedCell")}
70
+ disabled={true}
71
+ />
72
+ Packed Cell
73
+ </label>
74
+ <label>
75
+ <input
76
+ type="checkbox"
77
+ checked={this.props.viewerParams.spaceFilling}
78
+ onChange={() => this.handleOptionChange("vdwRadius")}
79
+ />
80
+ vdW radius
81
+ </label>
82
+ </div>
83
+ </div>
84
+ );
85
+ }
86
+ }
87
+
88
+ export default ControlBox;
@@ -0,0 +1,14 @@
1
+ .structure-window {
2
+ position: relative;
3
+ z-index: 2;
4
+ height: 350px;
5
+ width: 448px;
6
+ background: #f5fffa;
7
+ text-align: center;
8
+ border: 1px solid #999;
9
+ display: flex;
10
+ justify-content: center;
11
+ align-items: center;
12
+ margin: 3px;
13
+ border-radius: 10px;
14
+ }
@@ -0,0 +1,65 @@
1
+ import React from "react";
2
+
3
+ import ControlBox from "./ControlBox";
4
+
5
+ import Visualizer3dmol from "./3dmol/Visualizer3dmol";
6
+
7
+ import "./index.css";
8
+
9
+ class StructureVisualizer extends React.Component {
10
+ constructor(props) {
11
+ super(props);
12
+
13
+ this.state = {
14
+ viewerParams: {
15
+ supercell: [2, 2, 2],
16
+ orientation: "x",
17
+ bonds: true,
18
+ atomLabels: false,
19
+ packedCell: false,
20
+ vdwRadius: false,
21
+ },
22
+ };
23
+
24
+ // use Ref to send events to the visualizer backend
25
+ this.visualizerRef = React.createRef();
26
+
27
+ this.handleViewerParamChange = this.handleViewerParamChange.bind(this);
28
+ this.handleViewerEvent = this.handleViewerEvent.bind(this);
29
+ }
30
+
31
+ handleViewerParamChange(param, value) {
32
+ this.setState({
33
+ viewerParams: {
34
+ ...this.state.viewerParams,
35
+ [param]: value,
36
+ },
37
+ });
38
+ }
39
+
40
+ handleViewerEvent(param, value) {
41
+ this.visualizerRef.current.handleEvent(param, value);
42
+ }
43
+
44
+ render() {
45
+ // console.log("CIF", this.props.cifText);
46
+ return (
47
+ <div className="structure-visualizer">
48
+ <div className="structure-window">
49
+ <Visualizer3dmol
50
+ ref={this.visualizerRef}
51
+ viewerParams={this.state.viewerParams}
52
+ cifText={this.props.cifText}
53
+ />
54
+ </div>
55
+ <ControlBox
56
+ viewerParams={this.state.viewerParams}
57
+ onViewerParamChange={this.handleViewerParamChange}
58
+ onViewerEvent={this.handleViewerEvent}
59
+ />
60
+ </div>
61
+ );
62
+ }
63
+ }
64
+
65
+ export default StructureVisualizer;
package/src/index.css ADDED
@@ -0,0 +1,13 @@
1
+ body {
2
+ margin: 0;
3
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4
+ 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5
+ sans-serif;
6
+ -webkit-font-smoothing: antialiased;
7
+ -moz-osx-font-smoothing: grayscale;
8
+ }
9
+
10
+ code {
11
+ font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12
+ monospace;
13
+ }
package/src/index.js ADDED
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom/client';
3
+ import './index.css';
4
+ import App from './App';
5
+ import reportWebVitals from './reportWebVitals';
6
+
7
+ const root = ReactDOM.createRoot(document.getElementById('root'));
8
+ root.render(
9
+ <React.StrictMode>
10
+ <App />
11
+ </React.StrictMode>
12
+ );
13
+
14
+ // If you want to start measuring performance in your app, pass a function
15
+ // to log results (for example: reportWebVitals(console.log))
16
+ // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
17
+ reportWebVitals();
@@ -0,0 +1,13 @@
1
+ const reportWebVitals = onPerfEntry => {
2
+ if (onPerfEntry && onPerfEntry instanceof Function) {
3
+ import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4
+ getCLS(onPerfEntry);
5
+ getFID(onPerfEntry);
6
+ getFCP(onPerfEntry);
7
+ getLCP(onPerfEntry);
8
+ getTTFB(onPerfEntry);
9
+ });
10
+ }
11
+ };
12
+
13
+ export default reportWebVitals;