mc-react-structure-visualizer 0.4.3 → 0.6.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.
@@ -1,66 +0,0 @@
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 _Visualizer3dmol = _interopRequireDefault(require("./3dmol/Visualizer3dmol"));
10
- require("./index.css");
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
- 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); } }
14
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
15
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
16
- 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); }
17
- 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); }
18
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
19
- 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); }; }
20
- 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); }
21
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
22
- 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; } }
23
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
24
- var StructureWindow = /*#__PURE__*/function (_React$Component) {
25
- _inherits(StructureWindow, _React$Component);
26
- var _super = _createSuper(StructureWindow);
27
- function StructureWindow(props) {
28
- _classCallCheck(this, StructureWindow);
29
- return _super.call(this, props);
30
- }
31
- _createClass(StructureWindow, [{
32
- key: "render",
33
- value: function render() {
34
- var _this = this;
35
- var swClassName = "structure-window";
36
- if (!this.props.mouseEnabled) swClassName += " disable-mouse";
37
- var mouseNoteText = "Interaction off";
38
- var mouseNoteClass = "mouse-disabled-note";
39
- if (this.props.mouseEnabled) {
40
- mouseNoteText = "Interaction on";
41
- mouseNoteClass = "mouse-disabled-note on";
42
- }
43
- return /*#__PURE__*/_react["default"].createElement("div", {
44
- className: "structure-window-outer"
45
- }, /*#__PURE__*/_react["default"].createElement("div", {
46
- onClick: function onClick() {
47
- return _this.props.setMouseEnabledState(true);
48
- }
49
- }, /*#__PURE__*/_react["default"].createElement("div", {
50
- className: swClassName
51
- }, /*#__PURE__*/_react["default"].createElement(_Visualizer3dmol["default"], {
52
- ref: this.props.visualizerRef,
53
- viewerParams: this.props.viewerParams,
54
- cifText: this.props.cifText
55
- }))), /*#__PURE__*/_react["default"].createElement("div", {
56
- className: mouseNoteClass,
57
- onClick: function onClick() {
58
- return _this.props.setMouseEnabledState(!_this.props.mouseEnabled);
59
- }
60
- }, mouseNoteText));
61
- }
62
- }]);
63
- return StructureWindow;
64
- }(_react["default"].Component);
65
- var _default = StructureWindow;
66
- exports["default"] = _default;
package/dist/index.js DELETED
@@ -1,117 +0,0 @@
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 _StructureWindow = _interopRequireDefault(require("./StructureWindow"));
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
- bonds: true,
39
- atomLabels: false,
40
- packedCell: false,
41
- vdwRadius: false
42
- },
43
- mouseEnabled: false
44
- };
45
-
46
- // use Ref to send events to the visualizer backend
47
- _this.visualizerRef = /*#__PURE__*/_react["default"].createRef();
48
-
49
- // Ref to detect click outside
50
- _this.wrapperRef = /*#__PURE__*/_react["default"].createRef();
51
- _this.handleClickOutside = _this.handleClickOutside.bind(_assertThisInitialized(_this));
52
- _this.handleViewerParamChange = _this.handleViewerParamChange.bind(_assertThisInitialized(_this));
53
- _this.handleViewerEvent = _this.handleViewerEvent.bind(_assertThisInitialized(_this));
54
- _this.setMouseEnabledState = _this.setMouseEnabledState.bind(_assertThisInitialized(_this));
55
- return _this;
56
- }
57
- _createClass(StructureVisualizer, [{
58
- key: "componentDidMount",
59
- value: function componentDidMount() {
60
- document.addEventListener("mousedown", this.handleClickOutside);
61
- }
62
- }, {
63
- key: "componentWillUnmount",
64
- value: function componentWillUnmount() {
65
- document.removeEventListener("mousedown", this.handleClickOutside);
66
- }
67
- }, {
68
- key: "handleClickOutside",
69
- value: function handleClickOutside(event) {
70
- if (this.wrapperRef && !this.wrapperRef.current.contains(event.target)) {
71
- this.setState({
72
- mouseEnabled: false
73
- });
74
- }
75
- }
76
- }, {
77
- key: "setMouseEnabledState",
78
- value: function setMouseEnabledState(state) {
79
- this.setState({
80
- mouseEnabled: state
81
- });
82
- }
83
- }, {
84
- key: "handleViewerParamChange",
85
- value: function handleViewerParamChange(param, value) {
86
- this.setState({
87
- viewerParams: _objectSpread(_objectSpread({}, this.state.viewerParams), {}, _defineProperty({}, param, value))
88
- });
89
- }
90
- }, {
91
- key: "handleViewerEvent",
92
- value: function handleViewerEvent(param, value) {
93
- this.visualizerRef.current.handleEvent(param, value);
94
- }
95
- }, {
96
- key: "render",
97
- value: function render() {
98
- return /*#__PURE__*/_react["default"].createElement("div", {
99
- ref: this.wrapperRef,
100
- className: "structure-visualizer"
101
- }, /*#__PURE__*/_react["default"].createElement(_StructureWindow["default"], {
102
- visualizerRef: this.visualizerRef,
103
- viewerParams: this.state.viewerParams,
104
- cifText: this.props.cifText,
105
- mouseEnabled: this.state.mouseEnabled,
106
- setMouseEnabledState: this.setMouseEnabledState
107
- }), /*#__PURE__*/_react["default"].createElement(_ControlBox["default"], {
108
- viewerParams: this.state.viewerParams,
109
- onViewerParamChange: this.handleViewerParamChange,
110
- onViewerEvent: this.handleViewerEvent
111
- }));
112
- }
113
- }]);
114
- return StructureVisualizer;
115
- }(_react["default"].Component);
116
- var _default = StructureVisualizer;
117
- exports["default"] = _default;
Binary file
package/public/index.html DELETED
@@ -1,43 +0,0 @@
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
@@ -1,25 +0,0 @@
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
- }
package/public/robots.txt DELETED
@@ -1,3 +0,0 @@
1
- # https://www.robotstxt.org/robotstxt.html
2
- User-agent: *
3
- Disallow:
package/src/App.css DELETED
@@ -1,38 +0,0 @@
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 DELETED
@@ -1,44 +0,0 @@
1
- import React, { useState, useEffect } from "react";
2
-
3
- // Note: Bootstrap is not really used.
4
- // Just the default css is loaded to test how the component works with bootstrap.
5
- import "bootstrap/dist/css/bootstrap.min.css";
6
-
7
- import "./App.css";
8
- import StructureVisualizer from "./StructureVisualizer";
9
-
10
- async function fetchCif() {
11
- // Fetch a cif file from the Materials Cloud AiiDA rest api
12
- const aiidaRestEndpoint = "https://aiida.materialscloud.org/mc3d/api/v4";
13
- const uuid = "85260507-9cb4-4849-a10d-703f32697dd7";
14
- //const uuid = "07e48338-e639-485c-bed0-5f23bf6cfae2"; // Ag
15
- //const uuid = "e36f52ac-0f64-47eb-86eb-550608c8672c"; // BN mc3d-66325/pbe
16
- //const uuid = "aaea1e0f-337c-453f-a23a-acc06ddc93c9"; // BaTiO3 mc3d-46554/pbe
17
- //const uuid = "a490b0ff-012a-44c8-a48a-f734dc634b3c"; // EuI4La mc3d-34858/pbe
18
-
19
- const responseAiiDACif = await fetch(
20
- `${aiidaRestEndpoint}/nodes/${uuid}/download?download_format=cif&download=false`
21
- );
22
- const jsonAiiDACif = await responseAiiDACif.json();
23
-
24
- return jsonAiiDACif.data.download.data;
25
- }
26
-
27
- function App() {
28
- const [cifText, setCifText] = useState(null);
29
-
30
- // componentDidMount equivalent
31
- useEffect(() => {
32
- fetchCif().then((cifText) => {
33
- setCifText(cifText);
34
- });
35
- });
36
-
37
- return (
38
- <div className="App">
39
- <StructureVisualizer cifText={cifText} />
40
- </div>
41
- );
42
- }
43
-
44
- export default App;
@@ -1,67 +0,0 @@
1
- .control-box {
2
- position: relative;
3
- z-index: 1;
4
- height: 100px;
5
- width: 450px;
6
- background: rgb(250, 250, 250);
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-top: -20px;
14
- padding: 30px 10px 10px 10px;
15
- border-radius: 5px;
16
- }
17
-
18
- .supercell-input {
19
- width: 45px;
20
- height: 25px;
21
- }
22
-
23
- /* Always show the small arrows (needed for Chrome) */
24
- .supercell-input::-webkit-inner-spin-button,
25
- .supercell-input::-webkit-outer-spin-button {
26
- opacity: 1;
27
- }
28
-
29
- .control-box-row {
30
- margin: 5px 0px;
31
- padding: 0px 10px;
32
- width: 100%;
33
- line-height: inherit;
34
- /* background-color: pink; */
35
- display: flex;
36
- justify-content: space-between;
37
- align-items: stretch;
38
- }
39
-
40
- .control-box-row label {
41
- margin: 0px 5px;
42
- }
43
-
44
- .control-box-row button {
45
- border-width: 1px;
46
- border-style: outset;
47
- border-color: rgb(0, 0, 0);
48
- border-radius: 4px;
49
- display: inline-flex;
50
- align-items: center;
51
- /* margin-top: -10px; */
52
- margin: 0px 1px;
53
- height: 25px;
54
- }
55
-
56
- .control-box-row button:hover {
57
- background-color: rgb(222, 222, 222);
58
- }
59
- .control-box-row .option-checkbox {
60
- margin: 0px 2px;
61
- }
62
-
63
- .control-box-row .camera-controls {
64
- margin-left: auto;
65
- margin-right: auto;
66
- display: inline;
67
- }
@@ -1,94 +0,0 @@
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
- <div className="supercell-container">
29
- <label>Supercell: </label>
30
- {[0, 1, 2].map((index) => (
31
- <input
32
- key={index}
33
- className="supercell-input"
34
- type="number"
35
- min="1"
36
- value={this.props.viewerParams.supercell[index]}
37
- onChange={(e) =>
38
- this.handleSupercellChange(index, e.target.value)
39
- }
40
- />
41
- ))}
42
- </div>
43
- <div className="camera-controls">
44
- <label>Camera: </label>
45
- <button onClick={() => this.handleCameraEvent("x")}>x</button>
46
- <button onClick={() => this.handleCameraEvent("y")}>y</button>
47
- <button onClick={() => this.handleCameraEvent("z")}>z</button>
48
- </div>
49
- </div>
50
- <div className="control-box-row">
51
- <label>
52
- <input
53
- className="option-checkbox"
54
- type="checkbox"
55
- checked={this.props.viewerParams.bonds}
56
- onChange={() => this.handleOptionChange("bonds")}
57
- />
58
- Bonds
59
- </label>
60
- <label>
61
- <input
62
- className="option-checkbox"
63
- type="checkbox"
64
- checked={this.props.viewerParams.atomLabels}
65
- onChange={() => this.handleOptionChange("atomLabels")}
66
- />
67
- Atom labels
68
- </label>
69
- <label>
70
- <input
71
- className="option-checkbox"
72
- type="checkbox"
73
- checked={this.props.viewerParams.packedCell}
74
- onChange={() => this.handleOptionChange("packedCell")}
75
- disabled={true}
76
- />
77
- Packed cell
78
- </label>
79
- <label>
80
- <input
81
- className="option-checkbox"
82
- type="checkbox"
83
- checked={this.props.viewerParams.spaceFilling}
84
- onChange={() => this.handleOptionChange("vdwRadius")}
85
- />
86
- vdW radius
87
- </label>
88
- </div>
89
- </div>
90
- );
91
- }
92
- }
93
-
94
- export default ControlBox;
@@ -1,5 +0,0 @@
1
- .gldiv {
2
- width: 98%;
3
- height: 98%;
4
- position: relative;
5
- }
@@ -1,140 +0,0 @@
1
- import React from "react";
2
-
3
- import * as $3Dmol from "3dmol";
4
-
5
- import { covalentRadii } from "./bondLengths";
6
-
7
- import "./Visualizer3dmol.css";
8
-
9
- // override the covalent bond detection based on examples in MC3D
10
- const overrideBondLengths = {
11
- // uuid = "aaea1e0f-337c-453f-a23a-acc06ddc93c9"; // BaTiO3 mc3d-46554/pbe
12
- Ba: 0.92 * covalentRadii["Ba"],
13
- Ti: 0.94 * covalentRadii["Ti"],
14
- // uuid = "a490b0ff-012a-44c8-a48a-f734dc634b3c"; // EuI4La mc3d-34858/pbe
15
- I: 1.05 * covalentRadii["I"],
16
- Eu: 1.05 * covalentRadii["Eu"],
17
- };
18
-
19
- function setCustomBondLengths() {
20
- function setCustomBondLength(elem, len) {
21
- // 3dmol adds 0.25 to the total bond length as a "fudge_factor"
22
- let fudgeCorrection = 0.125;
23
- $3Dmol.setBondLength(elem, len - fudgeCorrection);
24
- }
25
-
26
- // override the default bond lengths with covalentRadii
27
- Object.keys(covalentRadii).forEach((elem) => {
28
- setCustomBondLength(elem, covalentRadii[elem]);
29
- });
30
-
31
- // override further based on custom-defined lengths
32
- Object.keys(overrideBondLengths).forEach((elem) => {
33
- setCustomBondLength(elem, overrideBondLengths[elem]);
34
- });
35
- }
36
-
37
- class Visualizer3dmol extends React.Component {
38
- constructor(props) {
39
- super(props);
40
-
41
- setCustomBondLengths();
42
-
43
- this.viewer = null;
44
- this.model = null;
45
-
46
- // Assign random id to prevent multiple 'gldiv' from clashing
47
- this.divId = "gldiv-" + (Math.random() + 1).toString(36).substring(7);
48
- }
49
-
50
- componentDidMount() {
51
- // set up the viewer instance
52
- let config = { backgroundColor: "white", orthographic: true };
53
- this.viewer = $3Dmol.createViewer(this.divId, config);
54
-
55
- this.updateView();
56
- }
57
-
58
- componentDidUpdate(prevProps) {
59
- if (
60
- prevProps.viewerParams != this.props.viewerParams ||
61
- prevProps.cifText != this.props.cifText
62
- ) {
63
- this.updateView();
64
- }
65
- }
66
-
67
- updateView() {
68
- this.viewer.removeAllModels();
69
- this.model = this.viewer.addModel(this.props.cifText, "cif");
70
-
71
- let style = {
72
- sphere: { scale: 0.3, colorscheme: "Jmol" },
73
- };
74
- if (this.props.viewerParams.vdwRadius) {
75
- style.sphere.scale = 1.0;
76
- }
77
- if (this.props.viewerParams.bonds) {
78
- style.stick = { radius: 0.2, colorscheme: "Jmol" };
79
- }
80
-
81
- this.viewer.setStyle(style);
82
-
83
- this.viewer.addUnitCell(this.model);
84
- let sc = this.props.viewerParams.supercell;
85
- this.viewer.replicateUnitCell(sc[0], sc[1], sc[2], this.model);
86
-
87
- this.model.assignBonds();
88
-
89
- this.viewer.removeAllLabels();
90
- if (this.props.viewerParams.atomLabels) {
91
- this.model.atoms.forEach((atom) => {
92
- this.viewer.addLabel(
93
- atom.elem,
94
- {
95
- position: { x: atom.x, y: atom.y, z: atom.z },
96
- fontColor: "black",
97
- bold: true,
98
- fontSize: 18,
99
- showBackground: false,
100
- backgroundOpacity: 1.0,
101
- inFront: true,
102
- },
103
- null,
104
- true
105
- );
106
- });
107
- }
108
-
109
- this.viewer.zoomTo();
110
- this.viewer.zoom(1.4);
111
- this.viewer.render();
112
- }
113
-
114
- handleEvent(type, value) {
115
- if (type == "camera") {
116
- // console.log(this.viewer.getView());
117
- if (value == "x") {
118
- this.viewer.setView([0.0, 0.0, 0.0, 0.0, -0.5, -0.5, -0.5, 0.5]);
119
- }
120
- if (value == "y") {
121
- this.viewer.setView([0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.5, 0.5]);
122
- }
123
- if (value == "z") {
124
- this.viewer.setView([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]);
125
- }
126
- this.viewer.zoomTo();
127
- this.viewer.zoom(1.4);
128
- }
129
- }
130
-
131
- render() {
132
- return (
133
- <div id={this.divId} className="gldiv">
134
- No data!
135
- </div>
136
- );
137
- }
138
- }
139
-
140
- export default Visualizer3dmol;