Skip to content

Commit

Permalink
update bond determination
Browse files Browse the repository at this point in the history
  • Loading branch information
eimrek committed Mar 26, 2024
1 parent 43f9c44 commit af35964
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 37 deletions.
20 changes: 14 additions & 6 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import StructureVisualizer from "./StructureVisualizer";
async function fetchCif3D() {
// Fetch a cif file from the Materials Cloud AiiDA rest api
const aiidaRestEndpoint = "https://aiida.materialscloud.org/mc3d/api/v4";
const uuid = "85260507-9cb4-4849-a10d-703f32697dd7";
//const uuid = "07e48338-e639-485c-bed0-5f23bf6cfae2"; // Ag
//const uuid = "e36f52ac-0f64-47eb-86eb-550608c8672c"; // BN mc3d-66325/pbe
//const uuid = "aaea1e0f-337c-453f-a23a-acc06ddc93c9"; // BaTiO3 mc3d-46554/pbe
//const uuid = "a490b0ff-012a-44c8-a48a-f734dc634b3c"; // EuI4La mc3d-34858/pbe
let uuid = "85260507-9cb4-4849-a10d-703f32697dd7";

// potentially problematic cases w.r.t. bond lengths
// uuid = "07e48338-e639-485c-bed0-5f23bf6cfae2"; // Ag
// uuid = "e36f52ac-0f64-47eb-86eb-550608c8672c"; // BN mc3d-66325/pbe
// uuid = "aaea1e0f-337c-453f-a23a-acc06ddc93c9"; // BaTiO3 mc3d-46554/pbe
// uuid = "a490b0ff-012a-44c8-a48a-f734dc634b3c"; // EuI4La mc3d-34858/pbe
// uuid = "74046bff-82f1-4ced-b33e-54c09db90b78"; // "bizarre" graphite mc3d-19759/pbe
// uuid = "f5e7395f-ecad-4227-9789-21e7e4d21124"; // Al2H4Li2O14Si4 (water molecule) mc3d-12502/pbe

const responseAiiDACif = await fetch(
`${aiidaRestEndpoint}/nodes/${uuid}/download?download_format=cif&download=false`,
Expand All @@ -23,7 +27,11 @@ async function fetchCif3D() {
async function fetchCif2D() {
// Fetch a cif file from the Materials Cloud AiiDA rest api
const aiidaRestEndpoint = "https://aiida.materialscloud.org/mc2d/api/v4";
const uuid = "42744ae7-0c30-43df-8136-ab625b4f8425"; // graphene

let uuid = "42744ae7-0c30-43df-8136-ab625b4f8425"; // graphene

// potentially problematic cases w.r.t. bond lengths
uuid = "89a8e9ec-d89b-47bb-a85e-8f1b6734a69c"; // Bi

const responseAiiDACif = await fetch(
`${aiidaRestEndpoint}/nodes/${uuid}/download?download_format=cif&download=false`,
Expand Down
35 changes: 4 additions & 31 deletions src/StructureVisualizer/StructureWindow/3dmol/Visualizer3dmol.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import React from "react";

import * as $3Dmol from "3dmol";

import * as math from "mathjs";

import { covalentRadii } from "./bondLengths";

import "./Visualizer3dmol.css";
Expand All @@ -12,32 +10,17 @@ function mod(n, m) {
return ((n % m) + m) % m;
}

// override the covalent bond detection based on examples in MC3D
const overrideBondLengths = {
// uuid = "aaea1e0f-337c-453f-a23a-acc06ddc93c9"; // BaTiO3 mc3d-46554/pbe
Ba: 0.92 * covalentRadii["Ba"],
Ti: 0.94 * covalentRadii["Ti"],
// uuid = "a490b0ff-012a-44c8-a48a-f734dc634b3c"; // EuI4La mc3d-34858/pbe
I: 1.05 * covalentRadii["I"],
Eu: 1.05 * covalentRadii["Eu"],
};

function setCustomBondLengths() {
function setCustomBondLength(elem, len) {
// 3dmol adds 0.25 to the total bond length as a "fudge_factor"
let fudgeCorrection = 0.125;
$3Dmol.setBondLength(elem, len - fudgeCorrection);
// to correct for this, one could here subtract 0.125 from each atom's
// bond length but it seems it's better to keep the "fudge factor".
$3Dmol.setBondLength(elem, len);
}

// override the default bond lengths with covalentRadii
Object.keys(covalentRadii).forEach((elem) => {
setCustomBondLength(elem, covalentRadii[elem]);
});

// override further based on custom-defined lengths
Object.keys(overrideBondLengths).forEach((elem) => {
setCustomBondLength(elem, overrideBondLengths[elem]);
});
}

class Visualizer3dmol extends React.Component {
Expand Down Expand Up @@ -93,16 +76,6 @@ class Visualizer3dmol extends React.Component {

let final_atoms = [];

// console.log("loadedAtoms", loadedAtoms);
// loadedAtoms = [
// {
// elem: "C",
// x: 0.1,
// y: 0.1,
// z: 50.0,
// },
// ];

// in case of packed cell, make sure all the initially specified atoms
// are folded back to the unit cell
let atoms = [];
Expand Down Expand Up @@ -198,7 +171,7 @@ class Visualizer3dmol extends React.Component {
style.sphere.scale = 1.0;
}
if (this.props.viewerParams.bonds) {
style.stick = { radius: 0.2, colorscheme: "Jmol" };
style.stick = { radius: 0.15, colorscheme: "Jmol" };
}

this.viewer.setStyle(style);
Expand Down

0 comments on commit af35964

Please sign in to comment.