| import { |
| IMolData, |
| sendResponseToMainThread, |
| waitForDataFromMainThread, |
| } from "@/Core/WebWorkers/WorkerHelper"; |
|
|
| import { |
| IAtom, |
| TreeNodeType, |
| SelectedType, |
| } from "@/UI/Navigation/TreeView/TreeInterfaces"; |
| import { randomID } from "@/Core/Utils/MiscUtils"; |
| import { |
| defaultProteinStyle, |
| defaultNucleicStyle, |
| defaultLigandsStyle, |
| defaultMetalsStyle, |
| defaultLipidStyle, |
| defaultIonsStyle, |
| defaultSolventStyle, |
| } from "@/Core/Styling/SelAndStyleDefinitions"; |
| import { |
| ionSel, |
| lipidSel, |
| metalSel, |
| nucleicSel, |
| proteinSel, |
| solventSel, |
| standardProteinResidues, |
| } from "../Types/ComponentSelections"; |
| import { IFormatInfo, getFormatInfoGivenType } from "../Types/MolFormats"; |
| import { getFileNameParts } from "@/FileSystem/FilenameManipulation"; |
| import { TreeNode } from "@/TreeNodes/TreeNode/TreeNode"; |
| import { TreeNodeList } from "@/TreeNodes/TreeNodeList/TreeNodeList"; |
| import { IFileInfo } from "@/FileSystem/Types"; |
| import { makeEasyParser } from "./EasyParser"; |
| import { EasyParserParent } from "./EasyParser/EasyParserParent"; |
| import { convertIAtomsToIFileInfoPDB } from "../ConvertMolModels/_ConvertIAtoms"; |
| import { ISelAndStyle } from "@/Core/Styling/SelAndStyleInterfaces"; |
| import { organizeNodesIntoHierarchy } from "@/UI/Navigation/TreeView/TreeUtils"; |
|
|
| enum NodesOrModel { |
| Nodes, |
| Model, |
| } |
|
|
| const COLLAPSE_ONE_NODE_LEVELS = false; |
| const COVALENT_RADII: { [key: string]: number } = { |
| H: 0.31, HE: 0.28, LI: 1.28, BE: 0.96, B: 0.84, C: 0.76, |
| N: 0.71, O: 0.66, F: 0.57, NE: 0.58, NA: 1.66, MG: 1.41, |
| AL: 1.21, SI: 1.11, P: 1.07, S: 1.05, CL: 1.02, K: 2.03, |
| CA: 1.76, SC: 1.57, TI: 1.48, V: 1.44, CR: 1.39, MN: 1.39, |
| FE: 1.32, CO: 1.26, NI: 1.24, CU: 1.32, ZN: 1.22, GA: 1.22, |
| GE: 1.20, AS: 1.19, SE: 1.20, BR: 1.20, KR: 1.16, RB: 2.20, |
| SR: 1.95, Y: 1.90, ZR: 1.75, NB: 1.64, MO: 1.54, TC: 1.47, |
| RU: 1.46, RH: 1.42, PD: 1.39, AG: 1.45, CD: 1.44, IN: 1.42, |
| SN: 1.39, SB: 1.39, TE: 1.38, I: 1.39, XE: 1.40, CS: 2.44, |
| BA: 2.15, LA: 2.07, CE: 2.04, PR: 2.03, ND: 2.01, PM: 1.99, |
| SM: 1.98, EU: 1.98, GD: 1.96, TB: 1.94, DY: 1.92, HO: 1.92, |
| ER: 1.89, TM: 1.90, YB: 1.87, LU: 1.87, HF: 1.75, TA: 1.70, |
| W: 1.62, RE: 1.51, OS: 1.44, IR: 1.41, PT: 1.36, AU: 1.36, |
| HG: 1.32, TL: 1.45, PB: 1.46, BI: 1.48, PO: 1.40, AT: 1.50, |
| RN: 1.50, FR: 2.60, RA: 2.21, AC: 2.15, TH: 2.06, PA: 2.00, |
| U: 1.96, NP: 1.90, PU: 1.87, AM: 1.80, CM: 1.69 |
| }; |
| const DEFAULT_COVALENT_RADIUS = 0.76; |
| const BONDING_TOLERANCE = 0.45; |
| |
| |
| |
| |
| |
| |
| function getAtomRadius(atom: IAtom): number { |
| const elem = atom.elem ? atom.elem.toUpperCase() : ""; |
| return COVALENT_RADII[elem] || DEFAULT_COVALENT_RADIUS; |
| } |
| |
| |
| |
| |
| |
| |
| |
| function areGroupsBonded(group1: EasyParserParent, group2: EasyParserParent): boolean { |
| |
| |
| if (!group1.isWithinDistance(group2, 3.0)) { |
| return false; |
| } |
| for (let i = 0; i < group1.length; i++) { |
| const a1 = group1.getAtom(i); |
| if (a1.x === undefined || a1.y === undefined || a1.z === undefined) continue; |
| const r1 = getAtomRadius(a1); |
| for (let j = 0; j < group2.length; j++) { |
| const a2 = group2.getAtom(j); |
| if (a2.x === undefined || a2.y === undefined || a2.z === undefined) continue; |
| const r2 = getAtomRadius(a2); |
| const distSq = (a1.x - a2.x) ** 2 + (a1.y - a2.y) ** 2 + (a1.z - a2.z) ** 2; |
| const threshold = r1 + r2 + BONDING_TOLERANCE; |
| if (distSq <= threshold * threshold) { |
| return true; |
| } |
| } |
| } |
| return false; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function _getDefaultTreeNode( |
| molName: string, |
| nodesOrModel = NodesOrModel.Nodes |
| ): TreeNode { |
| let obj = { |
| title: molName, |
| viewerDirty: true, |
| treeExpanded: false, |
| visible: true, |
| focused: false, |
| selected: SelectedType.False, |
| }; |
|
|
| obj = { |
| ...obj, |
| ...(nodesOrModel === NodesOrModel.Model |
| ? { model: [] } |
| : { nodes: new TreeNodeList() }), |
| }; |
|
|
| return new TreeNode(obj); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function organizeSelByChain( |
| sel: any, |
| mol: EasyParserParent, |
| molName: string |
| ): TreeNode { |
| let selectedAtoms = mol.selectedAtoms(sel, true); |
|
|
| |
| selectedAtoms = selectedAtoms.map((atom: IAtom) => { |
| if (atom.chain === " ") { |
| atom.chain = "X"; |
| } |
| return atom; |
| }); |
|
|
| const treeNode = _getDefaultTreeNode(molName); |
| let lastChainID = ""; |
| selectedAtoms.forEach((atom: IAtom) => { |
| const nodeList = treeNode.nodes as TreeNodeList; |
| if (atom.chain !== lastChainID) { |
| nodeList.push( |
| new TreeNode({ |
| title: atom.chain, |
| model: [], |
| viewerDirty: true, |
| treeExpanded: false, |
| visible: true, |
| selected: SelectedType.False, |
| focused: false, |
| }) |
| ); |
| lastChainID = atom.chain; |
| } |
|
|
| (nodeList.get(nodeList.length - 1).model as IAtom[]).push(atom); |
| }); |
| |
|
|
| return treeNode; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| function flattenChains(treeNode: TreeNode): TreeNode { |
| if (!treeNode.nodes) { |
| throw new Error("No nodes found in treeNode."); |
| } |
|
|
| const flattened = _getDefaultTreeNode(treeNode.title, NodesOrModel.Model); |
|
|
| treeNode.nodes.forEach((chain: TreeNode) => { |
| if (!chain.model) { |
| throw new Error("No atoms found in chain."); |
| } |
|
|
| (flattened.model as IAtom[]).push(...(chain.model as IAtom[])); |
| }); |
| return flattened; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| function residueID(atom: IAtom): string { |
| return atom.resn + ":" + atom.resi; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| function divideChainsIntoResidues(treeNode: TreeNode): TreeNode { |
| if (!treeNode.nodes) { |
| return treeNode; |
| } |
|
|
| const dividedMolEntry = _getDefaultTreeNode(treeNode.title); |
|
|
| let lastChainID = ""; |
| treeNode.nodes.forEach((chain: TreeNode) => { |
| if (!chain.model) { |
| |
| return; |
| } |
|
|
| if (chain.title === "" || chain.title === undefined) { |
| |
| chain.title = "A"; |
| } |
|
|
| if (chain.title !== lastChainID) { |
| dividedMolEntry.nodes?.push(_getDefaultTreeNode(chain.title)); |
| lastChainID = chain.title; |
| } |
|
|
| let lastResidueID = ""; |
| (chain.model as IAtom[]).forEach((atom: IAtom) => { |
| const chains = dividedMolEntry.nodes; |
| if (!chains) { |
| throw new Error("No chains found in dividedMolEntry."); |
| } |
| const residues = chains.get(chains.length - 1).nodes; |
| if (!residues) { |
| |
| throw new Error("No residues found in dividedMolEntry."); |
| } |
|
|
| const newKey = residueID(atom); |
| if (newKey !== lastResidueID) { |
| residues.push(_getDefaultTreeNode(newKey, NodesOrModel.Model)); |
| lastResidueID = newKey; |
| } |
| const atoms = residues.get(residues.length - 1).model as IAtom[]; |
| if (atoms) { |
| atoms.push(atom); |
| } |
| }); |
| }); |
| return dividedMolEntry; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function collapseSingles( |
| treeNode: TreeNode, |
| childTitleFirst = false |
| ): TreeNode { |
| if (treeNode.nodes) { |
| let anyNodeMerged = true; |
| while (anyNodeMerged) { |
| anyNodeMerged = false; |
|
|
| const allNodes = new TreeNodeList([treeNode]).flattened; |
| allNodes.forEach((anyNode: TreeNode) => { |
| const anyNodeNodes = anyNode.nodes as TreeNodeList; |
| if (anyNode.nodes && anyNodeNodes.length === 1) { |
| |
| const childNode = anyNodeNodes.get(0); |
| anyNode.title = childTitleFirst |
| ? `${childNode.title}:${anyNode.title}` |
| : `${anyNode.title}:${childNode.title}`; |
| anyNode.model = childNode.model; |
| anyNode.type = childNode.type; |
|
|
| if (childNode.nodes) { |
| anyNode.nodes = childNode.nodes; |
| } else { |
| delete anyNode.nodes; |
| } |
|
|
| anyNodeMerged = true; |
| } |
| }); |
| } |
| } |
|
|
| |
| |
|
|
| if (treeNode.title.endsWith(":Compound")) { |
| if (!treeNode.nodes || treeNode.nodes.length === 0) { |
| |
| treeNode.title = treeNode.title.substring( |
| 0, |
| treeNode.title.length - 9 |
| ); |
| } else { |
| |
| treeNode.title = treeNode.title.split(":")[1]; |
| } |
| } else { |
| |
| treeNode.title = treeNode.title.split(":")[0]; |
| } |
|
|
| return treeNode; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| function addMolTypeAndStyle(treeNode: TreeNode, stylesAndSels: ISelAndStyle[]) { |
| const molType = treeNode.type; |
| new TreeNodeList([treeNode]).filters.onlyTerminal.forEach( |
| (mol: TreeNode) => { |
| mol.type = molType; |
| mol.styles = stylesAndSels; |
| } |
| ); |
|
|
| new TreeNodeList([treeNode]).flattened.forEach((mol: TreeNode) => { |
| mol.id = randomID(); |
| mol.treeExpanded = false; |
| mol.visible = true; |
| mol.viewerDirty = true; |
| }); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| function getFormatInfo(data: IMolData): IFormatInfo { |
| const molFormat = data.format; |
| return getFormatInfoGivenType(molFormat) as IFormatInfo; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| function divideMolTxtIntoFrames( |
| molText: string, |
| molFormatInfo: IFormatInfo |
| ): string[] { |
| let frames: string[] = [molText]; |
|
|
| |
| |
| |
|
|
| if (molFormatInfo && molFormatInfo.frameSeparators) { |
| for (const frameSeparator of molFormatInfo.frameSeparators) { |
| |
| if (frameSeparator.isAtEndOfFrame) { |
| |
| |
| |
| |
| molText = molText.replaceAll( |
| frameSeparator.text, |
| |
| (frameSeparator.text !== "\n$$$$\n" |
| ? frameSeparator.text |
| : "\n$$$$$$$$\n") + "<<DIVIDE>>" |
| ); |
|
|
| |
| } else { |
| |
| |
| molText = molText.replaceAll( |
| frameSeparator.text, |
| "<<DIVIDE>>" + frameSeparator.text |
| ); |
| } |
| } |
|
|
| frames = molText.split("<<DIVIDE>>"); |
| frames = frames.map((f) => f.trim()).filter((f) => f.length > 0); |
| } |
|
|
| return frames; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| function getNameFromContent( |
| molText: string, |
| molFormatInfo: IFormatInfo |
| ): string { |
| const regexps = molFormatInfo.extractMolNameRegex; |
| let firstMatch = ""; |
| if (regexps) { |
| for (const regexp of regexps) { |
| |
| |
| regexp.lastIndex = 0; |
|
|
| const match = regexp.exec(molText); |
| if (match) { |
| firstMatch = match[1]; |
| break; |
|
|
| |
| |
| } |
| } |
| } |
|
|
| |
| if (firstMatch.endsWith(";")) { |
| firstMatch = firstMatch.substring(0, firstMatch.length - 1); |
| } |
|
|
| |
| |
|
|
| |
| |
| if (firstMatch.length > 20) { |
| firstMatch = firstMatch.substring(0, 20) + "..."; |
| } |
|
|
| |
| return firstMatch.replaceAll(":", ""); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| function dividePDBAtomsIntoDistinctComponents( |
| data: IMolData |
| ): Promise<TreeNodeList> { |
| |
|
|
| |
| const molFormatInfo = getFormatInfo(data); |
| const frames = divideMolTxtIntoFrames( |
| data.fileInfo.contents, |
| molFormatInfo |
| ); |
|
|
| const molName = getFileNameParts(data.fileInfo.name).basename; |
| const frameTitles = frames.map((f, i) => { |
| return `${getNameFromContent(f, molFormatInfo)}:${molName}:${i + 1}`; |
| }); |
|
|
| const fileContentsAllFrames: TreeNodeList = new TreeNodeList(); |
|
|
| for (let frameIdx = 0; frameIdx < frames.length; frameIdx++) { |
| const frame = frames[frameIdx]; |
| const frameTitle = frameTitles[frameIdx]; |
| const molWithAtomsToDivide = makeEasyParser({ |
| contents: frame, |
| name: `tmp.${data.format}`, |
| } as IFileInfo); |
|
|
| if (molWithAtomsToDivide.length === 0) { |
| |
| continue; |
| } |
| |
| const terminalNodes = new TreeNodeList(); |
| const componentSels: [any, TreeNodeType, boolean][] = [ |
| [proteinSel, TreeNodeType.Protein, false], |
| [nucleicSel, TreeNodeType.Nucleic, false], |
| [solventSel, TreeNodeType.Solvent, true], |
| [metalSel, TreeNodeType.Metal, true], |
| [ionSel, TreeNodeType.Ions, true], |
| [lipidSel, TreeNodeType.Lipid, false], |
| ]; |
| for (const [sel, type, flatten] of componentSels) { |
| let selToUse = {}; |
| if (sel.or) { |
| |
| for (const s of sel.or) { |
| selToUse = { ...selToUse, ...s }; |
| } |
| } else { |
| selToUse = sel; |
| } |
| const atoms = molWithAtomsToDivide.selectedAtoms(selToUse, true); |
| if (atoms.length > 0) { |
| if (flatten) { |
| terminalNodes.push( |
| new TreeNode({ |
| title: type, |
| type: type, |
| model: atoms, |
| visible: true, |
| focused: false, |
| viewerDirty: true, |
| treeExpanded: false, |
| selected: SelectedType.False, |
| }) |
| ); |
| } else { |
| |
| const atomsByChain: { [key: string]: IAtom[] } = {}; |
| atoms.forEach((atom) => { |
| const chain = atom.chain || "A"; |
| if (!atomsByChain[chain]) atomsByChain[chain] = []; |
| atomsByChain[chain].push(atom); |
| }); |
| for (const chainId in atomsByChain) { |
| terminalNodes.push( |
| new TreeNode({ |
| title: chainId, |
| type: type, |
| model: atomsByChain[chainId], |
| visible: true, |
| focused: false, |
| viewerDirty: true, |
| treeExpanded: false, |
| selected: SelectedType.False, |
| }) |
| ); |
| } |
| } |
| } |
| } |
| |
| const remainingAtoms = molWithAtomsToDivide.atoms; |
| if (remainingAtoms.length > 0) { |
| |
| const atomsByResidue: { [key: string]: IAtom[] } = {}; |
| const resKeys: string[] = []; |
| remainingAtoms.forEach((atom) => { |
| const resId = `${atom.resn}:${atom.resi}:${atom.chain || "A"}`; |
| if (!atomsByResidue[resId]) { |
| atomsByResidue[resId] = []; |
| resKeys.push(resId); |
| } |
| atomsByResidue[resId].push(atom); |
| }); |
| |
| const groups = resKeys.map((key) => ({ |
| key, |
| atoms: atomsByResidue[key], |
| parser: makeEasyParser(atomsByResidue[key]), |
| merged: false, |
| connectedTo: [] as number[], |
| })); |
| |
| const GRID_SIZE = 5.0; |
| const CUTOFF = 3.0; |
| const grid = new Map<string, number[]>(); |
|
|
| |
| groups.forEach((g, idx) => { |
| const bounds = g.parser.getBounds(); |
| if (!bounds) return; |
| const margin = CUTOFF / 2; |
| const iMin = Math.floor((bounds.minX - margin) / GRID_SIZE); |
| const iMax = Math.floor((bounds.maxX + margin) / GRID_SIZE); |
| const jMin = Math.floor((bounds.minY - margin) / GRID_SIZE); |
| const jMax = Math.floor((bounds.maxY + margin) / GRID_SIZE); |
| const kMin = Math.floor((bounds.minZ - margin) / GRID_SIZE); |
| const kMax = Math.floor((bounds.maxZ + margin) / GRID_SIZE); |
| for (let i = iMin; i <= iMax; i++) { |
| for (let j = jMin; j <= jMax; j++) { |
| for (let k = kMin; k <= kMax; k++) { |
| const key = `${i},${j},${k}`; |
| if (!grid.has(key)) grid.set(key, []); |
| grid.get(key)!.push(idx); |
| } |
| } |
| } |
| }); |
| |
| const potentialPairs = new Set<string>(); |
| for (const indices of grid.values()) { |
| if (indices.length < 2) continue; |
| for (let i = 0; i < indices.length; i++) { |
| for (let j = i + 1; j < indices.length; j++) { |
| const idx1 = indices[i]; |
| const idx2 = indices[j]; |
| |
| const key = idx1 < idx2 ? `${idx1},${idx2}` : `${idx2},${idx1}`; |
| potentialPairs.add(key); |
| } |
| } |
| } |
| |
| for (const pairKey of potentialPairs) { |
| const [s1, s2] = pairKey.split(","); |
| const i = parseInt(s1); |
| const j = parseInt(s2); |
| if (areGroupsBonded(groups[i].parser, groups[j].parser)) { |
| groups[i].connectedTo.push(j); |
| groups[j].connectedTo.push(i); |
| } |
| } |
| |
| for (let i = 0; i < groups.length; i++) { |
| if (groups[i].merged) continue; |
| const componentIndices: number[] = [i]; |
| groups[i].merged = true; |
| const stack = [i]; |
| while (stack.length > 0) { |
| const curr = stack.pop()!; |
| for (const neighbor of groups[curr].connectedTo) { |
| if (!groups[neighbor].merged) { |
| groups[neighbor].merged = true; |
| componentIndices.push(neighbor); |
| stack.push(neighbor); |
| } |
| } |
| } |
| |
| |
| componentIndices.sort((a, b) => a - b); |
| const combinedAtoms: IAtom[] = []; |
| const titles: string[] = []; |
| for (const idx of componentIndices) { |
| const g = groups[idx]; |
| combinedAtoms.push(...g.atoms); |
| |
| titles.push(`${g.atoms[0].resn}:${g.atoms[0].resi}`); |
| } |
| const mergedTitle = titles.join("-"); |
| terminalNodes.push( |
| new TreeNode({ |
| title: mergedTitle, |
| type: TreeNodeType.Compound, |
| model: combinedAtoms, |
| visible: true, |
| focused: false, |
| viewerDirty: true, |
| treeExpanded: false, |
| selected: SelectedType.False, |
| }) |
| ); |
| } |
| } |
| |
| let fileContents = organizeNodesIntoHierarchy( |
| terminalNodes.toArray(), |
| frameTitle |
| ); |
| |
| fileContents = cleanUpFileContents(fileContents); |
|
|
| fileContentsAllFrames.push(fileContents); |
| } |
|
|
| return Promise.resolve(fileContentsAllFrames); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| async function divideMol2AtomsIntoDistinctComponents( |
| data: IMolData |
| ): Promise<TreeNodeList> { |
| |
| const molName = getFileNameParts(data.fileInfo.name).basename; |
|
|
| |
| |
|
|
| const molNode = _getDefaultTreeNode(molName, NodesOrModel.Model); |
| molNode.model = data.fileInfo; |
| molNode.type = TreeNodeType.Compound; |
| const rootNode = organizeNodesIntoHierarchy([molNode], molName); |
| return new TreeNodeList([rootNode]); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| function cleanUpFileContents(treeNode: TreeNode): TreeNode { |
| if (treeNode.nodes) { |
| |
| |
| |
| treeNode.nodes = treeNode.nodes.filter((m: TreeNode) => { |
| let totalSubItems = 0; |
| totalSubItems += m.nodes ? m.nodes.length : 0; |
| totalSubItems += m.model ? (m.model as IAtom[]).length : 0; |
| return totalSubItems > 0; |
| }); |
|
|
| |
| |
| treeNode.nodes?.forEach((m: TreeNode) => { |
| if ( |
| m.nodes && |
| m.nodes.length > 0 && |
| ["Metal", "Ion", "Lipid", "Compound"].indexOf(m.title) > -1 |
| ) { |
| m.title += "s"; |
| } |
|
|
| |
| if (m.title) { |
| m.title = m.title.replace(/undefined:/g, ""); |
| } |
| m.title = m.title.replace(/undefined /g, ""); |
| }); |
| } |
|
|
| if (COLLAPSE_ONE_NODE_LEVELS) { |
| treeNode = collapseSingles(treeNode); |
| } |
|
|
| return treeNode; |
| } |
|
|
| |
| |
| |
| |
| |
| function addParentIds(treeNode: TreeNode) { |
| const allNodes = new TreeNodeList([treeNode]).flattened; |
| allNodes.forEach((anyNode: TreeNode) => { |
| if (anyNode.nodes && anyNode.nodes.length > 0) { |
| anyNode.nodes.forEach((node: TreeNode) => { |
| node.parentId = anyNode.id; |
| }); |
| } |
| }); |
| } |
|
|
| waitForDataFromMainThread() |
| .then(async (molData: IMolData[]) => { |
| if (molData.length === 0) { |
| sendResponseToMainThread([]); |
| return; |
| } |
|
|
| |
| |
| for (const molDatum of molData) { |
| if (["pdb", "mol2"].indexOf(molDatum.format) === -1) { |
| throw new Error( |
| `Format must be pdb or mol2. Got ${molDatum.format}.` |
| ); |
| } |
| } |
|
|
| |
|
|
| const promises = molData.map((d) => { |
| if (d.format === "pdb") { |
| return dividePDBAtomsIntoDistinctComponents(d); |
| } |
|
|
| |
| return divideMol2AtomsIntoDistinctComponents(d); |
| }); |
|
|
| const organizedAtomsFramesList = await Promise.all(promises); |
|
|
| |
| for (let i = 0; i < organizedAtomsFramesList.length; i++) { |
| for (let j = 0; j < organizedAtomsFramesList[i].length; j++) { |
| organizedAtomsFramesList[i].get(j).src = |
| molData[i].fileInfo.name; |
| } |
| } |
|
|
| |
| const organizedAtomsFrames = organizedAtomsFramesList[0]; |
| for (let i = 1; i < organizedAtomsFramesList.length; i++) { |
| organizedAtomsFrames.extend(organizedAtomsFramesList[i]); |
| } |
|
|
| let organizedAtomsFramesFixed = new TreeNodeList(); |
| organizedAtomsFrames.forEach((organizedAtoms: TreeNode) => { |
| organizedAtoms.id = randomID(); |
|
|
| const nodesToConsider = new TreeNodeList([organizedAtoms]); |
| if (organizedAtoms.nodes) { |
| nodesToConsider.extend(organizedAtoms.nodes); |
| } |
|
|
| nodesToConsider.forEach((node) => { |
| |
| |
| |
| |
| |
| |
| |
| |
| switch (node.type) { |
| case TreeNodeType.Protein: |
| addMolTypeAndStyle(node, defaultProteinStyle); |
| break; |
| case TreeNodeType.Nucleic: |
| addMolTypeAndStyle(node, defaultNucleicStyle); |
| break; |
| case TreeNodeType.Compound: |
| addMolTypeAndStyle(node, defaultLigandsStyle); |
| break; |
| case TreeNodeType.Metal: |
| addMolTypeAndStyle(node, defaultMetalsStyle); |
| break; |
| case TreeNodeType.Lipid: |
| addMolTypeAndStyle(node, defaultLipidStyle); |
| break; |
| case TreeNodeType.Ions: |
| addMolTypeAndStyle(node, defaultIonsStyle); |
| break; |
| case TreeNodeType.Solvent: |
| addMolTypeAndStyle(node, defaultSolventStyle); |
| break; |
| } |
| }); |
|
|
| addParentIds(organizedAtoms); |
|
|
| organizedAtomsFramesFixed.push(organizedAtoms); |
| }); |
|
|
| organizedAtomsFramesFixed = organizedAtomsFramesFixed.filter( |
| (o: TreeNode) => { |
| const hasNodes = o.nodes !== undefined && o.nodes.length > 0; |
| const hasModel = |
| o.model !== undefined && (o.model as IAtom[]).length > 0; |
| return hasNodes || hasModel; |
| } |
| ); |
|
|
| organizedAtomsFramesFixed.terminals.forEach((node: TreeNode) => { |
| |
| |
| if (Array.isArray(node.model)) { |
| |
| node.model = convertIAtomsToIFileInfoPDB(node.model); |
| } else { |
| |
| node.model = { |
| name: "tmp.mol2", |
| contents: (node.model as IFileInfo).contents, |
| } as IFileInfo; |
| } |
| }); |
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| sendResponseToMainThread(organizedAtomsFramesFixed.serialize()); |
|
|
| return; |
| }) |
| .catch((err: any) => { |
| throw err; |
| }); |
|
|