molstar
Version:
A comprehensive macromolecular library.
80 lines (79 loc) • 3.68 kB
JavaScript
/**
* Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { AtomNumber } from '../atomic';
import { getMoleculeType, getComponentType, getPolymerType, isPolymer, ElementSymbol } from '../../types';
import { getAtomIdForAtomRole } from '../../../../../mol-model/structure/util';
import { isProductionMode } from '../../../../../mol-util/debug';
export function getAtomicDerivedData(data, segments, index, chemicalComponentMap) {
var _a = data.atoms, label_comp_id = _a.label_comp_id, type_symbol = _a.type_symbol, atomCount = _a._rowCount;
var residueCount = data.residues._rowCount;
var offsets = segments.residueAtomSegments.offsets;
var atomicNumber = new Uint8Array(atomCount);
for (var i = 0; i < atomCount; ++i) {
atomicNumber[i] = AtomNumber(type_symbol.value(i));
}
var traceElementIndex = new Int32Array(residueCount);
var directionFromElementIndex = new Int32Array(residueCount);
var directionToElementIndex = new Int32Array(residueCount);
var moleculeType = new Uint8Array(residueCount);
var polymerType = new Uint8Array(residueCount);
var moleculeTypeMap = new Map();
var polymerTypeMap = new Map();
for (var i = 0; i < residueCount; ++i) {
var compId = label_comp_id.value(offsets[i]);
var chemCompMap = chemicalComponentMap;
var molType = void 0;
var polyType = void 0;
if (moleculeTypeMap.has(compId)) {
molType = moleculeTypeMap.get(compId);
polyType = polymerTypeMap.get(compId);
}
else {
var type = void 0;
if (chemCompMap.has(compId)) {
type = chemCompMap.get(compId).type;
}
else {
if (!isProductionMode)
console.info('chemComp not found', compId);
type = getComponentType(compId);
}
molType = getMoleculeType(type, compId);
// TODO if unknown molecule type, use atom names to guess molecule type
polyType = getPolymerType(type, molType);
moleculeTypeMap.set(compId, molType);
polymerTypeMap.set(compId, polyType);
}
moleculeType[i] = molType;
polymerType[i] = polyType;
var traceAtomId = getAtomIdForAtomRole(polyType, 'trace');
var traceIndex = index.findAtomsOnResidue(i, traceAtomId);
if (traceIndex === -1) {
var coarseAtomId = getAtomIdForAtomRole(polyType, 'coarseBackbone');
traceIndex = index.findAtomsOnResidue(i, coarseAtomId);
if (traceIndex === -1 && isPolymer(molType)) {
traceIndex = index.findElementOnResidue(i, ElementSymbol('C'));
}
}
traceElementIndex[i] = traceIndex;
var directionFromAtomId = getAtomIdForAtomRole(polyType, 'directionFrom');
directionFromElementIndex[i] = index.findAtomsOnResidue(i, directionFromAtomId);
var directionToAtomId = getAtomIdForAtomRole(polyType, 'directionTo');
directionToElementIndex[i] = index.findAtomsOnResidue(i, directionToAtomId);
}
return {
atom: {
atomicNumber: atomicNumber
},
residue: {
traceElementIndex: traceElementIndex,
directionFromElementIndex: directionFromElementIndex,
directionToElementIndex: directionToElementIndex,
moleculeType: moleculeType,
polymerType: polymerType,
}
};
}